Read and control a laser
This walkthrough reads the state of a laser every second, then sets its power and turns emission on.
Read the laser state
Hover over the workflow below and click its copy button, then paste it into an empty Bonsai workflow.
TimertriggersCreateCommandimmediately, then every second.CreateCommand, withCommandset toGetState, creates a command for each trigger.Deviceopens the serial port inPortName, sends each command and emits its reply. Each command waits for the reply to the previous one.ParseReply, withCommandset toGetState, emits theLaserStateof each reply.
Select Device and set PortName to the port of your laser; the drop-down lists the ports of this computer. Press F5 to start and double-click ParseReply to see the emission, operating mode, power, current, base plate temperature, status and faults. Stop with Shift+F5; the port is closed when the workflow stops.
Set the power and turn emission on
Warning
This workflow turns emission on. Make sure the beam is safely blocked.
- Three
CreateCommandnodes without inputs each create one command when the workflow starts:SetOperatingMode(constant power),SetPower(10 mW) andSetEmission(on). Concatsends them toDevicein that order.EnsureSuccessstops the workflow with an error if the laser rejects any of them, for example a power above its maximum.
Emission may start a few seconds after SetEmission, because of the laser warm-up and the 5 s CDRH delay. Device turns emission off when the workflow stops.
If it does not run
| Symptom | What to check |
|---|---|
Specify the serial port of the laser in PortName |
Set PortName on Device |
| Access to the port is denied | Another program, such as Coherent Connection or another workflow, has the port open |
| The sequence times out | The laser is off, on another port, or behind a controller: set Channel on CreateCommand |
ParseReply emits nothing |
The command was rejected: inspect the replies of Device, or add EnsureSuccess |
Continue with commands.