private bool SendCommand(IcpDeviceModel icpDevice, IcpCommand command, int addr) { string request = IcpDcom.CreateIcpDcomRequest(command, addr); string response = ComReader.SendCommand(request); bool result = IcpDcom.ParseIcpResponse(command, response, icpDevice); if (!result) { logger.Error($"Cant send {command} to {icpDevice.Name}, addr: {addr}, com: {ComReader.Port}"); } return(result); }
static void Main(string[] args) { ComReader comReader = new ComReader("COM1"); IcpDeviceModel deviceModel_3 = new IcpDeviceModel(); IcpDeviceModel deviceModel_9 = new IcpDeviceModel(); if (comReader.Open()) { string cmd = ""; { string request = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetName, 9); string response = comReader.SendCommand(request); bool res = IcpDcom.ParseIcpResponse(IcpCommand.GetName, response, deviceModel_9); request = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetModuleStatus, 9); response = comReader.SendCommand(request); res = IcpDcom.ParseIcpResponse(IcpCommand.GetModuleStatus, response, deviceModel_9); request = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetFirmware, 9); response = comReader.SendCommand(request); res = IcpDcom.ParseIcpResponse(IcpCommand.GetFirmware, response, deviceModel_9); request = IcpDcom.CreateIcpDcomRequest(IcpCommand.SetOutputs, 9, "", 15); response = comReader.SendCommand(request); res = IcpDcom.ParseIcpResponse(IcpCommand.SetOutputs, response, deviceModel_9); } { string request = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetName, 3); string response = comReader.SendCommand(request); bool res = IcpDcom.ParseIcpResponse(IcpCommand.GetName, response, deviceModel_3); request = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetFirmware, 3); response = comReader.SendCommand(request); res = IcpDcom.ParseIcpResponse(IcpCommand.GetFirmware, response, deviceModel_3); request = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetInputState, 3); response = comReader.SendCommand(request); res = IcpDcom.ParseIcpResponse(IcpCommand.GetInputState, response, deviceModel_3); } do { Console.Write("Enter command: "); cmd = Console.ReadLine(); var resp = comReader.SendCommand(cmd); Console.WriteLine($"Response: {resp}"); Console.WriteLine(); } while (cmd != "quit"); } }
public static bool PingDevice(int addr, ComReader comReader) { var req = CreateIcpDcomRequest(IcpCommand.GetModuleStatus, addr); var resp = comReader.SendCommand(req); if (string.IsNullOrEmpty(resp)) { return(false); } if (resp[0] == '!') { return(true); } return(false); }
public void TestMethod1() { ComReader comReader = new ComReader("COM1"); comReader.Close(); Thread.Sleep(200); comReader.Close(); Thread.Sleep(200); if (comReader.Open()) { string resp = comReader.SendCommand("$02M"); resp = comReader.SendCommand("$02C"); resp = comReader.SendCommand("$03C"); resp = comReader.SendCommand("$03M"); resp = comReader.SendCommand("$03L0"); resp = comReader.SendCommand("$02L0"); resp = comReader.SendCommand("$@03"); resp = comReader.SendCommand("$@02"); } }