Example #1
0
        public override async Task <bool> ConnectAsync()
        {
            ProtocalLinker = new SiemensPpiProtocalLinker(_com);
            var inputStruct  = new ComCreateReferenceSiemensInputStruct(SlaveAddress, MasterAddress);
            var outputStruct =
                await await
                ForceSendReceiveAsync(this[typeof(ComCreateReferenceSiemensProtocal)],
                                      inputStruct).
                ContinueWith(async answer =>
            {
                if (!ProtocalLinker.IsConnected)
                {
                    return(false);
                }
                var inputStruct2  = new ComConfirmMessageSiemensInputStruct(SlaveAddress, MasterAddress);
                var outputStruct2 =
                    (ComConfirmMessageSiemensOutputStruct)
                    await
                    ForceSendReceiveAsync(this[typeof(ComConfirmMessageSiemensProtocal)],
                                          inputStruct2);
                return(outputStruct2 != null);
            });

            return(outputStruct);
        }
        public override async Task <byte[]> SendReceiveWithoutExtAndDecAsync(byte[] content)
        {
            var ans = await base.SendReceiveWithoutExtAndDecAsync(content);

            while (ans.Length == 1 && ans[0] == 0xf9)
            {
                Thread.Sleep(500);
                if (content.Length <= 6)
                {
                    var inputStruct2 = new ComConfirmMessageSiemensInputStruct(content[1], content[2]);
                    ans =
                        await SendReceiveWithoutExtAndDecAsync(
                            new ComConfirmMessageSiemensProtocal().Format(inputStruct2));
                }
                else
                {
                    var inputStruct2 = new ComConfirmMessageSiemensInputStruct(content[4], content[5]);
                    ans =
                        await SendReceiveWithoutExtAndDecAsync(
                            new ComConfirmMessageSiemensProtocal().Format(inputStruct2));
                }
            }
            return(ans);
        }
        public override async Task <byte[]> SendReceiveAsync(byte[] content)
        {
            var extBytes = BytesExtend(content);

            if (extBytes[6] == 0x7c)
            {
                var inputStruct2  = new ComConfirmMessageSiemensInputStruct(content[4], content[5]);
                var receiveBytes2 =
                    await SendReceiveWithoutExtAndDecAsync(
                        new ComConfirmMessageSiemensProtocal().Format(inputStruct2));
            }
            var receiveBytes = await SendReceiveWithoutExtAndDecAsync(extBytes);

            if (content.Length > 6 && receiveBytes.Length == 1 && receiveBytes[0] == 0xe5)
            {
                var inputStruct2  = new ComConfirmMessageSiemensInputStruct(content[4], content[5]);
                var receiveBytes2 =
                    await SendReceiveWithoutExtAndDecAsync(
                        new ComConfirmMessageSiemensProtocal().Format(inputStruct2));

                return(BytesDecact(receiveBytes2));
            }
            return(BytesDecact(receiveBytes));
        }