Question

I have an application talking between the PC and a board with a microcontroller running uCLinux. When I send a message over the /dev/TTYS0 I get it on the PC side, however the message comes across as gibberish. I'm pretty sure that I have a baud rate mismatch of some sort.

On the PC side I'm using the baud rate provided:

Serial<id=0x1efb320, open=True>(port='COM4', baudrate=9600, bytesize=8, parity='
N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)

On the Linux board side I'm setting the same baud rate in the code:

tcgetattr(fd, &options);
cfsetispeed(&options, 9600);
cfsetospeed(&options, 9600);
tcsetattr(fd, TCSANOW, &options);
tcgetattr(fd, &options);

This worked for me when I was testing a PC (Win 7)->Linux Box (OpenSuse) so I know the theory is sound. Now that I've ported this to my true target (coldfire microcontroller board running uCLinux) I'm getting garbage.

So my first option is to "guess and check" at various baud rates to see if I can find one that will work, but rather than that I'd like to programmatically find a way to identify the supported baud rates of a specific target.

I'm sure there's some API, but I haven't found one. Ideas?

EDIT: Seems it's possible to get max baud rate on Windows with the COMMPROP structure. Does anything even like this exist on Linux?

Était-ce utile?

La solution

Please read the cfsetospeed() man page. The speed parameter must be a constant: B50, B75, .., B9600, B19200, B38400, B57600, B115200, or B230400, not just the rate as a number.

To find out if a specific rate is supported, just set it cfset?speed()+tcsetattr(), then read back the settings (using tcgetattr()+cfget?speed()), and check if the speed was set to the desired value or not. The driver should reject invalid baud rates, I believe.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top