2

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?

4

1 に答える 1

2

cfsetospeed()マニュアルページをお読みください。speedパラメータは定数である必要があります:、、B50.. B75、、、、、、、、またはB9600、数値B19200としてB38400のレートだけではありませんB57600B115200B230400

特定の速度がサポートされているかどうかを確認するには、それをcfset?speed()+に設定tcsetattr()してから、設定を読み直し(tcgetattr()+を使用cfget?speed())、速度が目的の値に設定されているかどうかを確認します。ドライバーは無効なボーレートを拒否する必要があると私は信じています。

于 2012-10-16T15:57:42.667 に答える