0

I got an instrument (Vötsch climate chamber VT 4002) connected via TCP/IP and pyVISA as SOCKET and i can query it using *IDN?. Now I need to send a command to it that includes the ASCII 182 character combined with a normal string:

instr = rm.open_resource(TCPIP::...::SOCKET', read_termination='\r')
instr.write('11001'+u'\xb6')

But I get the Error:

UnicodeEncodeError; 'ascii' codec can't encode character u'\xb6' in position 5: ordinal not in range(128)

I know that the ASCII value is above 128, but how to write it to the instrument? Is write even the right command (although the *IDN? query works)? I am new to python and pyVISA, so please answer for newbies :) Thanks!

PS:

# -*- coding: utf-8 -*-

did not work

PPS: I think the problem is that the write() method always uses the ASCII decoding. So no matter which format my string had before the write() method will always decode to ASCII (which can't be done with >128). But is there an alternative to sending the command via TCP/IP without using the write() method?

d307
  • 1
  • 2
  • 1
    `instr.write('11001\xb6')` – falsetru Jan 07 '16 at 12:11
  • thanks, but this and u"\u00b6" don't work either – d307 Jan 07 '16 at 17:55
  • "ASCII value is above 128": no such thing. Are you dealing with binary, pure text or binary mixed into text? If pure text, which encoding is the instrument expecting? (Match your pyVISA to suit; sorry, I don't know how.) If binary, just send it as binary. If mixed, you'll have to mix it yourself and [send it as binary](http://pyvisa.readthedocs.org/en/stable/rvalues.html#writing-binary-values). – Tom Blodget Jan 08 '16 at 01:52

0 Answers0