Example driver using serial
RR-C2N opened this issue · 1 comments
RR-C2N commented
Hey guys,
Do you have an example of a driver that uses a serial port? and the way to properly write the Local Configuration file for it?
Thanks,
R
Python-simulation commented
Hi!
Pyvisa can be used to connect to serial ports, you just need to use the correct address and specify the correct baud rate when instantiating your instrument.
For example, the address can be 'ASRL::2::INSTR'
and the baud rate 115200
.
You can look at the driver arduino_CUSTOMSHUTTERS as an example.
Its driver class look like this:
class Driver_VISA(Driver):
def __init__(self, address='ASRL::2::INSTR', **kwargs):
import pyvisa as visa
self.BAUDRATE = 115200
# Instantiation
rm = visa.ResourceManager()
self.inst = rm.open_resource(address)
self.inst.timeout = 5000 #ms
self.inst.baud_rate = self.BAUDRATE
Driver.__init__(self)
def close(self):
try : self.inst.close()
except : pass
def query(self,command):
return self.inst.query(command).strip('\n')
def write(self,command):
self.inst.write(command)
For the config file, it will look like this:
[my_arduino_CUSTOMSHUTTERS]
driver = arduino_CUSTOMSHUTTERS
connection = VISA
address = ASRL::2::INSTR