Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            var configurationRoot = new ConfigurationBuilder()
                                    .SetBasePath(Directory.GetCurrentDirectory())
                                    .AddJsonFile("AppConfig.Json").Build();
            var serial = new SerialPort("com2", 9600);

            serial.Open();
            var reader = new BinaryReader(serial.BaseStream);
            var writer = new BinaryWriter(serial.BaseStream);
            var option = new SerialPortDataTransportOption();

            configurationRoot.GetSection(nameof(SerialPortDataTransportOption)).Bind(option);

            _dataTransport = new DeviceSerialDataTransport((new OptionsWrapper <SerialPortDataTransportOption>(option)));
            _dataTransport.Open();
            var b = new byte[] { 0xaa, 0xaa, 0x00, 0x64, 0x04, 0x04 };

            _dataTransport.Channels[0].DataReceived += Channel_DataReceived;
            var packet = new Device()
            {
                Content = new Data()
                {
                    Content = new Fault()
                    {
                    }
                }
            };

            while (true)
            {
                //writer.Write(b);
                if (serial.BytesToRead > 0)
                {
                    //Console.WriteLine(reader.ReadBytes(serial.BytesToRead).ToHexString());
                    writer.Write(reader.ReadBytes(serial.BytesToRead));
                    ;
                }
                lock (_o)
                    while (_list.Count > _index)
                    {
                        Console.WriteLine(_list[_index++]);
                    }

                (_dataTransport.Channels[0]).Transmit(packet);
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 2
0
 public DeviceService(DeviceSerialDataTransport deviceSerialDataTransport)
 {
     _deviceSerialDataTransport = deviceSerialDataTransport;
 }