Python and USB/serial, weird errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JimmyC
    New Member
    • Apr 2008
    • 1

    Python and USB/serial, weird errors

    Dear All,

    Two separate questions...

    I am using pyUSB with python 2.5 and libusb-win32 version 0.1.12.1. My code is able to connect to my device (AT91SAM7X256) but is unable to do bulkwrites even though the bulkwrites are fine. I get a "usb_reap: timeout error". I tried to change the timeout to various values but still get that error. Has anyone experienced this before or knows what causes it and the solution to it?

    I am using pySerial with python 2.5. I am reading a stream of data, 1 byte at a time and need to reverse and concatenate the bytes 2 bytes at a time. That is if i read in "FF 00 FF 00" the desired output is "00FF 00FF" which can later be converted to "255 255". I have a algorithm which works perfectly fine but what does not work is that the program never picks up 2D (45). The values before it and after it are picked up but 2D is missing. No matter what I make the timeout value, or the number of bytes I send to the computer from the AT91SAM7X256, pySerial never picks up 2D. The microcontroller is setup to run CDC communication with endpoint sizes of 64 bytes and a packet size of 1000 bytes. I do not believe that the problem lies with the microcontroller because I can see that the value 2D is comming through on the USB port with a port sniffer. Any ideas on what might be going on?

    Thank you in advance,
    JimmyC
  • woooee
    New Member
    • Mar 2008
    • 43

    #2
    It sounds like the problem is with your code, but no one can tell unless you post it. When reading from a serial port, you use a flip-flop or switch, assuming that Null is sent between data bytes. This is a quick reply so I'm not 100% on the logic, but it shows the general idea. I have only used USPP for Python serial port access, so can't comment on PySerial. (And there seems to be a problem with the code tags??) [CODE]
    flip_flop=1
    while 1:
    ......data=read _data()
    ......if flip_flop and data:
    ...........## process data
    ...........flip _flop=0
    ......if not data and not flip_flop:
    ...........flip _flop=1 [/CODE}

    Comment

    • jlm699
      Contributor
      • Jul 2007
      • 314

      #3
      Originally posted by woooee
      (And there seems to be a problem with the code tags??)
      Code:
      flip_flop=1 
      while 1:    
      ......data=read_data()    
      ......if flip_flop and data:       
      ...........##   process data       
      ...........flip_flop=0    
      ......if not data and not flip_flop:       
      ...........flip_flop=1
      You kept the shift key held down when you closed your ']' bracket....

      Comment

      Working...