Exemplo n.º 1
0
 public Form1()
 {
     InitializeComponent();
     physicalPorts[0] = new SerialPort("COM1", 9600);
     physicalPorts[1] = new TcpClient("127.0.0.1", 2756);
     parsedPort       = new TopPort(physicalPorts[1], new FootParser(foot));
     parsedPort.OnReceiveParsedData += ReceiverDataEventAsync;
     //Task.Run(async () =>
     //{
     //    while (true)
     //    {
     //        await parsedPort.SendAsync(new byte[] { 0x01, 0x03, 0x10, 0x02, 0x00, 0x04, 0xE1, 0x09 });
     //        await Task.Delay(3000);
     //    }
     //});
 }
Exemplo n.º 2
0
        private async void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == -1)
            {
                return;
            }
            await parsedPort.CloseAsync();

            if (comboBox1.SelectedIndex == 0)
            {
                parsedPort = new TopPort(physicalPorts[comboBox2.SelectedIndex], new TimeParser(200));
                parsedPort.OnReceiveParsedData += ReceiverDataEventAsync;
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                parsedPort = new TopPort(physicalPorts[comboBox2.SelectedIndex], new HeadFootParser(head, foot));
                parsedPort.OnReceiveParsedData += ReceiverDataEventAsync;
            }
            else if (comboBox1.SelectedIndex == 2)
            {
                parsedPort = new TopPort(physicalPorts[comboBox2.SelectedIndex], new HeadLengthParser(head, async data =>
                {
                    if (data.Length < 2)
                    {
                        return new GetDataLengthRsp()
                        {
                            ErrorCode = Parser.ErrorCode.LengthNotEnough
                        }
                    }
                    ;
                    return(await Task.FromResult(new GetDataLengthRsp()
                    {
                        Length = data[1], ErrorCode = Parser.ErrorCode.Success
                    }));
                }));
                parsedPort.OnReceiveParsedData += ReceiverDataEventAsync;
            }
            else if (comboBox1.SelectedIndex == 3)
            {
                parsedPort = new TopPort(physicalPorts[comboBox2.SelectedIndex], new FootParser(foot));
                parsedPort.OnReceiveParsedData += ReceiverDataEventAsync;
            }
            await parsedPort.OpenAsync();
        }
Exemplo n.º 3
0
 public TilesLayer(ITopPort topPort)
 {
     _topPort = topPort;
     _topPort.OnReceiveParsedData += async data => OnReceiveData?.Invoke(data);
 }
Exemplo n.º 4
0
 public TilesLayer(ITopPort topPort)
 {
     _topPort = topPort;
     _topPort.OnReceiveParsedData += async data => { OnReceiveData?.Invoke(data); await Task.CompletedTask; };
 }