pyvisa / pyvisa-py

A pure python PyVISA backend
https://pyvisa-py.readthedocs.io
MIT License
288 stars 124 forks source link

struct problems on python2.7 #30

Closed daritter closed 9 years ago

daritter commented 9 years ago

when running on python2.7 I get errors with struct.pack:

File "/home/hybrid5/.local/lib/python2.7/site-packages/pyvisa-py/protocols/rpc.py", line 282, in sendfrag header = struct.pack(">I", x) TypeError: Struct() argument 1 must be string, not unicode

locally I fixed the two occurences of struct.pack to use a byte-string literal and that seems to work fine.

hgrecco commented 9 years ago

does it work on Python 3 as well? If not, please use the same solution as here:

https://github.com/hgrecco/pyvisa/blob/master/pyvisa/util.py#L28

daritter commented 9 years ago

I don't have python3 on the machine where the device is connected so I cannot verify it directly. But struct.pack(b">I", 5) == struct.pack(">I", 5) seems to work fine in python 3.4 on my local machine.

Of course the solution in utils.py would also be fine. Do you want me to prepare a pull request for the two occurences in protocols/rpc.py and the four in protocols/usbmtc.py ?

hgrecco commented 9 years ago

I have the idea that there was a bug in certain versions of python (maybe in 3.2) that required us to do the solution coded in utils.py. We are putting common compatibility code in PyVISA compat package to make it easier to maintain and test. Therefore, please:

  1. The first against PyVISA, moving the struct functions (but removing the underscore) to an new module compat\struct.py and then use them directly from there in utils.py.
  2. Then a second PR against PyVISA-py using this module in rpc.py and usbtmc.py

Thanks for looking into this!