On Fri, Jun 07, 2002 at 10:31:20AM -0400, Doug Alcorn wrote:
> I'm running kernel 2.4.17 with a Keyspan USA-19QW usb serial adapter.
> I know that the source/firmware for the 19QW isn't included in the
> 2.4.17 kernel.  I downloaded it from their web-site.  As such, this
> may not be the appropriate channel to ask for help.  I'm not really
> sure the status of this driver since it is GPL.

The stuff on their web site is already in the 2.5 kernel.  I'll be
backporting it to the 2.4 kernel once 2.4.19 is out.

> Anyway, I have a fairly smart device that I'm talking to with a
> proprietary protocol over the serial port.  The technique is pretty
> simple: I send commands and it sends me results.  The code I inherited
> for this task in user-land looked like this:
> 
> static int SendCommand (int sPort, char *command)
> {
>     tcflush (sPort, TCIOFLUSH);
>     return (write (sPort, command, strlen (command)) == strlen (command));
> }
> 
> Using the standard serial port, this seemed to work fine.  Using the
> usb-serial adapter some commands just failed.  I know this code isn't
> very good so I re-wrote it like this:
> 
> static int SendCommand (int sPort, char *command)
> {
>     int rc = 0;                 /* return code from write command */
>     int total = 0;              /* total bytes written */
>     int size = strlen (command); /* size of command to write */
> 
>     /* clear serial port buffers */
>     tcflush (sPort, TCIOFLUSH);
> 
>     /* keep writing the command until the total written is equal to
>      * the size of the command */
>     while (total != size || rc == -1) {
>         rc = write (sPort, command + total, size - total);
>         total += rc;
>     }
> 
>     /* return false on write error */
>     return ((rc == -1) ? 0 : 1);
> }
> 
> 
> Using gdb with this function I can see clearly now what's happening.
> With the standard serial port all of the commands I write out always
> go in one write.  The usb-serial adapter seems to have a limit of 126
> bytes for each write.  The command I'm testing right now is 143 bytes
> long.  Using usb-serial it takes two writes: one of 126 another of
> 17.  Both writes succeed.  My device reports an error of "Command too
> long" when I do these two writes rather than just the one with the
> standard serial port.
> 
> My question is where do you thing the corruption is?  Is there
> something wrong with my code I wrote, they keyspan protocol driver,
> the usbserial driver, or the keyspan device itself?

Most usbserial drivers (like the keyspan one) only accept a small
ammount of data, like you have found out.  But since both writes do
succeed, are you seeing the correct data out the serial portion of the
device?

Does your device require a constant byte stream, with no delays between
characters within a single "command"?

thanks,

greg k-h

_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-users

Reply via email to