Exemplo n.º 1
0
 public SerialModel(string port, ModbusModel model, IModbusScanner scanner)
 {
     this.model   = model;
     this.scanner = scanner;
     serial       = new SerialPort(port);
     serial.Open();
     Task.Factory.StartNew(Run);
 }
Exemplo n.º 2
0
 public TcpServerModel(ModbusModel model, IModbusScanner scanner)
 {
     this.model   = model;
     this.scanner = scanner;
     server       = new TcpListener(IPAddress.Loopback, 0);
     server.Start();
     port = ((IPEndPoint)server.LocalEndpoint).Port;
     Task.Factory.StartNew(Run);
 }
Exemplo n.º 3
0
        void Test(IModbusScanner scanner, IModbusProtocol protocol, IModbusCommand cmd)
        {
            const int offset  = 2;
            var       wrap    = protocol.Wrap(cmd);
            var       request = new byte[offset + wrap.RequestLength];

            wrap.FillRequest(request, offset);
            scanner.Append(request, offset, wrap.RequestLength);
            Assert.AreEqual(wrap.ToString(), scanner.Scan().ToString());
        }
Exemplo n.º 4
0
 void Test(IModbusScanner scanner, IModbusProtocol protocol)
 {
     Test(scanner, protocol, new ModbusF01ReadCoils(0x01, 0x0203, 0x0405));
     Test(scanner, protocol, new ModbusF02ReadInputs(0x01, 0x0203, 0x0405));
     Test(scanner, protocol, new ModbusF03ReadHoldingRegisters(0x01, 0x0203, 0x0405));
     Test(scanner, protocol, new ModbusF04ReadInputRegisters(0x01, 0x0203, 0x0405));
     Test(scanner, protocol, new ModbusF05WriteCoil(0x01, 0x0203, true));
     Test(scanner, protocol, new ModbusF05WriteCoil(0x01, 0x0203, false));
     Test(scanner, protocol, new ModbusF06WriteRegister(0x01, 0x0203, 0x0405));
     Test(scanner, protocol, new ModbusF15WriteCoils(0x01, 0x0203, bo()));
     Test(scanner, protocol, new ModbusF15WriteCoils(0x01, 0x0203, bo(true)));
     Test(scanner, protocol, new ModbusF15WriteCoils(0x01, 0x0203, bo(false)));
     Test(scanner, protocol, new ModbusF15WriteCoils(0x01, 0x0203, bo(true, false, true, false, true, false, true)));
     Test(scanner, protocol, new ModbusF15WriteCoils(0x01, 0x0203, bo(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false)));
     Test(scanner, protocol, new ModbusF16WriteRegisters(0x01, 0x0203, us()));
     Test(scanner, protocol, new ModbusF16WriteRegisters(0x01, 0x0203, us(0x0405, 0x0607, 0x0809, 0x0A0B)));
     Test(scanner, protocol, new ModbusF16WriteRegisters(0x01, 0x0203, us(0x0405, 0x0607, 0x0809, 0x0A0B, 0x0405, 0x0607, 0x0809, 0x0A0B, 0x0405, 0x0607, 0x0809, 0x0A0B)));
 }
Exemplo n.º 5
0
 public ModelStream(ModbusModel model, IModbusScanner scanner)
 {
     this.model   = model;
     this.scanner = scanner;
 }