Convert 'bytes' object to string

Viewed 780

I tried to find solution, but still stuck with it. I want to use PyVisa to control function generator. I have a waveform which is a list of values between 0 and 16382 Then I have to prepare it in a way that each waveform point occupies 2 bytes. A value is represented in big-endian, MSB-first format, and is a straight binary. So I do binwaveform = pack('>'+'h'*len(waveform), *waveform) And then when I try to write it to the instrument with AFG.write('trace ememory, '+ header + binwaveform) I get an error:

  File ".\afg3000.py", line 97, in <module>
    AFG.write('trace ememory, '+ header + binwaveform)
TypeError: Can't convert 'bytes' object to str implicitly

I tried to solve it with AFG.write('trace ememory, '+ header + binwaveform.decode()) but it looks that by default it tries to use ASCII characters what is not correct for some values: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 52787: invalid start byte

Could you please help with it?

1 Answers
Related