mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 22:38:27 +08:00
refactor: Extract WriteS7Header
This commit is contained in:
@@ -20,6 +20,16 @@ namespace S7.Net
|
||||
stream.Write(new byte[] { 0x02, 0xf0, 0x80 });
|
||||
}
|
||||
|
||||
private static void WriteS7Header(System.IO.MemoryStream stream, byte messageType, int parameterLength, int dataLength)
|
||||
{
|
||||
stream.Write(0x32); // S7 protocol ID
|
||||
stream.Write(messageType); // Message type
|
||||
stream.Write(new byte[] { 0x00, 0x00 }); // Reserved
|
||||
stream.Write(new byte[] { 0x00, 0x00 }); // PDU ref
|
||||
stream.Write(Word.ToByteArray((ushort) parameterLength));
|
||||
stream.Write(Word.ToByteArray((ushort) dataLength));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the header to read bytes from the PLC
|
||||
/// </summary>
|
||||
@@ -30,10 +40,9 @@ namespace S7.Net
|
||||
// Header size 19, 12 bytes per item
|
||||
WriteTpktHeader(stream, 19 + (12 * amount));
|
||||
WriteDateHeader(stream);
|
||||
stream.Write(new byte[] { 0x32, 0x01, 0x00, 0x00, 0x00, 0x00 });
|
||||
//data part size
|
||||
stream.Write(Word.ToByteArray((ushort)(2 + (amount * 12))));
|
||||
stream.Write(new byte[] { 0x00, 0x00, 0x04 });
|
||||
WriteS7Header(stream, 0x01, 2 + amount * 12, 0);
|
||||
// Function code: read request
|
||||
stream.Write(0x04);
|
||||
//amount of requests
|
||||
stream.WriteByte((byte)amount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user