1
\$\begingroup\$

I'm just starting out with understanding how modbus works over a rs485 protocol.

I've received a communication protocol document from a company that makes solar inverters.

I want to send a command to the slaves but the documentation notes that I need to send a command + a sub-command.

I'm given a table of protocol characters and a communication table.

Since I'm new to this I'm having a hard time understanding this.

The protocol table:

protocol table

And this is the communication table:

communication table

How would the packet look in hex if I would send the following details:

  • Slave address: 4
  • Command: 32
  • Sub-command: 3

I do understand I need to start the package with the STX, ENQ hex codes. But I have no idea how to construct the rest of the package. Especially the (N, N + 1, N + 2, N + 3) part.

Is there any tutorial that will explain how to construct a package?

I don't understand how I need to provide a value for all the bytes (since I don't know exactly what they mean).

Could somebody give a good example of a packet with these details and please describe each field?

A good tutorial/explanation will also do the job.

I just started studying this for 2 days, so please excuse me if I sound like a complete noob.

Thanks in advance!

\$\endgroup\$
1
\$\begingroup\$

What you ahve there doesn't look like traditional modbus rtu.
Which looks like this:

enter image description here

Of which the standard is freely available at http://www.modbus.org/


But it looks like you have something custom text based. So I think you're on your own here. Or maybe they do use modbus, but made it text based for some reason.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Why do you think it is "something custom text based"? It looks like they named function codes for simplicity, the rest are just bytes. \$\endgroup\$ – Maple Dec 13 '19 at 16:09
  • \$\begingroup\$ @Maple Modbus doesn't use STX/ETX or a command 32. I can be derived from modbus though. \$\endgroup\$ – Jeroen3 Dec 16 '19 at 6:48
  • \$\begingroup\$ My comment was about "text based" part. While they use standard ASCII character codes, they certainly transmit byte packets. It is hard to describe something that uses non-printable character codes as "text based" \$\endgroup\$ – Maple Dec 16 '19 at 7:19
0
\$\begingroup\$

From what you have posted, here is how I see it working for the logical packet.

STX ENQ ADD #Bytes CMD SUBCMD Data (payload) CRC L CRC H ETX

02   05   04   0C(*)  20(**)   03     XX XX XX XX XX XX XX XX XX XX  LL    HH   03

(*) The # bytes is the number of payload bytes (under Data) plus the two command bytes so 0x0C in here (decimal 12) means 10 bytes of payload and two command bytes on the grounds that the commands are also information being sent to the slave device.

(**) This assumes your command above was decimal; if not it should read 32

The CRC is computed over the entire field from STX to the end of the payload data. There is some code for that here although your documentation may use a different method (check the documents).

The data is XX because it might be anything; some messages may have no data except the command and sub-command in which case the # bytes would be 02

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ The payload is not required right? I can't find anything in the documentation about including some payload. If so, can I leave out the whole (data) payload? \$\endgroup\$ – SaltyPotato Dec 13 '19 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.