public Status CheckRequest(byte[] Request) { if (Request.Length < 13) { return(Status.Error); } Header = new MBAP(Request); if (Header.ProtocolID != 0) { return(Status.Error); } switch (Request[1]) { case 0x01: PDU = new ReadCoilsPDU(); break; case 0x02: PDU = new ReadDiscreteInputsPDU(); break; case 0x03: PDU = new ReadHoldingRegistersPDU(); break; case 0x04: PDU = new ReadInputRegistersPDU(); break; case 0x05: PDU = new WriteSingleCoilPDU(); break; case 0x06: PDU = new WriteSingleRegisterPDU(); break; case 0x0F: PDU = new WriteMultipleCoilsPDU(); break; case 0x10: PDU = new WriteMultipleRegistersPDU(); break; default: return(Status.Error); } var PDURequest = new byte[Request.Length - 3]; for (int i = 0; i < PDURequest.Length; i++) { PDURequest[i] = Request[i + 1]; } return(PDU.CheckRequest(PDURequest)); }
public byte[] BuildRequest() { var Request = new byte[ReqSize]; Header = new MBAP(Device.Address, PDU.ReqSize); Request[0] = (byte)((Header.TransactionID >> 8) & 0xFF); Request[1] = (byte)( Header.TransactionID & 0xFF); Request[2] = (byte)((Header.ProtocolID >> 8) & 0xFF); Request[3] = (byte)( Header.ProtocolID & 0xFF); Request[4] = (byte)((Header.Lenght >> 8) & 0xFF); Request[5] = (byte)( Header.Lenght & 0xFF); Request[6] = (byte)( Header.UnitID ); var PDUReq = PDU.BuildRequest(); PDUReq.CopyTo(Request, 7); return Request; }
public byte[] BuildRequest() { var Request = new byte[ReqSize]; Header = new MBAP(Device.Address, PDU.ReqSize); Request[0] = (byte)((Header.TransactionID >> 8) & 0xFF); Request[1] = (byte)(Header.TransactionID & 0xFF); Request[2] = (byte)((Header.ProtocolID >> 8) & 0xFF); Request[3] = (byte)(Header.ProtocolID & 0xFF); Request[4] = (byte)((Header.Lenght >> 8) & 0xFF); Request[5] = (byte)(Header.Lenght & 0xFF); Request[6] = (byte)(Header.UnitID); var PDUReq = PDU.BuildRequest(); PDUReq.CopyTo(Request, 7); return(Request); }
public Status CheckRequest(byte[] Request) { if (Request.Length < 13) return Status.Error; Header = new MBAP(Request); if (Header.ProtocolID != 0) return Status.Error; switch (Request[1]) { case 0x01: PDU = new ReadCoilsPDU(); break; case 0x02: PDU = new ReadDiscreteInputsPDU(); break; case 0x03: PDU = new ReadHoldingRegistersPDU(); break; case 0x04: PDU = new ReadInputRegistersPDU(); break; case 0x05: PDU = new WriteSingleCoilPDU(); break; case 0x06: PDU = new WriteSingleRegisterPDU(); break; case 0x0F: PDU = new WriteMultipleCoilsPDU(); break; case 0x10: PDU = new WriteMultipleRegistersPDU(); break; default: return Status.Error; } var PDURequest = new byte[Request.Length - 3]; for (int i=0; i<PDURequest.Length; i++) PDURequest[i] = Request[i + 1]; return PDU.CheckRequest(PDURequest); }