/// <summary> Wait for moving complete. </summary> /// <returns> true if it succeeds, false if it fails. </returns> private bool WaitForMovingComplete() { // get a Thorlabs simple message to request a status as a byte[] array MessageStruct statusMessage = ThorlabsDevice.SimpleMessageStruct(DeviceMessages.MGMSG_MOT_REQ_DCSTATUSUPDATE); // NOTE - some devices use 0x0480 as status request byte[] byteArray = Utilities.SerializeMessage(statusMessage); // loop until move complete bool moved = false; while (!moved) { // send status request command _device.SendCommand(byteArray); // get any response (maybe a status response or a move complete response) byte[] response = _device.WaitForUnknownReply(250); // get response as a message structure object returnObject = ObjectFromData(response); if (returnObject != null) { // if a motor status then check for moving bit if (returnObject is MotorStatus) { moved = ((((MotorStatus)returnObject)._status & 0x00f0) == 0); } // if a simple message structure then check for move complete message if (returnObject is MessageStruct) { moved = ((MessageStruct)returnObject)._messageId == DeviceMessages.MGMSG_MOT_MOVE_COMPLETE; } } } return(true); }
/// <summary> Wait for homing to complete. </summary> /// <returns> true if it succeeds, false if it fails. </returns> private bool WaitForHomimgComplete() { // get a Thorlabs simple message to request a status as a byte[] array MessageStruct statusMessage = ThorlabsDevice.SimpleMessageStruct(DeviceMessages.MGMSG_MOT_REQ_DCSTATUSUPDATE); byte[] byteArray = Utilities.SerializeMessage(statusMessage); // loop until homed complete bool homed = false; while (!homed) { // send status request command _device.SendCommand(byteArray); // get any response (maybe a status response or a homed response) byte[] response = _device.WaitForUnknownReply(250); // get response as a message structure object returnObject = ObjectFromData(response); if (returnObject != null) { // if a motor status then check the homing bit if (returnObject is MotorStatus) { homed = ((((MotorStatus)returnObject)._status & 0x0400) != 0); } // if a simple message structure then check for homed message if (returnObject is MessageStruct) { homed = ((MessageStruct)returnObject)._messageId == DeviceMessages.MGMSG_MOT_MOVE_HOMED; } } } return(true); }
/// <summary> Constructor. </summary> /// <param name="distance"> The distance. </param> public MotorMoveRelative(Int32 distance) { _channel = 1; _header = ThorlabsDevice.SimpleMessageStruct(DeviceMessages.MGMSG_MOT_MOVE_RELATIVE); _header._packetLength = 6; _header._destination |= 0x80; _distance = distance; }
/// <summary> Starts a move operation. </summary> /// <param name="step"> Amount to increment by. </param> /// <param name="complete"> [out] The complete. </param> /// <returns> true if it succeeds, false if it fails. </returns> private bool StartMoving(int step, out bool complete) { complete = false; // gets the MotorMoveRelative command structure as a byte[] array MotorMoveRelative motorMessage = new MotorMoveRelative(step); byte[] byteArray = Utilities.SerializeMessage(motorMessage); // flush any existing messages and send move message _device.FlushMessages(); if (!_device.SendCommand(byteArray)) { return(false); } // get a Thorlabs simple message to request a status as a byte[] array MessageStruct statusMessage = ThorlabsDevice.SimpleMessageStruct(DeviceMessages.MGMSG_MOT_REQ_DCSTATUSUPDATE); // NOTE - some devices use 0x0480 as status request byteArray = Utilities.SerializeMessage(statusMessage); // loop until device is moving bool started = false; while (!started && !complete) { // request status _device.SendCommand(byteArray); // get any response (maybe a status response or a move complete response) byte[] response = _device.WaitForUnknownReply(250); // get response as a message structure object returnObject = ObjectFromData(response); if (returnObject != null) { // if a motor status then check for moving bit if (returnObject is MotorStatus) { started = ((((MotorStatus)returnObject)._status & 0x00f0) != 0); } // if a simple message structure then check for move complete message if (returnObject is MessageStruct) { complete = ((MessageStruct)returnObject)._messageId == DeviceMessages.MGMSG_MOT_MOVE_COMPLETE; } } } return(true); }
/// <summary> Starts a homing operation. </summary> /// <param name="complete"> [out] The complete. </param> /// <returns> true if it succeeds, false if it fails. </returns> private bool StartHoming(out bool complete) { complete = false; // gets the MotorHome command structure as a byte[] array MessageStruct message = ThorlabsDevice.SimpleMessageStruct(DeviceMessages.MGMSG_MOT_MOVE_HOME); byte[] byteArray = Utilities.SerializeMessage(message); // flush any existing messages and send move message _device.FlushMessages(); if (!_device.SendCommand(byteArray)) { return(false); } // get a Thorlabs simple message to request a status as a byte[] array MessageStruct statusMessage = ThorlabsDevice.SimpleMessageStruct(DeviceMessages.MGMSG_MOT_REQ_DCSTATUSUPDATE); byteArray = Utilities.SerializeMessage(statusMessage); // loop until device is homing bool started = false; while (!started && !complete) { // request status _device.SendCommand(byteArray); // get any response (maybe a status response or a homed response) byte[] response = _device.WaitForUnknownReply(250); // get response as a message structure object returnObject = ObjectFromData(response); if (returnObject != null) { // if a motor status then check the homing bit if (returnObject is MotorStatus) { started = ((((MotorStatus)returnObject)._status & 0x0200) != 0); } // if a simple message structure then check for homed message if (returnObject is MessageStruct) { complete = ((MessageStruct)returnObject)._messageId == DeviceMessages.MGMSG_MOT_MOVE_HOMED; } } } return(true); }
/// <summary> Gets the correct message structure for the supplied message byte[] array. </summary> /// <param name="data"> The source byte[] array. </param> /// <returns> The correct message structure of NULL if not known. </returns> public object ObjectFromData(byte[] data) { if ((data == null) || (data.Length < 6)) { return(null); } // select depending upon the Message Id switch (ThorlabsDevice.MessageType(data)) { case 0: return(null); case DeviceMessages.MGMSG_MOT_GET_DCSTATUSUPDATE: // DC Servo Motor Status response message case DeviceMessages.MGMSG_MOT_GET_STATUSUPDATE: // Stepper Motor Status response message return(Utilities.DeserializeMsg <MotorStatus>(data)); case DeviceMessages.MGMSG_MOT_MOVE_HOMED: // Motor Homed Message case DeviceMessages.MGMSG_MOT_MOVE_COMPLETE: // Motor Moved Message return(Utilities.DeserializeMsg <MessageStruct>(data)); } return(null); }
/// <summary> Constructor. </summary> /// <param name="device"> The device. </param> public ThorlabsMotorHome(ThorlabsDevice device) : base(device) { }
/// <summary> Constructor. </summary> /// <param name="device"> The device. </param> protected ThorlabsMotor(ThorlabsDevice device) { _device = device; }
/// <summary> Constructor. </summary> /// <param name="device"> The device. </param> public ThorlabsMotorMove(ThorlabsDevice device) : base(device) { }