シリアル ポートから 100 ボー レートで読み取ることができるかどうかを知りたいです。ボーレートtermio.h
として100を設定する規定はありません。私はLinuxで働いています。相手側の通信デバイスは 100 ボーレートでデータを送信しており、固定されています。ボーレートが 110 に設定されているかどうかを知りたいのですが、受信しているデータが正しいことは保証されますか? またはこれに対する解決策はありますか?
よろしくお願いします。
シリアル ポートから 100 ボー レートで読み取ることができるかどうかを知りたいです。ボーレートtermio.h
として100を設定する規定はありません。私はLinuxで働いています。相手側の通信デバイスは 100 ボーレートでデータを送信しており、固定されています。ボーレートが 110 に設定されているかどうかを知りたいのですが、受信しているデータが正しいことは保証されますか? またはこれに対する解決策はありますか?
よろしくお願いします。
あなたは実際に幸運です。100 ボーは、一般的な 16450 互換のシリアル ポート (ほぼすべてのもの) でそれを実行する除数 (1,152) を計算できるほど十分に低く、Linuxはパラメータ to を使用してカスタム除数をサポートします。spd_cust
setserial
うーん.... 110 bps はシリアル ポートの速度の中で独特で、従来は 2 つのストップ ビットがあり (他のすべての速度は 1 つのストップ ビットを使用)、1 文字を送信するには 7 ビット データの場合は 10 ビット、8 ビット データの場合は 11 ビットが必要です。 -ビットデータ。
通信プロトコルが1 秒あたり 10 文字で通信され、1950 年代のプロトコルを知らない人が 1 ストップ ビットと 8 ビット データのみを想定して cps をボーに変換した場合、100 ボーが結果であると結論付けます。
真の 100 ボーのカスタム設定が機能しない場合は、標準の 110 ボーを設定してみてください。
関連する回答からの抜粋:
#include <errno.h>
#include <termios.h>
#include <unistd.h>
int
set_interface_attribs (int fd, int speed, int parity)
{
struct termios tty;
memset (&tty, 0, sizeof tty);
if (tcgetattr (fd, &tty) != 0)
{
error_message ("error %d from tcgetattr", errno);
return -1;
}
cfsetospeed (&tty, speed);
cfsetispeed (&tty, speed);
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
if (speed == B110)
tty.c_cflag |= CSTOPB; // 2 stop bits for 110
// disable IGNBRK for mismatched speed tests; otherwise receive break
// as \000 chars
tty.c_iflag &= ~IGNBRK; // ignore break signal
tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read doesn't block
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
// enable reading
tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
tty.c_cflag |= parity;
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CRTSCTS;
if (tcsetattr (fd, TCSANOW, &tty) != 0)
{
error_message ("error %d from tcsetattr", errno);
return -1;
}
return 0;
}
void
set_blocking (int fd, int should_block)
{
struct termios tty;
memset (&tty, 0, sizeof tty);
if (tcgetattr (fd, &tty) != 0)
{
error_message ("error %d from tggetattr", errno);
return;
}
tty.c_cc[VMIN] = should_block ? 1 : 0;
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
if (tcsetattr (fd, TCSANOW, &tty) != 0)
error_message ("error %d setting term attributes", errno);
}
...
char *portname = "/dev/ttyUSB1"
...
int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
if (fd < 0)
{
error_message ("error %d opening %s: %s", errno, portname, strerror (errno));
return;
}
set_interface_attribs (fd, B110, 0); // set speed to 115,200 bps, 8n2 (no parity)