[英]Talking to a power supply via mac os x using a usb-serial converter
我正在嘗試與Mac OS X Yosemite的電源進行通訊。 該代碼在linux機器上可以正常工作,但是當我在mac上嘗試時,它不起作用。 我正在使用USB串行轉換器,並已下載PL-2303驅動程序。 驅動程序在我的/ dev文件夾中顯示為cu.usbserial和tty.usbserial。
我的代碼中失敗的部分:
fd = initserial("/dev/cu.usbserial");
int initserial(char port[])
{
struct termios shimtermios;
int fd;
if((fd=open(port,O_RDWR)) < 0) {
perror("Opening the RS-232 port failed for initserial\n");
exit(-1);
}
if (tcgetattr(fd, &shimtermios) < 0) {
perror("couldn't get terminal attributes\n");
exit(-2);
}
shimtermios.c_iflag=012005;
shimtermios.c_oflag=014004;
shimtermios.c_cflag=03206276;
shimtermios.c_lflag=05060;
cfsetospeed(&shimtermios,B19200);
if (tcsetattr(fd, TCSAFLUSH, &shimtermios) < 0) {
perror("couldn't set terminal attributes\n");
exit(-3);
}
return (fd);
}
我收到以下錯誤消息
couldn't set terminal attributes
: Invalid argument
如果您對此linux / unix問題有任何經驗,請告訴我。 非常感謝!
有關可用於c_iflag
, c_oflag
, c_cflag
和c_lflag
的有效掩碼,請參見termios
手冊頁 。 您應該將掩碼常量或在一起,而不是對值進行硬編碼。
同樣從經驗來看,FTDI USB串行轉換器在OS X上的性能往往優於pl2303。 OS X具有用於這些的內置驅動程序(AppleUSBFTDI)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.