Parsing string containing ascii codes to float

1.6k views Asked by At

I'm using pyvisa to control a Signal recovery sr7225 lockin amplifier. Almost everything works as expected. There is only one problem, when the queried value is exactly zero and one queries in the floating point mode the following is returned

>>>import visa
>>>lockin = visa.instrument('GPIB::08')
>>>lockin.ask('X.') # Query X value in floating point mode
0.0E+00\x00

An ascii value is appended to the response string. I guess the appended ascii value of \x00 is a bug, but it means that I cannot use float() to convert the string response to float. How would you handle this?

1

There are 1 answers

0
georg On BEST ANSWER

simply

float(x.strip('\x00')) ?