jcb*_*344 5 unix macos posix serial-port ftdi
我有一个USB连接到我的mac的串行FTDI适配器.我能够使用命令:
screen /dev/tty.usbserial-A601L9OC
Run Code Online (Sandbox Code Playgroud)
这将打开端口的串行终端,一切正常.但是当我尝试通过命令将字符发送到串行端口时:
root# echo 'a' > /dev/tty.usbserial-A601L9OC
Run Code Online (Sandbox Code Playgroud)
命令挂起,没有发送任何内容.当我尝试在ac程序中连接它时,会发生类似的事情.程序挂起试图打开串口:
int fd = open("/dev/tty.usbserial-A601L9OC", O_RDWR | O_NOCTTY | O_SYNC);
Run Code Online (Sandbox Code Playgroud)
当我在端口上运行stty时它会打印:
root# stty -f /dev/tty.usbserial-A601L9OC
speed 9600 baud;
lflags: -icanon -isig -iexten -echo
iflags: -icrnl -ixon -ixany -imaxbel -brkint
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb
Run Code Online (Sandbox Code Playgroud)
看起来很正确.有没有人知道为什么这些命令挂起并且在连接到串口时从不发送但是屏幕工作得很好?任何帮助将不胜感激.
更新:从stty获取信息的结果
bash-3.2# stty -a -f /dev/tty.usbserial-A601L9OC
speed 9600 baud; 0 rows; 0 columns;
lflags: -icanon -isig -iexten -echo -echoe -echok -echoke -echonl
-echoctl -echoprt -altwerase -noflsh -tostop -flusho -pendin
-nokerninfo -extproc
iflags: -istrip -icrnl -inlcr -igncr -ixon -ixoff -ixany -imaxbel -iutf8
-ignbrk -brkint -inpck -ignpar -parmrk
oflags: -opost -onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
stop = ^S; susp = ^Z; time = 0; werase = ^W;
Run Code Online (Sandbox Code Playgroud)
请改用设备/dev/cu.usbserial-A601L9OC,并将速度设置为9600波特.以下是Magnus的macrumor帖子的一个例子:
strcpy(bsdPath, "/dev/cu.usbserial-A601L9OC");
fileDescriptor = open(bsdPath, O_RDWR);
if (-1 == fileDescriptor)
{
return EX_IOERR;
}
struct termios theTermios;
memset(&theTermios, 0, sizeof(struct termios));
cfmakeraw(&theTermios);
cfsetspeed(&theTermios, 9600);
theTermios.c_cflag = CREAD | CLOCAL; // turn on READ and ignore modem control lines
theTermios.c_cflag |= CS8;
theTermios.c_cc[VMIN] = 0;
theTermios.c_cc[VTIME] = 10; // 1 sec timeout
int ret = ioctl(fileDescriptor, TIOCSETA, &theTermios);
ret = read(fileDescriptor, &c, 1);
Run Code Online (Sandbox Code Playgroud)