@Rayman said:
Guess had a 50/50 shot at getting byte order correct and of course was wrong...
Yeah, Modbus is something of a dog's breakfast when it comes to consistency. When reading the docs it's apparent it had distinctly different authors between the original and later extensions. It shows the likely ages it was written. Before the PC became dominant Big Endian was seen as the right way but after, then Little Endian gets preferential treatment.
Ray: I noticed that you're using jm_fullduplexserial in your code. Are you going through an RS-485 converter? If yes, are you using a 4-wire connection? I don't see any mechanism in your code to enable the transmit of a '485 chip.
Your MODBUS work inspired me to get an USB-to-RS485 adapter and give it a go. I already had a RS-485 driver for the P2 which is [mostly] compatible with my other serial drivers (though it lacks [unneeded] formatting methods). My friend John at JonyJib uses the RS-485 driver is his projects, though in that case, we have a custom protocol (that looks a lot like XBee messages). That is to say I think the RS-485 driver is solid.
Over the past several nights I started chipping away. I liberated some bits and bobs from your project; maybe you'll find something useful here. ATM it is a framework for a MODBUS slave; command 2 (read inputs) works. I have a 4-button board that attaches to an Eval (my version of the Parallax Control accessory). I can press any of the buttons and the scanner shows the message working. On that board I have an APA102c. If you find a piece of shareware that lets you write registers I will use that command to set the R, G, and B levels of the pixel.
Was using ChatGPT as an assistant while programming and asked about a piece of freeware for MODBUS testing. It recommended QModMaster. It's easy, if a bit annoying in that it sends a message any time you change a control, but it does allow you to use the write commands. I updated my program to use the Write Register ($06) and Write Registers ($10) commands.
'defaults for Copeland VFD's
Const bitrate=19200 'communication speed
ID=45 'default modbus id
'init system for ZERO using gp0/gp1/gp2
'open COM1 port with modbus defaults 19200/8bit/even parity/1 stop
setpin gp1, gp0, COM1 'rx,tx,port
setpin gp2,dout : pin(gp2)=0 'DE pin is GP2
Open "COM1:"+Str$(bitrate)+",EVEN" As #1
device ws2812 o,gp16,1,pur% 'gp16 is connected to the RGB color LED
dim oe$ = "" , e$ = ""
timout!= 2 * 11 * 1000 / bitrate 'message end = 2 characters, 11 bits each, in ms
timer=0
'snoop bus
do
timestamp!=timout!+timer
do
if loc(1) then e$=e$+Input$(Loc(1),#1): timestamp!=timout!+timer
loop until timer>timestamp! 'end of message when no new character for 22 bittime
if len(e$)>0 then prtx e$ : oe$ = e$ : e$ = ""
loop
'prints the string from UART in readable form on console
Sub prtx a$
Local i
print gr$;str$(timer/1000,4,3,"0");" : ";wh$;
For i=1 To Len(a$)
If i=2 Then Print choice(Asc(Mid$(a$,i,1))>127,rd$,bl$);
If i=Len(a$)-1 Then Print choice(check(a$),wh$,rd$);
Print Right$("0"+Hex$(Asc(Mid$(a$,i,1))),2);" ";
'separate CRC from message
cr$=Right$(a$,2)
crc_mes=256Asc(Right$(cr$,1))+Asc(Left$(cr$,1))
'compare CRC's -> when equal, message is okay.
If crc_mes=crc_pd Then
check=1 : device ws2812 o,gp16,1,grn%
else
check=0 : device ws2812 o,gp16,1,red%
end if
else
device ws2812 o,gp16,1,pur%
End If
Comments
Yeah, Modbus is something of a dog's breakfast when it comes to consistency. When reading the docs it's apparent it had distinctly different authors between the original and later extensions. It shows the likely ages it was written. Before the PC became dominant Big Endian was seen as the right way but after, then Little Endian gets preferential treatment.
Eg: There is a 32-bit extension for register sizes.
Ray: I noticed that you're using jm_fullduplexserial in your code. Are you going through an RS-485 converter? If yes, are you using a 4-wire connection? I don't see any mechanism in your code to enable the transmit of a '485 chip.
Just using regular serial via FTDI USB chip, nothing special.
Although in future will probably be Modbus TCP. Although maybe a serial connection to something nearby might be useful, who knows...
Your MODBUS work inspired me to get an USB-to-RS485 adapter and give it a go. I already had a RS-485 driver for the P2 which is [mostly] compatible with my other serial drivers (though it lacks [unneeded] formatting methods). My friend John at JonyJib uses the RS-485 driver is his projects, though in that case, we have a custom protocol (that looks a lot like XBee messages). That is to say I think the RS-485 driver is solid.
Over the past several nights I started chipping away. I liberated some bits and bobs from your project; maybe you'll find something useful here. ATM it is a framework for a MODBUS slave; command 2 (read inputs) works. I have a 4-button board that attaches to an Eval (my version of the Parallax Control accessory). I can press any of the buttons and the scanner shows the message working. On that board I have an APA102c. If you find a piece of shareware that lets you write registers I will use that command to set the R, G, and B levels of the pixel.
(Program updated. See below)
Was using ChatGPT as an assistant while programming and asked about a piece of freeware for MODBUS testing. It recommended QModMaster. It's easy, if a bit annoying in that it sends a message any time you change a control, but it does allow you to use the write commands. I updated my program to use the Write Register ($06) and Write Registers ($10) commands.
Qmodmaster looks good. Have to try that. Most seem to only handle commands 1..4. This looks to do more.
@Rayman
Don't know if there's anything of any use to you in the attached but you never know.
Also "Modbus Spy"