Hi,
On Ubuntu I try to access a PIC-controler via the ttyUSB0. I send a few
command bytes and get the status from the controller. My C code works
without problems on ttyS0 but with the usb-to-serial adapter (I tried
tree defferent chipsets pl2303, ch341-uart and FT232RL) it just sends
but can't read from the controller.
With minicom I can communicate with an other computer without problems
but in my code there must be something wrong for the ttyUSB.
Any ideas what the problem could be?
Manfred
Im working on Ubuntu 9.10, Kernel 2.6.31-21
here is my code:
=====================================================
struct termios oldtio,newtio;
extern "C" HANDLE SioOpen(char *name, unsigned int baudrate)
{
BOOL RetStat;
HANDLE ComHandle;
DWORD winrate;
//Open COM port as a file
printf("Opening %s\n",name);
ComHandle = open(name, O_RDWR) | O_NOCTTY);
if (ComHandle < 0)
{
printf("%s failed to open\n",name);
perror(name); }
switch (baudrate) {
case 9600: winrate = B9600; break;
case 19200: winrate = B19200; break;
case 38400: winrate = B38400; break;
case 57600: winrate = B57600; break;
case 115200: winrate = B115200; break;
default: printf("Baud rate not supported - using default of
19200\n");
winrate = B19200;
}
//printf("tcgetattr(ComHandle,&oldtio)\n");
tcgetattr(ComHandle,&oldtio); // save current port settings
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = winrate | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
// set input mode (non-canonical, no echo,...)
newtio.c_lflag = 0;
// Wait block for 100ms, then timeout
newtio.c_cc[VTIME] = 1; // inter-character timer unused
newtio.c_cc[VMIN] = 0; // blocking read until 1 chars received
//tcflush(ComHandle, TCIFLUSH);
tcflush(ComHandle, TCIOFLUSH);
//printf("tcsetattr(ComHandle,TCSANOW,&newtio)\n");
RetStat = tcsetattr(ComHandle,TCSANOW,&newtio);
if (RetStat < 0)
{
printf("Failed to set COMM configuration\n");
//break;
}
//printf("Setup complete, returning file handle.\n"); return(ComHandle);
}
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html