RS485/RS232/Modbus everything

Announcement - Help us fight the BOTS! Please report all spam including stuff in your inbox!
Joined
Mar 7, 2018
Messages
1,055
This will be brief and compact believe it or not...

So, after a long overdue task to re-visit the battery, solar and inverter setup I took some time to try and consolidate the parts of the system into a single framework that could then be monitored and controled in real-time from different devices.

First up, to get the inverters (1200W grid tie with limiter - separate thread with protocol and code) sorted out so that they can be controlled and the feedback from them does not conflict with other inverters and this needed each one splitting onto a separate RS485 port (yes, yes, RS485 is supposed to be a bus). The software sits on linux and the RS485 adapters are USB plug-in from Aliexpress, which then needed the ports fixing between reboots so that they map correctly :
nano /etc/udev/rules.d/20-usb-serial.rules (create a new file if it does not exist)
KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="2-1:6:1.0", SYMLINK+="ttyUSBmppt01"
KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="2-1:7:1.0", SYMLINK+="ttyUSBmppt02"
KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="2-1.1:1.0", SYMLINK+="ttyUSBinv01"
KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="2-1.2:1.0", SYMLINK+="ttyUSBinv02"
In my instance the "2-1" is the hardware and the ".2:1.0" is the port on the hardware, which is obtained by looking at a combination of :
dmesg | grep tty
lsusb
ls /sys/bus/usb/devices/
udevadm info –attribute-walk –path=/dev/ttyUSB0
This creates symlinks to each port, which you can then use as the consistent mapping.

Next up, the Juntek VAT4300 power meter I have as a shunt between the main -ve and battery -ve busbar. I had a closer look at the USB cable and port because I was curious if the thing used 4 wires and two of them were power then there were only enough cables (2) left for simplified serial and the A/B on the 2 middle pins of USB port inside the main unit indicated RS485. So.... next was to figure out how to find out the baud, parity, etc. and then the protocol.
So, I just cut the cable in half, wired the two bits together and tapped in a separate RS485-USB adapter to the A/B wires. Initially no data at all (which sort of made sense) because the display can send settings back and so must be a protocol handshake of sorts. Plugged in the display and a stream of packets separated by about 30-40mS appeared. Then after a short while 57600 8 data, no parity, 2 stop bits created a stable stream.
Set the port read timeout to 20mS and read buffer size to 50 bytes, which will then read a full packet and timeout so you can read the data and this is the protocol.

Byte offset​
Sample​
Register​
0​
AA​
Address​
1​
1C​
Bytes in data​
2​
01​
1​
??​
3​
01​
1​
01​
??​
4​
12​
2​
5​
61​
2​
4705
Volts / 100​
6​
FF​
3​
7​
EE​
3​
65518​
Amps / 10 (signed Int16)​
8​
00​
4​
9​
01​
4​
10​
4A​
5​
11​
D2​
5​
84690​
Watts / 1000​
12​
00​
6​
13​
02​
6​
14​
F5​
7​
15​
F2​
7​
194034​
Ah / 1000​
16​
06​
8​
17​
0B​
8​
18​
E6​
9​
19​
20​
9​
101443104​
Wh / 1000​
20​
00​
10​
21​
0F​
10​
22​
83​
11​
23​
A4​
11​
1016740​
Elapsed seconds​
24​
00​
12​
25​
00​
12​
26​
00​
13​
27​
00​
13​
0​
??​
28​
7B​
14​
123​
CRC​

The Juntek display unit sends the command :
AA 04 01 01 B0
If you wanted to remove the display unit altogether, however then you need to send and wait for the data.... the display unit polling does most of the hard work.
 
Last edited:
Joined
Mar 7, 2018
Messages
1,055
Next up the MUST PC1800F, 80A solar controller. I had contacted them via the web chat and had a typical English-Chinese problematic communication exchange, which resulted in the unfortunate scenario of confusion and compeltely different answers as to what I was asking for. The desktop software to read and set the unit is an interesting bit of code put together with some testing and user experience involved but the simple value of total Wh was incorrect and the unit would also scan and open every port on your computer. Critically the software would not work next day if it was left on overnight for some magical reason, anyhow, it did provide a means to do a man in the middle on the exchange of protocol and figure most of it out..
Connection is 9600 baud 8 data no parity 1 stop
Modbus 01 03 register request packet of 8 bytes with standard modbus CRC calculation
Register 10000 = hardware and software summary / unit identification - register count 9
Register 10101 = Settings request - register count 25
Register 15201 = Active state summary of real time data - register count 24

Register 1000 Response

Byte​
Data​
Sample​
Register​
Value​
1​
Header​
01​
1​
Header​
2​
Function​
03​
3​
Header​
3​
Byte No​
12​
1​
18​
Byte count​
4​
1​
50​
1​
5​
2​
43​
2​
20547​
Model ??​
6​
3​
07​
2​
7​
4​
08​
3​
120​
??​
8​
5​
FF​
3​
9​
6​
FF​
4​
65535​
??​
10​
7​
FF​
4​
11​
8​
FF​
5​
65535​
??​
12​
9​
27​
5​
13​
10​
DA​
6​
10202​
Hardware version​
14​
11​
2D​
6​
15​
12​
6E​
7​
11630​
Software version​
16​
13​
40​
7​
17​
14​
00​
8​
1024​
??​
18​
15​
40​
8​
19​
16​
00​
9​
1024​
??​
20​
17​
40​
9​
21​
18​
00​
10​
1024​
??​
22​
CRC​
92​
chk​
Check​
23​
CRC​
D2​
chk​
Check​

Register 10101 Response

Byte​
Data​
Sample​
Register​
Value​
1​
Header​
01​
1​
1​
Header​
2​
Function​
03​
1​
3​
Header​
3​
Byte No​
32​
1​
50​
Byte count​
4​
1​
00​
1​
5​
2​
01​
2​
1​
Work mode ??​
6​
3​
01​
2​
7​
4​
F4​
3​
500​
??​
8​
5​
02​
3​
9​
6​
12​
4​
530​
Float voltgae​
10​
7​
02​
4​
11​
8​
12​
5​
530​
Absorbtion voltage​
12​
9​
01​
5​
13​
10​
54​
6​
340​
Low voltage​
14​
11​
01​
6​
15​
12​
68​
7​
360​
Low voltage release ?​
16​
13​
02​
7​
17​
14​
58​
8​
600​
Battery type ??​
18​
15​
03​
8​
19​
16​
20​
9​
800​
Max charger amps​
20​
17​
00​
9​
21​
18​
64​
10​
100​
??​
22​
19​
00​
10​
23​
20​
01​
11​
1​
??​
24​
21​
00​
11​
25​
22​
C8​
12​
200​
??​
26​
23​
00​
12​
27​
24​
00​
13​
0​
?? Auto page on display enabled ??​
28​
25​
00​
13​
29​
26​
00​
14​
0​
?? LCD Light enabled ??​
30​
27​
03​
14​
31​
28​
20​
15​
800​
Hardware max amps ??​
32​
29​
00​
15​
33​
30​
01​
16​
1​
Voltage grade (Auto == 1)​
34​
31​
00​
16​
35​
32​
96​
17​
150​
CV charge time​
36​
33​
00​
17​
37​
34​
00​
18​
0​
BTS compensation​
38​
35​
00​
18​
39​
36​
00​
19​
0​
Equalisation enabled​
40​
37​
02​
19​
41​
38​
1C​
20​
540​
Equalisation voltage​
42​
39​
00​
20​
43​
40​
96​
21​
150​
Max equalisation current OR CV charging time​
44​
41​
00​
21​
45​
42​
3C​
22​
60​
Equalization time​
46​
43​
00​
22​
47​
44​
78​
23​
120​
Equalisation timeout​
48​
45​
00​
23​
49​
46​
1E​
24​
30​
Equalization interval (days)​
50​
47​
00​
24​
51​
48​
00​
25​
0​
??​
52​
49​
00​
25​
53​
50​
00​
26​
0​
??​
54​
CRC​
3F​
26​
16255​
Check​
55​
CRC​
7F​
27​
Err:502​
Check​

You can also change the settings of the device with a message like this - the register address is just the register address in the settings (10101) with the appropriate offset added as in the column above.

Setting max charge amps to 60​
Header​
01​
1​
1​
Header​
Function​
10​
1​
16​
272​
Function​
Byte No​
27​
1​
39​
Register start address​
1​
7C​
1​
124​
10108​
10108​
Register start address​
2​
00​
2​
0​
Registers to write​
3​
01​
2​
1​
1​
1​
Registers to write​
4​
02​
3​
2​
18​
2​
Register size (bytes)​
5​
02​
3​
2​
Ah battery​
6​
58​
4​
88​
600​
600​
Ah battery​
FA​
4​
250​
Check​
37​
5​
55​
64055​
Check​
 
Joined
Mar 7, 2018
Messages
1,055
Register 15201 Rresponse

Byte​
Data​
Sample​
Register​
Value​
1​
Header​
01​
2​
Function​
03​
3​
Byte No​
30​
48​
Byte count​
4​
1​
00​
1​
x​
5​
2​
03​
1​
3​
??​
6​
3​
00​
2​
x​
7​
4​
00​
2​
0​
Charger work state (work mode)​
8​
5​
00​
3​
x​
9​
6​
00​
3​
0​
MPPT state (MPPT)​
10​
7​
00​
4​
x​
11​
8​
00​
4​
0​
Charge state (absorb)​
12​
9​
01​
5​
x​
13​
10​
DE​
5​
478​
PV Volts /10​
14​
11​
01​
6​
x​
15​
12​
E2​
6​
482​
Battery Volts /10​
16​
13​
00​
7​
x​
17​
14​
00​
7​
0​
Charge Amps /10​
18​
15​
00​
8​
x​
19​
16​
00​
8​
0​
Charge power watts​
20​
17​
00​
9​
x​
21​
18​
0D​
9​
13​
Radiator temp​
22​
19​
00​
10​
x​
23​
20​
03​
10​
3​
External temp (-57)​
24​
21​
00​
11​
x​
25​
22​
00​
11​
0​
??​
26​
23​
00​
12​
x​
27​
24​
00​
12​
0​
??​
28​
25​
00​
13​
x​
29​
26​
20​
13​
32​
Battery relay​
30​
27​
00​
14​
x​
31​
28​
00​
14​
0​
PV relay​
32​
29​
00​
15​
x​
33​
30​
30​
15​
48​
Battery volt grade​
34​
31​
03​
16​
x​
35​
32​
20​
16​
800​
Rated Amps​
36​
33​
00​
17​
x​
37​
34​
00​
17​
0​
x​
38​
35​
01​
18​
x​
39​
36​
01​
18​
257​
Accumulated PV power (/ 10 == kWh) 32 bit​
40​
37​
00​
19​
x​
41​
38​
04​
19​
4​
Accumulatd day​
42​
39​
00​
20​
x​
43​
40​
06​
20​
6​
Accumulated hour​
44​
41​
00​
21​
x​
45​
42​
27​
21​
39​
Accumulated minute​
46​
43​
28​
22​
47​
44​
AE​
22​
10414​
Protocol version​
48​
45​
00​
23​
49​
46​
19​
23​
25​
State of Charge (5% increments)​
50​
47​
00​
24​
51​
48​
08​
24​
8​
??​
52​
CRC​
6E​
28247​
Check​
53​
CRC​
57​
1393​
Check​
 
Joined
Mar 7, 2018
Messages
1,055
Then I have an outline which is along the lines of :
20210209-HESoverview.png
 
Joined
Mar 7, 2018
Messages
1,055
The PC1800F solar charger shuts down overnight so stops responding to poll requests until the next day when the PV voltage triggers a restart

Still have to sort out the metering properly as I have a compromise of 2 meters on the 2 main feeds to the house and did not have a spare RS485-Ethernet adapter at the time to add one for the total. The reason for the delay was that the meters I'm using are not exactly that great for accuracy and consistency and do not have the ability to determine the direction of the power flow... For that I have some 2+ year old RS485 CT meters I have yet to get back out the box and install, before coding them up.

The way I approached the system is to take each unit completely separate and just write a small wrapper for that unit (with a configuration file) so that all interaction is with a message bus (in my case Rabbit MQ but could easily be MQTT) and then it makes the whole system into just a separate set of functional parts and can be expanded or scaled as required.
 
Joined
Mar 7, 2018
Messages
1,055
The code is written in VS2019 Visual Basic .NET 5.0 Core. because I started coding in VB waaaaay back when it first came out.. so no python, etc. Using oxyplot for the charts, which scroll live (add new points and once you have say 1000 points, just keep removing the first point on each add).

Still very much a work in progress....
 
Joined
Mar 7, 2018
Messages
1,055
Battery voltage, when measured at the main busbar) has always been a bit of an issue due to the small voltage drop on the battery pack leads and chemical state in the cells.

After a bit of playing with some numbers and measurements from the pack I took the current output power and then multiplied it by a value to create an offset which is applied to the battery voltage. This sort of gives a corrected battery voltage, which turns out to be a lot more stable and indicative of the real battery state.

The meain reason for doing this was I needed a battery voltage to turn the pack on and offf (or reduce inverter output when the remaining energy is low) and using the busbar voltage would have triggered a switch off far too early when the system is loaded up and the voltage is pulled down.

This is what it looks like (as I like picutres and chart way better than heaps of dull words) :

20210213-HESoverview-Updated.png
 
Joined
Mar 7, 2018
Messages
1,055
The pack has another 90W load attached to it at the moment, which is part of the larger difference between battery load level and house load level. The 90W is an APC UPS with a laptop from the dark ages that needs winding up every so often.
 

italianuser

Member
Joined
Feb 25, 2020
Messages
361
Verrrry nice indeed, I love measuments and charts(y)I'll be sharing mine soon.

Keep it up!
 

Strip

New member
Joined
Sep 27, 2021
Messages
1
Hi! Thanks for your work, it helped me out a lot!
I just registered to post a great document i found regarding the MUST PV1800 and most of their product line modbus protocol (i think it also applies to the PH product line).

I'm working on adapting the awesome RS485-WIFI-EPever by chickey (https://github.com/chickey/RS485-WiFi-EPEver) arduino software to the MUST inverters.

I hope it helps other people in their monitoring projects :)
 

Attachments

  • PH PV RS485 Modbud RTU communication Protocol1.4.3 20170313.x.xlsx
    38.6 KB · Views: 20
Top