示例#1
0
        public void Write <TValue>(DataAddress address, IEnumerable <TValue> values)
        {
            if (address.Equals(DataAddress.Empty))
            {
                throw new ApplicationException("地址为空");
            }
            if (values == null || !values.Any())
            {
                throw new ApplicationException($"参数异常,values为null或空");
            }

            var command = ProtocolUpperLinkCommand.GetWriteCommand(address, values);

            byte[] response = { };

            using (new StopwatchWrapper($"写入PLC"))
            {
                response = Send(command);
            }

            if (!response.Any() || !GetString(response).Contains("OK"))
            {
                Reconnect();

                throw new ApplicationException($"写入失败,地址:{address }");
            }
        }
示例#2
0
        public IEnumerable <TValue> Read <TValue>(DataAddress address)
        {
            if (address.Equals(DataAddress.Empty))
            {
                throw new ApplicationException("地址为空");
            }

            var command = ProtocolUpperLinkCommand.GetReadCommand(address);

            byte[] response = { };

            using (new StopwatchWrapper($"读取PLC"))
            {
                response = Send(command);
            }

            if (!response.Any())
            {
                Reconnect();

                throw new ApplicationException($"读取失败,地址:{address }");
            }

            return(GetValues <TValue>(address, response));
        }