autolab-project / autolab

Python package for laboratory instruments control and scientific experiments automation

Home Page:https://autolab.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example driver using serial

RR-C2N opened this issue · comments

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

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