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

ZMQ Serial driver #35

Open
wants to merge 10 commits into
base: development
Choose a base branch
from
Open

ZMQ Serial driver #35

wants to merge 10 commits into from

Conversation

simbilod
Copy link
Collaborator

@simbilod simbilod commented Apr 20, 2022

New driver class for serial connections that occur through an intermediate server, for instance

User <--> Client (e.g. instrumentation server) <--ZMQ--> Server/controller (e.g. Raspberry PI) <--Serial/USB--> Instrument

There is also an example of a driver leveraging this (MDT693B, Thorlabs Piezo Controller)

As described in the example notebook, the user experience is setup to be identical to other lightlab drivers. The user only needs to connect the server/controller machine to the instrument, and setup passwordless SSH access from the client machine to it. Then, for the user it is as if the instrument is directly connected to the client, with simple execution such as

    stage = MDT693B_OLPC(name='stage', server_address='IP_address', server_user='pi')
    print(stage.set_volt('x', 12)) # outputs 1 for successful upload
    print(stage.get_volt('x')) # outputs 12

This is enabled by the fact that, when instanciating an instrument subclassed from this driver type, ZMQ server code is automatically uploaded and then persistently executed on the server/controller. The client can then use ZMQclient methods such as request and write to send commands to the instrument, relayed through the server/controller. The user can then entirely focus on adapting the serial commands from the instrument manual:

def get_volt(self, axis):
    cmd = "{}voltage?".format(axis)
    ans = self.request(cmd)
    return float(ans.strip('[]\r> '))

TODO:

  • Allow non-passwordless connections between client and server/controller. Since there is only one SSH connection during instanciation, it would be nice to have the option to just provide a password once there (like Paramiko allows).
  • Add hardware-free unit test, maybe spawing client/server on localhost with a dummy instrument.
  • Add better logging, need to decide what to do about server vs client logging, since user presumably only
  • Support for multiple commands on the same communication

@simbilod
Copy link
Collaborator Author

@thomaslima @jclederman just wondering if you have some comments before I merge to development

@jclederman
Copy link
Contributor

I think this makes sense. What happens if two Piezo controllers are connected to the same pi? Is there a way of specifying some local USB address (like the GPIB address)? I'm picturing something similar to the prologix, where there is a pi prefix, the ip address, then the local address

@simbilod
Copy link
Collaborator Author

Yes sorry should have linked the notebook. Look at the function call for the driver/ZMQclient here

@atait
Copy link
Collaborator

atait commented Apr 20, 2022

+1 for decentralization! This will be useful. Could you put some things in the automated test? It could be very simple like launching a server process, then pinging it at "localhost". @simbilod I have just shared some code to your email with similar examples.

@simbilod
Copy link
Collaborator Author

@jclederman in your example you would spin two servers on two different zmq_ports, each with the required serial_port

@atait yes I was thinking about that (it's on the TODO). Thanks for the example. I will add this before I merge.

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

Successfully merging this pull request may close these issues.

3 participants