4

I've written a PRN generator in Python and I am trying to test the sequences to validate them. I have a bit error rate tester, but in order for everything to work, I need to provide it with clocked data.

Is there any way of getting raw binary data out of the computer via USB or serial? I haven't found any python modules which are capable of doing this, but the language I use doesn't really matter so if this is doable in a different language, I can use that.

MPelletier
  • 16,256
  • 15
  • 86
  • 137
gwenger
  • 1,211
  • 3
  • 12
  • 11
  • What system are you using? There's quite a good topic for linux here: http://stackoverflow.com/questions/469243/how-can-i-listen-for-usb-device-inserted-events-in-linux-in-python Maybe not exacly, what you're searching for, but it might be useful. – Gandi Jun 27 '11 at 14:44
  • I'm using windows, but I can easily switch over to linux since this is just a test. My goal here is really just to avoid having to use a microcontroller to send data to my tester, so solutions don't have to be platform specific. – gwenger Jun 27 '11 at 14:59

1 Answers1

2

To get the data from the serial port use pyserial. To convert the binary data use the struct module. These tools should work for Windows, Linux, and Mac.

Edit: Maybe, by "raw data", the OP means he would like to use the serial port as a DIO interface with no serial protocol? This type of thing is generally done using the parallel port, and is easy and possible using the pyParallel module within pyserial (given that one has a parallel port). I know of no way to do this directly with a serial port.

tom10
  • 67,082
  • 10
  • 127
  • 137
  • Sorry I should have mentioned that I am using pyserial. I know how to send binary data out of my computer's serial port, but doesn't that include some type of packeting that would change the data being sent? I need to have the serial port transmit exactly the bits that I send. – gwenger Jun 27 '11 at 15:39
  • 1
    seria.write can send a bytes, bytearray, or a str object. Usually people convert their binary data into a string, which is why I recommended the struct module. Just to be clear though, this is sending the exact, byte-for-byte data, but just giving the data to serial.write in a string object. – tom10 Jun 27 '11 at 17:20
  • I've been sending my data as bytearrays so I do know what bytes I am sending. The issue is, the RS-232 standard requires start and stop bits. Also, I think the serial connection is little endian. So, if i send F0 as a bytearray, I see 5 high bits followed by 5 low bits on my oscilloscope (the first and last bits are start and stop, respectively, and the data is inverted). What I need is to find some way to send my data without the start and stop bits and change the endianness. – gwenger Jun 27 '11 at 18:40
  • You can change the endianness of the data you're sending using the struct module. start and stop bits are part of the protocol (and aren't really bits, btw, but time intervals) so it doesn't make sense to remove these as then you wouldn't be doing he rs232 protocol anymore and your receiver couldn't receive, etc. So I think something's not as you're expecting other than start and stop bits, usually, parity, byte size, etc, which are valid parameters in the protocol. – tom10 Jun 27 '11 at 19:00
  • I actually was trying to find a way to communicate without the rs232 protocol because my tester didn't have the required serial port, but we just got a new interface module, so I'm back to using pyserial the correct (and much less frustrating) way. – gwenger Jun 28 '11 at 18:15