socat を使用している場合、何らかの理由で Arduino への通信しか機能しないため、socat がシリアル通信に対して行うことについて少し説明したいと思います。
これは、socat のセットアップに使用するコマンドです。
socat -d -v -x PTY,link=/tmp/serial,wait-slave,raw /dev/ttyACM0,raw
私が C++ で使用したコードは次のとおりです。
int file;
file = open("/tmp/serial", O_RDWR | O_NOCTTY | O_NDELAY);
if (file == -1)
{
perror("open_port: Unable to open \n");
}
else
fcntl(file, F_SETFL, 0);
struct termios options;
//* Get the current options for the port...
tcgetattr(file, &options);
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
options.c_oflag = 0;
//options.c_oflag &= ~(OCRNL | ONLCR | ONLRET | ONOCR | OFILL | OLCUC | OPOST);
options.c_cflag |= (CLOCAL | CREAD);
cfmakeraw(&options);
tcsetattr(file, TCSANOW, &options);
sprintf(sendpack,"$C000C000C000C000\r");
num = write(file,sendpack,18);
tcflush(file, TCIOFLUSH); // clear buffer
したがって、これを socat で実行すると、arduino は想定どおりに反応しますが、open() 行を /tmp/serial から /dev/ttyACM0 に変更すると、arduino はまったく機能しなくなります。socat がデータに対して行っていることと、C コードを変更して同じことを行う方法を説明してもらえますか? socat を使用すると遅延が発生し、ロボットの運転が予測不能になるため、最終的な実装では socat を使用できません。