Linuxでマイコンとシリアル通信を試みています。
Linuxからマイコンへ送信したシリアル通信データをエコーバックで受信するデータなのですが、
linuxからシリアルデータが送信されません。
write()
関数でデータ送信できるものと思い込んでいるのですが、その考えは正しいでしょうか。
#include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <fcntl.h> #include <termios.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/wait.h> #define SERIAL_PORT "/dev/ttyUSB0" #define BAUDRATE B115200 int main(int argc, char *argv[]){ struct termios oldtio, newtio; int fd; fd = open(SERIAL_PORT, O_RDWR); if(fd<0){ printf("open error"); } ioctl(fd, TCGETS, &oldtio); newtio = oldtio; newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD; ioctl(fd, TCSETS, &newtio); while(1){ char command[4]; char key; #define BUFSIZE 4 int txData[BUFSIZE]; txData[0] = 0xAA; txData[1] = 0x00; txData[2] = 0x01; txData[3] = 0xAB; write(fd, txData, BUFSIZE-1); } ioctl(fd, TCSETS, &oldtio); close(fd); }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/06 09:16 編集
2018/11/06 09:18
2018/11/06 09:21
2018/11/06 09:53