/// <summary> Get the device MotorInfo structure. </summary> /// <returns> Success if the motor info retrieved succesfully. </returns> public bool GetMotorInfo(char motorID) { if (!IsMotorIdValid(motorID)) { return(false); } UpdateOutput(string.Format("Requesting Motor{0} info...", motorID)); ELLDevicePort.SendString(Address, "i" + motorID); try { string msg = ELLDevicePort.WaitForResponse(Address, "I" + motorID, MoveTimeout); if (!string.IsNullOrEmpty(msg)) { MotorInfo info = new MotorInfo(msg); _motorInfo[motorID] = info; UpdateOutput("Get Device Status: ", info.Description()); UpdateParameter(MessageUpdater.UpdateTypes.MotorInfo, Address, info); return(true); } } catch (ELLException) { UpdateOutput(string.Format("Requesting Motor{0}: FAILED", motorID)); } return(false); }
/// <summary> Scans the addresses. </summary> /// <param name="minDeviceAddress"> The minimum device address. </param> /// <param name="maxDeviceAddress"> The maximum device address. </param> /// <returns> Returns a list of available device addresses. </returns> public List <string> ScanAddresses(char minDeviceAddress, char maxDeviceAddress) { List <string> connections = new List <string>(); if (!ELLDevicePort.IsConnected) { return(connections); } _messageUpdater.UpdateOutput("Scanning for devices"); foreach (char address in ELLBaseDevice.ValidAddresses.Where(item => item >= minDeviceAddress && item <= maxDeviceAddress)) { ELLDevicePort.SendString(address, "in"); try { string msg = ELLDevicePort.WaitForResponse(address, "IN", ELLBaseDevice.StatusTimeout); if (!string.IsNullOrEmpty(msg)) { connections.Add(msg); } } catch (ELLException e) { Debug.WriteLine(e.Message); // device address not used } } _messageUpdater.UpdateOutput(connections.Count < 2 ? string.Format("{0} device found", connections.Count) : string.Format("{0} devices found", connections.Count)); return(connections); }
private bool WaitForPositions(List <char> addresses, int msTimeout = MoveTimeout) { try { Dictionary <char, bool> _isCompletedList = addresses.ToDictionary(c => c, c => false); List <string> responses = new List <string> { "GS", "PO" }; int counter = 10 * addresses.Count; while (true) { string msg = ELLDevicePort.WaitForResponse(addresses, responses, msTimeout); if (!string.IsNullOrEmpty(msg)) { bool returnValue; if (TestStatus(msg, "gp", true, ref counter, out returnValue)) { return(returnValue); } char address = msg[0]; if ((msg.Substring(1, 2) == "PO") && addresses.Contains(address)) { if (msg.Length != 11) { return(false); } _position = DeviceInfo.PulseToUnit(msg.Substring(3).ToBytes(8).ToInt(true)); UpdateParameter(MessageUpdater.UpdateTypes.Position, address, _position); _isCompletedList[address] = true; if (_isCompletedList.All(item => item.Value)) { return(true); } } } } } catch (ELLException ex) { UpdateOutput($"Get Device Status: {ex.Message}", true); } return(false); }
private bool WaitForPosition(PaddleIDs paddleID, int msTimeout = MoveTimeout) { try { string command = $"p{(char)paddleID}"; string response = $"P{(char)paddleID}"; List <string> responses = new List <string> { "GS", response }; int counter = 10; while (true) { string msg = ELLDevicePort.WaitForResponse(Address, responses, msTimeout); if (!string.IsNullOrEmpty(msg)) { bool returnValue; if (TestStatus(msg, command, true, ref counter, out returnValue)) { return(returnValue); } if (msg.Substring(1, 2) == response) { if (msg.Length != 7) { return(false); } PaddlePosition position = GetPosition(msg.Substring(3).ToBytes(4).ToInt(true), paddleID); UpdateParameter(MessageUpdater.UpdateTypes.PaddlePosition, Address, position); return(true); } } } } catch (ELLException ex) { UpdateOutput($"Get Device Status: {ex.Message}", true); } return(false); }
private bool WaitForJogstepSize(string cmd, bool getter, int msTimeout = MoveTimeout) { try { List <string> responses = new List <string> { "GS", "GJ" }; int counter = 10; while (true) { string msg = ELLDevicePort.WaitForResponse(Address, responses, msTimeout); if (!string.IsNullOrEmpty(msg)) { bool returnValue; if (TestStatus(msg, cmd, getter, ref counter, out returnValue)) { return(returnValue); } if (msg.Substring(1, 2) == "GJ") { if (msg.Length != 11) { return(false); } _jogstepSize = DeviceInfo.PulseToUnit(msg.Substring(3).ToBytes(8).ToInt(true)); UpdateParameter(MessageUpdater.UpdateTypes.JogstepSize, Address, _jogstepSize); return(true); } } } } catch (ELLException ex) { UpdateOutput($"Get Device Status: {ex.Message}", true); } return(false); }
private bool WaitForPositions(int msTimeout = MoveTimeout) { try { List <string> responses = new List <string> { "GS", "PO" }; int counter = 10; while (true) { string msg = ELLDevicePort.WaitForResponse(Address, responses, msTimeout); if (!string.IsNullOrEmpty(msg)) { bool returnValue; if (TestStatus(msg, "gp", true, ref counter, out returnValue)) { return(returnValue); } if (msg.Substring(1, 2) == "PO") { if (msg.Length != 11) { return(false); } PolarizerPaddlePositions polarizerPaddlePositions = GetPositions(msg.Substring(3).ToBytes(8).ToInt(true)); UpdateParameter(MessageUpdater.UpdateTypes.PolarizerPositions, Address, polarizerPaddlePositions); return(true); } } } } catch (ELLException ex) { UpdateOutput($"Get Device Status: {ex.Message}", true); } return(false); }
/// <summary> Wait for status. </summary> /// <param name="msTimeout"> (Optional) The milliseconds timeout. </param> /// <returns> True if it succeeds, false if it fails. </returns> protected bool WaitForCleaning(int msTimeout = CleanTimeout) { try { int counter = 60; while (true) { string msg = ELLDevicePort.WaitForResponse(Address, "GS", msTimeout); if (!String.IsNullOrEmpty(msg)) { if (msg.Substring(1, 4) == "GS09") { SetSleepDelayCounter(10); while (GetSleepDelayCounter() >= 0) { SetSleepDelayCounter(GetSleepDelayCounter() - 1); Thread.Sleep(1000); } ELLDevicePort.SendString(Address, "gs"); } else { bool returnValue; if (TestStatus(msg, "gs", false, ref counter, out returnValue)) { return(returnValue); } } } } } catch (ELLException ex) { _messageUpdater?.UpdateOutput($"Get Device Status: {ex.Message}", true); } return(false); }
/// <summary> Wait for status. </summary> /// <param name="address"> The device address. </param> /// <param name="msTimeout"> (Optional) The milliseconds timeout. </param> /// <param name="getter"> True to getter. </param> /// <returns> True if it succeeds, false if it fails. </returns> protected bool WaitForStatus(char address, int msTimeout = MoveTimeout, bool getter = false) { try { int counter = 10; while (true) { string msg = ELLDevicePort.WaitForResponse(address, "GS", msTimeout); if (!String.IsNullOrEmpty(msg)) { bool returnValue; if (TestStatus(msg, "gs", getter, ref counter, out returnValue)) { return(returnValue); } } } } catch (ELLException ex) { _messageUpdater?.UpdateOutput($"Get Device Status: {ex.Message}", true); } return(false); }