2

I am trying to use a pyvisa library to write a configuration to a test device. When I am trying to send the command over I get the following error from the utilty function used to talk with the equipment.

"struct.error: char format requires a byte object of length 1"

I have traced down to the code that is throwing the error and am able to reproduce just the error using a small code fragment which I have included below.

iter = b'<setup pro'
fullfmt = '<10c'
header = b'#510'
result = header + struct.pack(fullfmt, *iter)

When I do this I expect to get a packed byte structure containing

b'#510<10c

but instead I get the following:

Traceback (most recent call last): File "/usr/lib/python3.6/code.py", line 91, in runcode exec(code, self.locals) File "", line 1, in struct.error: char format requires a bytes object of length 1

So them I decided that I would that maybe my format was wrong and that it it should be a 's' instead of a 'c' so I tried the above code again by changing fullfmt from '<10c' to '<10s' and then get the following error message.

Traceback (most recent call last): File "/usr/lib/python3.6/code.py", line 91, in runcode exec(code, self.locals) File "", line 1, in struct.error: pack expected 1 items for packing (got 10)

I'm at a bit of a loss. Any help would be greatly appreciated.

4

0 回答 0