USB to Serial converter issue
Joseph Sinclair
plug-devel@lists.PLUG.phoenix.az.us
Mon Feb 7 14:54:02 2005
This is a multi-part message in MIME format.
--------------070902060100030601060508
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Do you actually close _fd at some point?
Also, it looks like you're setting the local-mode bit, this *may*
prevent proper functioning of a USB-to-Serial converter by masking out
some of the USB status information, try recoding it without that flag.
Further, what is the value of iBaud, are you certain the USB-to-Serial
driver handles that particular setting?
I also assume you're not freeing the _newtio structure until AFTER
you're done with _fd, and that _newtio is NOT allocated on the stack.
The remainder of the code might make this clearer...
P.S. This is exactly the kind of post appropriate for the devel list, Shawn.
==Joseph++
Shawn Cook wrote:
> Hi there,
> This is my first PLUG mailing list attempt, so please forgive me if I
> break some "email mailing list" etiquette. :o)
>
> I have an IOGear USB to Serail converter cable
> (http://www.iogear.com/main.php?loc=product&Item=GUC232A
> <http://www.iogear.com/main.php?loc=product&Item=GUC232A>). This
> puppy works fine when I use cat to read or write to the serial port.
> However, when I run the code snippette pasted below, it will read but
> not write and after I quit the executable the USBtoSerial converter
> stops working entirely until I reset it by unplugging it and
> replugging it. I'm pretty sure it's not my code because I can change
> the device to a standard serial port and it reads/writes with no
> problems.
>
> Here's some system info:
> Embedded Linux distro, kernel v2.6.5
> Octagon XE800 Single Board Computer (detailed sys info:
> http://octagonsystems.com/CPUpages/xe800.html)
> AMD GX-1 300MHz processor
> USB 2.0
>
> Code Snipette:
> --------------------------------------------------------------------------------------------------------------------
> cComDev="/dev/ttyUSB0";
> ...
> _fd = open( cComDev, O_RDWR | O_NOCTTY );
> ...
> _newtio.c_cflag = _iBaud | CRTSCTS | CS8 | CLOCAL | CREAD;
> _newtio.c_iflag = IGNPAR | ICRNL;
> _newtio.c_oflag = 0;
> _newtio.c_lflag = ICANON;
> _newtio.c_cc[VINTR] = 0; /* Ctrl-c */
> _newtio.c_cc[VQUIT] = 0; /* Ctrl-\ */
> _newtio.c_cc[VERASE] = 0; /* del */
> _newtio.c_cc[VKILL] = 0; /* @ */
> _newtio.c_cc[VEOF] = 4; /* Ctrl-d */
> _newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
> _newtio.c_cc[VMIN] = 1; /* blocking read until 1 character
> arrives */
> _newtio.c_cc[VSWTC] = 0; /* '\0' */
> _newtio.c_cc[VSTART] = 0; /* Ctrl-q */
> _newtio.c_cc[VSTOP] = 0; /* Ctrl-s */
> _newtio.c_cc[VSUSP] = 0; /* Ctrl-z */
> _newtio.c_cc[VEOL] = 0; /* '\0' */
> _newtio.c_cc[VREPRINT] = 0; /* Ctrl-r */
> _newtio.c_cc[VDISCARD] = 0; /* Ctrl-u */
> _newtio.c_cc[VWERASE] = 0; /* Ctrl-w */
> _newtio.c_cc[VLNEXT] = 0; /* Ctrl-v */
> _newtio.c_cc[VEOL2] = 0; /* '\0' */
> tcflush( fd, TCIFLUSH );
> tcsetattr( fd, TCSANOW, &_newtio );
> ...
> status = read( _fd, data, bufsize );
> ...
> status = write( _fd, data, bufsize );
> --------------------------------------------------------------------------------------------------------------------
>
> Like I said before, all this jazz works fine for a standard serial
> port (cComDev="/dev/ttyS0";), but when I change this line:
> cComDev="/dev/ttyUSB0"; it gets all 'crappy'.
>
> Thanks, PLUG'rs
>
> -S Cook
>
>
--------------070902060100030601060508
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Arial">Do you actually close _fd at some point?<br>
Also, it looks like you're setting the local-mode bit, this *may*
prevent proper functioning of a USB-to-Serial converter by masking out
some of the USB status information, try recoding it without that flag.<br>
Further, what is the value of iBaud, are you certain the USB-to-Serial
driver handles that particular setting?<br>
I also assume you're not freeing the _newtio structure until AFTER
you're done with _fd, and that _newtio is NOT allocated on the stack.
The remainder of the code might make this clearer...<br>
<br>
P.S. This is exactly the kind of post appropriate for the devel list,
Shawn.<br>
<br>
==Joseph++<br>
</font><br>
Shawn Cook wrote:
<blockquote cite="midBAY101-DAV159B6F1EB6C66A214B04D3BC730@phx.gbl"
type="cite">
<meta http-equiv="Content-Type" content="text/html; ">
<meta content="MSHTML 6.00.2900.2523" name="GENERATOR">
<style></style>
<div><font face="Arial" size="2">Hi there,</font></div>
<div><font face="Arial" size="2">This is my first PLUG mailing list
attempt, so please forgive me if I break some "email mailing list"
etiquette. :o)</font></div>
<div> </div>
<div><font face="Arial" size="2">I have an IOGear USB to Serail
converter cable (<a
href="http://www.iogear.com/main.php?loc=product&Item=GUC232A">http://www.iogear.com/main.php?loc=product&Item=GUC232A</a>).
This puppy works fine when I use cat to read or write to the serial
port. However, when I run the code snippette pasted below, it will
read but not write and after I quit the executable the USBtoSerial
converter stops working entirely until I reset it by unplugging it and
replugging it. I'm pretty sure it's not my code because I can change
the device to a standard serial port and it reads/writes with no
problems. </font></div>
<div> </div>
<div><font face="Arial" size="2">Here's some system info:</font></div>
<div><font face="Arial" size="2">Embedded Linux distro, kernel v2.6.5</font></div>
<div><font face="Arial" size="2">Octagon XE800 Single Board Computer
(detailed sys info: <a
href="http://octagonsystems.com/CPUpages/xe800.html">http://octagonsystems.com/CPUpages/xe800.html</a>)</font></div>
<div><font face="Arial" size="2">AMD GX-1 300MHz processor</font></div>
<div><font face="Arial" size="2">USB 2.0</font></div>
<div> </div>
<div><font face="Arial" size="2">Code Snipette:</font></div>
<div><font face="Arial" size="2">--------------------------------------------------------------------------------------------------------------------</font></div>
<div><font face="Arial" size="2">cComDev="/dev/ttyUSB0";</font></div>
<div><font face="Arial" size="2">...</font></div>
<div><font face="Arial" size="2">_fd = open( cComDev, O_RDWR |
O_NOCTTY );</font></div>
<div><font face="Arial" size="2">...</font></div>
<div><font face="Arial" size="2">_newtio.c_cflag = _iBaud | CRTSCTS |
CS8 | CLOCAL | CREAD;</font></div>
<div><font face="Arial" size="2">_newtio.c_iflag = IGNPAR | ICRNL;</font></div>
<div><font face="Arial" size="2">_newtio.c_oflag = 0;</font></div>
<div><font face="Arial" size="2">_newtio.c_lflag = ICANON;</font></div>
<div><font face="Arial" size="2"> _newtio.c_cc[VINTR] = 0; /*
Ctrl-c */<br>
_newtio.c_cc[VQUIT] = 0; /* Ctrl-\ */<br>
_newtio.c_cc[VERASE] = 0; /* del */<br>
_newtio.c_cc[VKILL] = 0; /* @ */<br>
_newtio.c_cc[VEOF] = 4; /* Ctrl-d */<br>
_newtio.c_cc[VTIME] = 0; /* inter-character timer unused */<br>
_newtio.c_cc[VMIN] = 1; /* blocking read until 1 character
arrives */<br>
_newtio.c_cc[VSWTC] = 0; /* '\0' */<br>
_newtio.c_cc[VSTART] = 0; /* Ctrl-q */<br>
_newtio.c_cc[VSTOP] = 0; /* Ctrl-s */<br>
_newtio.c_cc[VSUSP] = 0; /* Ctrl-z */<br>
_newtio.c_cc[VEOL] = 0; /* '\0' */<br>
_newtio.c_cc[VREPRINT] = 0; /* Ctrl-r */<br>
_newtio.c_cc[VDISCARD] = 0; /* Ctrl-u */<br>
_newtio.c_cc[VWERASE] = 0; /* Ctrl-w */<br>
_newtio.c_cc[VLNEXT] = 0; /* Ctrl-v */<br>
_newtio.c_cc[VEOL2] = 0; /* '\0' */</font></div>
<div><font face="Arial" size="2"> tcflush( fd, TCIFLUSH );<br>
tcsetattr( fd, TCSANOW, &_newtio );</font></div>
<div><font face="Arial" size="2">...</font></div>
<div><font face="Arial" size="2">status = read( _fd, data, bufsize );</font></div>
<div><font face="Arial" size="2">...</font></div>
<div><font face="Arial" size="2">status = write( _fd, data, bufsize );</font></div>
<div><font face="Arial" size="2">--------------------------------------------------------------------------------------------------------------------</font></div>
<div> </div>
<div><font face="Arial" size="2">Like I said before, all this jazz
works fine for a standard serial port (cComDev="/dev/ttyS0";), but when
I change this line: cComDev="/dev/ttyUSB0"; it gets all 'crappy'.</font></div>
<div> </div>
<div><font face="Arial" size="2">Thanks, PLUG'rs</font></div>
<div> </div>
<div><font face="Arial" size="2">-S Cook</font></div>
<div> </div>
<div> </div>
</blockquote>
</body>
</html>
--------------070902060100030601060508--