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.&nbsp;
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.&nbsp; :o)</font></div>
  <div>&nbsp;</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&amp;Item=GUC232A">http://www.iogear.com/main.php?loc=product&amp;Item=GUC232A</a>).&nbsp;
This puppy works fine when I use cat to read or write to the serial
port.&nbsp; However, when I run the code snippette pasted below, it&nbsp;will
read but not&nbsp;write and after I quit the executable the USBtoSerial
converter stops working entirely until I reset it by unplugging it and
replugging it.&nbsp; 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.&nbsp;&nbsp; </font></div>
  <div>&nbsp;</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>&nbsp;</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">&nbsp; _newtio.c_cc[VINTR]&nbsp;&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /*
Ctrl-c */<br>
&nbsp; _newtio.c_cc[VQUIT]&nbsp;&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* Ctrl-\ */<br>
&nbsp; _newtio.c_cc[VERASE]&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* del */<br>
&nbsp; _newtio.c_cc[VKILL]&nbsp;&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* @ */<br>
&nbsp; _newtio.c_cc[VEOF]&nbsp;&nbsp;&nbsp;&nbsp; = 4;&nbsp;&nbsp;&nbsp;&nbsp; /* Ctrl-d */<br>
&nbsp; _newtio.c_cc[VTIME]&nbsp;&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* inter-character timer unused */<br>
&nbsp; _newtio.c_cc[VMIN]&nbsp;&nbsp;&nbsp;&nbsp; = 1;&nbsp;&nbsp;&nbsp;&nbsp; /* blocking read until 1 character
arrives */<br>
&nbsp; _newtio.c_cc[VSWTC]&nbsp;&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* '\0' */<br>
&nbsp; _newtio.c_cc[VSTART]&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* Ctrl-q */<br>
&nbsp; _newtio.c_cc[VSTOP]&nbsp;&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* Ctrl-s */<br>
&nbsp; _newtio.c_cc[VSUSP]&nbsp;&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* Ctrl-z */<br>
&nbsp; _newtio.c_cc[VEOL]&nbsp;&nbsp;&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* '\0' */<br>
&nbsp; _newtio.c_cc[VREPRINT] = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* Ctrl-r */<br>
&nbsp; _newtio.c_cc[VDISCARD] = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* Ctrl-u */<br>
&nbsp; _newtio.c_cc[VWERASE]&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* Ctrl-w */<br>
&nbsp; _newtio.c_cc[VLNEXT]&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* Ctrl-v */<br>
&nbsp; _newtio.c_cc[VEOL2]&nbsp;&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp;&nbsp; /* '\0' */</font></div>
  <div><font face="Arial" size="2">&nbsp; tcflush( fd, TCIFLUSH );<br>
&nbsp; tcsetattr( fd, TCSANOW, &amp;_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>&nbsp;</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>&nbsp;</div>
  <div><font face="Arial" size="2">Thanks, PLUG'rs</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">-S Cook</font></div>
  <div>&nbsp;</div>
  <div>&nbsp;</div>
</blockquote>
</body>
</html>

--------------070902060100030601060508--