2013-03-03 33 views

回答

0

你可以試試下面的代碼,看看它是否有幫助嗎?

int open_port(void) 
{ 
    int fd; 

fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY); 
if (fd == -1) 
{ 
    perror("open_port: Unable to open /dev/ttyS0 - "); 
} 
else 
    fcntl(fd, F_SETFL, 0); 

struct termios options; 

tcgetattr(fd, &options); 

cfsetispeed(&options, B9600); 
cfsetospeed(&options, B9600); 

tcsetattr(fd, TCSANOW, &options); 

return (fd); 
} 
+0

是的,這是一個錯字。我更新了它。 – Cacheing 2013-03-03 20:43:06

+0

你認爲代碼是正確的嗎?我只是不確定它是否正確... – Cacheing 2013-03-03 20:45:04

+0

您需要檢查每個命令的返回代碼,以查看哪個失敗。 – 2013-03-03 20:53:46

相關問題