I've got an XM receiver installed in my car now, and I'm trying to control it via the serial port. Unfortunately, though I can see serial data coming from the receiver on my laptop, and can control the receiver using software on my laptop, I can't get the XM receiver to communicate successfully with my empeg via the serial port, even using the same code that works on my laptop.

The receiver is 9600 baud, N81, no flow control. I've set car_rate to 9600 in config.ini, and set Hijack (v500) to "Apps use the serial port." Still, no luck.

Here is a stripped-down test program that works on my Mac laptop (sees and prints data coming from the XM receiver) but doesn't on the empeg:

Code:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

#define BAUDRATE B9600
#ifdef MAC
#define SERIALDEV "/dev/tty.usbserial"
#else
#define SERIALDEV "/dev/ttS1"
#endif
 
int main(int argc,char** argv)
{
    struct termios termios;
    struct termios stdio;
    int serial_fd;
    fd_set rdset;
 
    unsigned char c='\0';

    fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);

    memset(&termios,0,sizeof(termios));
    termios.c_iflag=0;
    termios.c_oflag=0;
    termios.c_cflag=CS8|CREAD|CLOCAL;
    termios.c_lflag=0;
    termios.c_cc[VMIN]=1;
    termios.c_cc[VTIME]=5;

    serial_fd = open(SERIALDEV, O_NOCTTY | O_RDWR | O_NONBLOCK);
    if (serial_fd < 0)
    {
        fprintf(stderr, "can't open fd");
    }
    cfsetospeed(&termios,BAUDRATE);
    cfsetispeed(&termios,BAUDRATE);
 
    tcsetattr(serial_fd,TCSANOW,&termios);

    while (c!='q')
    {
        if (read(serial_fd,&c,1)>0)        write(STDOUT_FILENO,&c,1);
        if (read(STDIN_FILENO,&c,1)>0)  write(serial_fd,&c,1);
    }
 
    close(serial_fd);
}


Now, I've found some threads indicating there are some termios flags you have to mess with in some cases, and I've tried some of those, but still can't get anything to work.

Here are the combinations that work:
serialtest program on laptop can read data from XM receiver
serialtest program on laptop can talk to serialtest program on empeg (and vice versa)

The one combination that isn't working is serialtest program on empeg being able to see anything from the XM receiver when it's plugged in.

Any ideas what to try?


Edited by tonyc (14/07/2010 21:54)
_________________________
- Tony C
my empeg stuff