Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input buffer is not cleared #1028

Open
d-el opened this issue Jan 18, 2024 · 1 comment
Open

Input buffer is not cleared #1028

d-el opened this issue Jan 18, 2024 · 1 comment

Comments

@d-el
Copy link

d-el commented Jan 18, 2024

The input buffer is not cleared.

Version

$ pip3 show pymeasure
Name: PyMeasure
Version: 0.13.1
Summary: Scientific measurement library for instruments, experiments, and live-plotting
Home-page: https://github.com/pymeasure/pymeasure
Author: PyMeasure Developers
Author-email: 
License: MIT
Location: /home/del/.local/lib/python3.10/site-packages
Requires: numpy, pandas, pint, pyqtgraph, pyserial, pyvisa
Required-by:

To reproduce (start and abort several times)

import logging
import time
import serial
from pymeasure.instruments.hp import HP34401A

log = logging.getLogger('')
logging.getLogger().addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)

meter = HP34401A('ASRL/dev/ttyUSB0', timeout=5000, baud_rate=1200, data_bits=8, parity=0)
#meter.adapter.flush_read_buffer() # does not affect
#meter.adapter._read_bytes(-1) # workaround

meter.reset()
meter.clear()
meter.write('SYSTem:REMote')
time.sleep(1)
while True:
	print('meter: {}'.format(meter.id))
	time.sleep(1)`

Output

No visa library specified, trying to find alternatives.
Environment variable PYVISA_LIBRARY is unset.
Not loading dll_extra_paths because we are not on Windows or Python < 3.8
Automatically found library files: [None, None, None, None, None]
No user defined library files
Did not find IVI binary
SerialSession was correctly imported.
USBSession and USBRawSession were not imported No module named 'usb'.
TCPIPSession was correctly imported.
GPIBSession was not imported No module named 'gpib'.
pyvisa-py is available.
Created library wrapper for py
Created ResourceManager with session 7483050
ASRL/dev/ttyUSB0::INSTR - opening ...
ASRL/dev/ttyUSB0::INSTR - is open with session 9652017
Initializing HP 34401A.
WRITE:*RST
Serial.write b'*RST\r\n'
WRITE:*CLS
Serial.write b'*CLS\r\n'
WRITE:SYSTem:REMote
Serial.write b'SYSTem:REMote\r\n'
WRITE:*IDN?
Serial.write b'*IDN?\r\n'
ASRL/dev/ttyUSB0::INSTR - reading 20480 bytes (last status <StatusCode.success_max_count_read: 1073676294>)
Traceback (most recent call last):
  File "/mnt/hd500/workspace/hp.py", line 21, in <module>
    print('meter: {}'.format(meter.id))
  File "/home/del/.local/lib/python3.10/site-packages/pymeasure/instruments/common_base.py", line 298, in __getattribute__
    return super().__getattribute__(name)
  File "/home/del/.local/lib/python3.10/site-packages/pymeasure/instruments/instrument.py", line 133, in id
    return self.ask("*IDN?").strip()
  File "/home/del/.local/lib/python3.10/site-packages/pymeasure/instruments/common_base.py", line 387, in ask
    return self.read()
  File "/home/del/.local/lib/python3.10/site-packages/pymeasure/instruments/instrument.py", line 152, in read
    return self.adapter.read(**kwargs)
  File "/home/del/.local/lib/python3.10/site-packages/pymeasure/adapters/adapter.py", line 108, in read
    read = self._read(**kwargs)
  File "/home/del/.local/lib/python3.10/site-packages/pymeasure/adapters/visa.py", line 172, in _read
    return self.connection.read(**kwargs)
  File "/home/del/.local/lib/python3.10/site-packages/pyvisa/resources/messagebased.py", line 485, in read
    message = self._read_raw().decode(enco)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe1 in position 0: ordinal not in range(128)
Closing ResourceManager (session: 7483050)
ASRL/dev/ttyUSB0::INSTR - closing
ASRL/dev/ttyUSB0::INSTR - is closed
ASRL/dev/ttyUSB0::INSTR - closing
@msmttchr
Copy link
Member

@d-el, this look like a pyvisa issue, isn't it ?
Have you tried to replicate the same problem using directly pyvisa?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants