I have written a script in Zaber Console to control my stages, but now I want to take some sensor readings during the movement. I want to move the stages, take a reading, and then move the stages again. Sometimes the sensor readings will affect the movements I need to make. How can I coordinate the movement with the sensor readings?
I want to talk to my Zaber devices on one serial port, and my sensor on a second serial port.
When you write a Zaber Console script, you have access to everything in the Microsoft.NET framework, so you can open a second serial port yourself. Here's a simple example that tries to maintain a constant pressure on a pressure sensor. Each time through the loop, it reads the pressure sensor, then either retracts the device to increase the pressure or extends the device to decrease the pressure.
The
using
block makes sure that you close the serial port even when errors occur. The pressure sensor I used understoodct0
as a tare command ando0w1
as a command to return the current pressure, you'll need to look at your sensor's manual to see what commands it understands. You'll also need to look up what baud rate and other settings to use. TheSerialPort
documentation lists all the communication parameters you can set.If you want to record the data from the sensor readings, one option is to just use
Output.WriteLine(data)
to dump the data values in the output window. Then you can copy and paste them into a spreadsheet or some other file. If you want to write directly to the file, look at theFile.CreateText()
method.