Пример #1
0
        public override void GetMemoryRequest(DeviceCode code, ushort offset, ushort count)
        {
            var request         = this.CreatePacket();
            var requestFunction = new MCFunctionBatchReadRequest();

            requestFunction.DeviceCode = code;
            requestFunction.Offset     = offset;
            requestFunction.Count      = count;
            request.Function           = requestFunction;

            using (var sw = new StreamWrapper(this.Stream))
            {
                try
                {
                    this.Protocol.WritePacket(sw, request);
                    var response = this.Protocol.ReadPacket(sw, request.Function);

                    if (response.Function is MCFunctionBatchReadResponse responseFunction)
                    {
                        this.Logger.OnMessageLog("Get : " + code.ToString() + offset + ".." + count + "=" + ObjectUtils.ToString(responseFunction.Data));
                    }
                    else
                    {
                        this.Logger.OnMessageLog("Err : " + ((MCQHeaderResponse)response.QHeader).ResultCode.ToString("X4"));
                    }
                }
                finally
                {
                    this.Logger.OnCommunicationLog(sw.Log);
                }
            }
        }
Пример #2
0
        public static void Write(DeviceCode code, MCDataProcessor target)
        {
            if (target.DataCode == CommunicationDataCode.BINARY)
            {
                target.WriteByte((byte)code);
            }
            else if (target.DataCode == CommunicationDataCode.ASCII)
            {
                bool prev = target.IgnoreConvert;
                try
                {
                    target.IgnoreConvert = true;
                    var bytes = Encoding.Default.GetBytes(code.ToString().PadRight(2, '*'));

                    target.WriteBytes(bytes);
                }
                finally
                {
                    target.IgnoreConvert = prev;
                }
            }
        }
Пример #3
0
        public override void GetMemoryRequest(DeviceCode code, ushort offset, ushort count)
        {
            var values = this.MemoryMap.Get(code, offset, count);

            this.Logger.OnMessageLog("Get : " + code.ToString() + offset + ".." + count + "=" + ObjectUtils.ToString(values));
        }
Пример #4
0
 public override void SetMemoryRequest(DeviceCode code, ushort offset, ushort[] values)
 {
     this.MemoryMap.Set(code, offset, values);
     this.Logger.OnMessageLog("Set : " + code.ToString() + offset + ".." + values.Length + "=" + ObjectUtils.ToString(values));
 }