Я использую Ubuntu 9.10 и, похоже, у меня проблемы с termios.
Таким образом, я могу запустить Minicom, открыв последовательный порт на скорости 57600 бод, 8N1, без аппаратного или программного управления потоком, и он отлично работает. Я набираю 17 17 5, и мое устройство отвечает. Когда я пытаюсь настроить свой последовательный порт в своем коде C ++, я не получаю ответ. Я знаю, что программное обеспечение связывается с портом, потому что загорается светодиод.
Вот мой главный:
int main(void)
{
int fd; /* File descriptor for the port */
fd = open("/dev/keyspan1", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/*
* Could not open the port.
*/
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
fcntl(fd, F_SETFL, 0);
/*****************************CHANGE PORT OPTIONS***************************/
struct termios options;
/*
* Get the current options for the port...
*/
tcgetattr(fd, &options);
/*
* Set the baud rates to 57600...
*/
cfsetispeed(&options, B57600);
cfsetospeed(&options, B57600);
/*
* Enable the receiver and set local mode...
*/
options.c_cflag |= (CLOCAL | CREAD);
/*
* Set the new options for the port...
*/
tcsetattr(fd, TCSANOW, &options);
/***********************************END PORT OPTIONS***********************/
int n;
n = write(fd, "@17 5 \r", 7);
if (n < 0)
fputs("write() of 8 bytes failed!\n", stderr);
char buff[20];
sleep(1);
n = read(fd, buff, 10);
printf("Returned = %d\n", n);
close(fd);
return(0);
}
Любые предложения будут оценены. Спасибо.