User:Don Kirkby

From ZaberWiki
Jump to: navigation, search

I wrote the .NET version of the sample projects, along with a reusable Zaber library. I also wrote the LabVIEW instrument driver.

If you can't get enough of my writing, check out my posts at Stack Overflow or my projects at Google Code. I also have some photos on flickr.

Send me an e-mail.

New sample scripts

This section is a draft version for a new feature of Zaber Console that will be released soon.

Units of Measure

By default, all positions are sent in microsteps. You can also specify a position in standard units of measure like millimeters, inches, or degrees. If your device supports that unit of measure, then it will be converted to microsteps for you.

You can see which units of measure are available by looking on the settings tab of Zaber Console, or by opening the Script Editor, clicking the Help menu, and choosing Zaber Library Help File. Look at the UnitOfMeasure class fields.

// C# or Javascript example script using units of measure
#template(Simple)

var mm = UnitOfMeasure.Millimeter;

// Read starting position and display it in units
var startPosition = 
    Conversation.Request(Command.ReturnCurrentPosition).Measurement;
Output.WriteLine("Starting at {0}.", startPosition);

// Go to a specific position
var position2 = Conversation.Request(Command.MoveAbsolute, 5, mm).Measurement;
Output.WriteLine("Moved to {0}.", position2);
' Visual Basic.NET example script using units of measure
#template(Simple)

Dim mm As UnitOfMeasure = UnitOfMeasure.Millimeter

' Read starting position and display it in units
Dim startPosition As Measurement = _
    Conversation.Request(Command.ReturnCurrentPosition).Measurement
Output.WriteLine("Starting at {0}.", startPosition)

' Go to a specific position
Dim position2 As Measurement = _
    Conversation.Request(Command.MoveAbsolute, 5, mm).Measurement
Output.WriteLine("Moved to {0}.", position2)


Calculating With Units of Measure

In addition to specifying literal measurement values like new Measurement(5, UnitOfMeasure.Millimeter), you can also perform calculations on measurement objects. Two main types of operations are supported:

  1. Add two measurements together - the result uses the units of measure from the second argument, and the first argument is converted if necessary.
  2. Multiply a measurement by a ratio.

Subtraction, negation, and division are also supported. These basic operations can be combined to do other things if you define a unit variable like this:

var mm = new Measurement(1, UnitOfMeasure.Millimeter);

Now I can add five millimeters to a measurement position like this:

position + 5*mm

I can convert position to millimeters like this:

position + 0*mm

Here's a full example that uses these two tricks:

// C# example script calculating with units of measure
#template(Simple)

var mm = new Measurement(1, UnitOfMeasure.Millimeter);

// Read starting position and display it in units
var startPosition = 
    Conversation.Request(Command.ReturnCurrentPosition).Measurement;
Output.WriteLine("Starting at {0}.", startPosition + 0*mm);

// Go to a specific position
var position2 = Conversation.Request(Command.MoveAbsolute, 5*mm).Measurement;
Output.WriteLine("Moved to {0}.", position2);

// 10mm beyond starting position.
var position3 = Conversation.Request(
    Command.MoveAbsolute, 
    startPosition + 10*mm).Measurement;
Output.WriteLine("10mm beyond start: {0}.", position3);

// Double the starting position.
var position4 = Conversation.Request(
    Command.MoveAbsolute,
    startPosition * 2).Measurement;
Output.WriteLine("Double the start: {0}.", position4 + 0*mm);
Personal tools
Zaber Website