Using C# to program a zaber stage but getting null variable error in my code for "var speed"

115 views Asked by At
    using System;
    using Zaber.Motion;
    using Zaber.Motion.Ascii;
    namespace ZaberMotion
    {

    class Program
     {
    static Axis x_axis;
    static Device device1;
   
      public static void Main(string[] args)
      {
        Library.EnableDeviceDbStore();

        using (var connection = Connection.OpenSerialPort("COM3"))
        {
            var deviceList = connection.DetectDevices();
            Console.WriteLine($"Found {deviceList.Length} devices.");
            


            var speed = x_axis.Settings.Get("maxspeed",Units.Velocity_MillimetresPerSecond);

            Console.WriteLine("Maximum speed [mm/s]: {0}", speed);

            x_axis.Settings.Set("maxspeed", speed /9.0,Units.Velocity_MillimetresPerSecond);

            }
         }
       }
      }

I am getting a null value for var speed. Simple mistake I am unsure how to fix. Any tips? The initializing of the device and all is successful

1

There are 1 answers

0
ZaberCS On

You need to define the device and axis before you can get the setting for the axis.

after:

var deviceList = connection.DetectDevices();
Console.WriteLine($"Found {deviceList.Length} devices.");

include:

device1 = deviceList[0];
x_axis = device1.GetAxis(1);

Mike McDonald

Zaber Technologies

[email protected]