Hello,
I'll try to give you a step by step solution how to build up a packet.
1. Make a command that you want to send to device. (this time lets make setdigout with a timer, as requested).
Command: setdigout 1 60
Lets convert it to HEX: 73 65 74 64 69 67 6f 75 74 20 31 20 36 30
(I have used this calculator to convert a command http://www.unit-conversion.info/texttools/hexadecimal/)
2. Now we have to build up a packet around the command.
a) Packet always starts with 4 zero bytes
00 00 00 00
b) Then let’s add 4 more bytes with data size, at this point we don't know the packet data size so let's just leave a question mark here.
00 00 00 00 00 00 00 ??
c) Lets add one more byte 0C (it's just always 0C)
00 00 00 00 00 00 00 ?? 0C
d) Adding one more byte with number of commands. (in this case we are using only one command so it's 01)
00 00 00 00 00 00 00 ?? 0C 01
e) Lets add one more byte 05 command type (request 05, response 06)
00 00 00 00 00 00 00 ?? 0C 01 05
f) Now let's add 4 bytes with length of the command. So we had a hex: 73 65 74 64 69 67 6f 75 74 20 31 20 36 30 of 14 bytes. So it's 00 00 00 0E.
00 00 00 00 00 00 00 ?? 0C 01 05 00 00 00 0E
g) Then goes command hex which we calculated at step 1.
00 00 00 00 00 00 00 ?? 0C 01 05 00 00 00 0E 73 65 74 64 69 67 6f 75 74 20 31 20 36 30
h) At this point we should add one more byte with number of commands 01
00 00 00 00 00 00 00 ?? 0C 01 05 00 00 00 0E 73 65 74 64 69 67 6f 75 74 20 31 20 36 30 01
i) Now we can calculate data size. It contains a number of bytes that goes after it. (Except CRC witch will be calculated in next step) In this case it’s 22 byte in hex it’s 16.
00 00 00 00 00 00 00 16 0C 01 05 00 00 00 0E 73 65 74 64 69 67 6f 75 74 20 31 20 36 30 01
j) Finally we have to calculate CRC. It's 4 bytes calculated using same bytes that are used to calculate data size (0C 01 05 00 00 00 0E 73 65 74 64 69 67 6f 75 74 20 31 20 36 30 01). CRC is calculated using CRC-16-IBM Reversed 0xA001 Little Endian (DCBA) (Calculator link: https://www.scadacore.com/tools/programming-calculators/online-checksum-calculator/). We are getting 00 00 B3 3E
00 00 00 00 00 00 00 16 0C 01 05 00 00 00 0E 73 65 74 64 69 67 6f 75 74 20 31 2C 36 30 01 00 00 B3 3E
3. So now we have a final command: 00 00 00 00 00 00 00 16 0C 01 05 00 00 00 0E 73 65 74 64 69 67 6f 75 74 20 31 20 36 30 01 00 00 B3 3E
Best regards