Example #1
0
        private static bool SendCommand(ComReader comReader, 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);
        }
Example #2
0
        public bool ChangeOutput(string name, int output, int value)
        {
            int addr = IcpDeviceDict
                       .Where(el => el.Value.Name == name)
                       .Select(kv => kv.Value.Address)
                       .FirstOrDefault();

            if (addr == 0)
            {
                return(false);
            }

            var request  = IcpDcom.CreateIcpDcomRequest(IcpCommand.SetOutputs, addr, name, output);
            var response = ComReader.SendCommand(request);

            return(IcpDcom.ParseIcpResponse(IcpCommand.SetOutputs, response, IcpDeviceDict[addr]));
        }
Example #3
0
        public static async Task <List <IcpDeviceModel> > ScanIcpDevicesAsync(ComReader comReader)
        {
            await TaskEx.Run(() =>
            {
                List <IcpDeviceModel> icpDevices = new List <IcpDeviceModel>();
                for (int i = 1; i < 10; i++)
                {
                    if (!IcpDcom.PingDevice(i, comReader))
                    {
                        continue;
                    }

                    IcpDeviceModel devInfo = GetFullInfo(comReader, i);
                    icpDevices.Add(devInfo);
                }
                return(icpDevices);
            });

            return(null);
        }
Example #4
0
 private bool PingIcpDevice(int addr)
 {
     return(IcpDcom.PingDevice(addr, ComReader));
 }