/// <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> 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> 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); }