Glib and Serial Port Help
So I want to write a small program to read and write data to a serial port (115200 baud, 8N1) using GIOChannel. No matter what I try, I can't seem to get input callbacks from the channel. :( Does anyone have any small working examples of using a GIOChannel to drive a serial port I can look at?
NP: Mungo's Hi-Fi at Exodus
fd = open("/dev/ttyS0", O_RDWR|O_NOCTTY|O_NONBLOCK);
(all the usual tcsets...)
io = g_io_channel_unix_new(fd);
g_io_add_watch(io, G_IO_IN, has_data, ptr);
tcgetattr (fd, &tio);
tio.c_cflag = CREAD | CLOCAL | B115200 | CS8;
tio.c_iflag = IGNPAR | IGNBRK;
tio.c_oflag = 0;
tio.c_lflag = 0;
tio.c_cc[VTIME] = 0;
tio.c_cc[VMIN] = 1;
tcsetattr (fd, TCSANOW, &tio);
tcflush (fd, TCIFLUSH);
tcflush (fd, TCOFLUSH);
g_io_channel_set_encoding(channel, NULL);
g_io_channel_set_buffered(channel, FALSE);
works for you?
BTW, is your cable the correct one (null-modem/direct)?
Hope it helps in some way.
Ciao.
acs_fd = g_open ("/dev/ttyS0", O_NOCTTY | O_RDONLY);
tcgetattr (acs_fd, &acs_termios);
cfsetispeed (&acs_termios, B19200);
cfsetospeed (&acs_termios, B19200);
acs_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INLCR | IGNCR | ICRNL | IXON | IXOFF | IXANY);
acs_termios.c_oflag &= ~OPOST;
acs_termios.c_lflag &= ~(ECHO | ECHONL | ECHOE | ICANON | ISIG | IEXTEN);
acs_termios.c_cflag &= ~(CRTSCTS | CSTOPB | PARENB | INPCK | ISTRIP | CSIZE);
acs_termios.c_cflag |= CREAD | CLOCAL | CS8;
acs_termios.c_cc[VMIN] = 1;
acs_termios.c_cc[VTIME] = 0;
tcflush (acs_fd, TCIOFLUSH);
tcsetattr (acs_fd, TCSANOW, &acs_termios);
acs_io = g_io_channel_unix_new (acs_fd);
g_io_channel_set_encoding (acs_io, NULL, NULL);
g_io_add_watch (acs_io, G_IO_IN, acs_scoe_process, (gpointer) &acs_scoe_pkt);
Did you resolve this? I'm having a similar problem.
My configuration is:
newtio.c_cflag = baud | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
//all others are zero.
If I write "AT\n" to /dev/ttyACM0 and then immediately read, read() always returns 0.
Was the hardware problem your USB port or the modem?