Support for RS485 on Duet 6XD and 6HC
-
@dc42 Do you have a recommendation for a suitable converter? Most of the ones on Amazon seem to use automatic switching. This one seems to have enable pins: https://www.amazon.co.uk/WINGONEER-MAX485-Module-RS-485-Development/dp/B06XHHWLMW
-
@dc42 i will continue testing
-
-
i am testing with the following GCODE. Can you review to see if i am doing it correctly
M575 P1 B115200 S7 ; Set Serial comms parameters TX & RX M260.1 P1 A1 R42 B1 ; Modbus Write to registers / Coils M261.1 P1 A1 R42 B2 ; Modbus Read from Holding or Input registers / Coils
Below is:
RS485 Serial Connections Configurations on the PLC MODBUS RTU Side:
Modbus Slave Address (PLC): 1 Comm Mode : RS485 Modbus RTU Parameters: 115200, 8Bit, None, 1Bit i.e Baudrate : 115200 Length: 8 Parity : None Stop Bits: 1 Hardware Control: Flow Control Mode: No DTR: Enable RTS: Enable
-
@developeralgo222 you only need one M575 P1 command, and the C parameter should only be used if your RS485 adapter has a Tx/Rx control input.
The V parameter of M261.1 is not yet implemented.
-
@dc42 as edited above ?
-
@developeralgo222 yes, if your RS485 adapter does automatic Tx/Rx switching, and you want to write 1 word with value 1 to register 42 and then read registers 42 and 43.
It might be a good idea to try with a lower baud fate initially e.g. 19200. The automatic Tx/Rx switching will probably only work over a range of baud rates. 9600 and 19200 are commonly used for Modbus RTU.
-
@dc42 , i managed to have it working at 115200. Need to go through simple tests
As per your statement above so far Function Code:
0x03 (Read Holding registers ) and 0x04 (Read input registers ) are working and i can also write to a single Register but i can't seem to be able force a single coil to ON (1) or OFF (0) directly
-
@developeralgo222 FX3U MODBUS Serial Communication Edition.pdf
If you review pages 55 - 75 & 95 on the PDF that has Modbus Format & address mapping for the device i have FX3U
. I am trying to Write a single Coil to turn it ON(1) of OFF (0)
; Write to a single coil Mxxx e.g M41 (which has address 0x0029) in order to turn it ON(1) = FF00 or OFF(0) = 0000 M260.1 P1 A1 R0x0029 B1 ; Read a single coil M41 (which has address 0x0029) in order to turn it ON(1) = FF00 or OFF(0) = 0000 M260.1 P1 A1 R0x0029 B1
i don't seem to be able to format it correctly with Duet 6XD, any help on the formatting. i don't get errors but seem to be writing to correct Register
M260.1: Modbus write registers
Supported from firmware version 3.6Write data to a Modbus slave device.
Parameters
- Pnn -- Serial port to send/receive through, numbered as in M575 (1 = first aux port, 2 = second aux port). The port must already have been set to Modbus mode using M575.
- Ann -- Modbus slave device address
- Rnn -- First Modbus register number to send data to
- Bnn:nn:nn... --- 16-bit words to send
is the register number Rnn in Hexadecimal or decimal ? i presume it should be in Hex format ? what is the correct format , can you give an example using Coil M41 in my case . Note: i am able to turn it ON or OFF using Modbus RTU connection from my laptop or manually on the FX3U config app
Here is some snapshot captures (Request & Response ) of the MODBUS communications between MODBUS Master (Open Modscan on a PC ) and Slave ( Mitsubishi FX3U-48MR PLC with FX3U-485ADP-MB Adapter) when testing various functions:
-
@developeralgo222 RRF doesn't yet support writing coils or reading discrete inputs, I only implemented writing registers, reading input registers, and reading holding registers.
Your document gives register numbers in hex. RRF takes parameters in decimal by default, but you can use hex numbers like this:
M260.1 P1 A1 R{0x0029} B1
-
@dc42 Fantastic.
When do you think you will be able to get to implementing the coils part , The SMT feeders i am testing it on needs to be able to Read/Write Coils to turn the Feeder triggers ON or OFF ?
-
@developeralgo222 I've attempted to add Modbus coil support but I don't have a Modbus device that implements coils to test it on. I've put a new MB6XD binary at https://www.dropbox.com/scl/fo/gwhkwjg232hd6us8yvr0k/ABiZ84dcbZEb9PYiznBRMZU?rlkey=whab6c638wj8w4hyo2jyvjign&dl=0.
-
@dc42 i will try and test the coils with the new binary now
-
@developeralgo222 M260.1 now takes a F parameter to specify the Modbus function number. See https://docs.duet3d.com/en/User_manual/Reference/Gcodes#m2601-modbus-write-registers-or-coils.
-
@dc42 First tests on R/W to a single Coil ( M42 = Coil Address(Hex) is 0x002A ) and also multiple coils:
-
Single READ = Works & Single WRITE = Doesn't work -- can't write to single coil
-
Multiple READ = Works & Multiple WRITE = Doesn't Work and come back with an error even though it writes the Value to those multiple coils . i also tried writing to a single coil using F15 and i am able to write it but Duet responds with an Error even though it write to the Single coil
Note: For single READ test , i turned the coil to ON = 1 manually and read it to see if it was reading from the correct coil and then changed it back to OFF = 0 and read it again
Also i think there is a mix up between Read & Write functions on Multiple coils . When you send a WRITE function (F15 or F{0x0F} ) it comes back with an error but when you send READ function (F1 or F{0x01} ) command for multiple Coils it shows that the coils values have been updated from 0 (OFF) to 1(ON)
Is there a way to get the debug logs easily to see what its sending and the format ?
-
-
@developeralgo222 thanks for your feedback. So it looks as though it was sending the correct data for WriteSingleCoil and WriteMultipleCoils even though it returned failure. I've updated the binary at https://www.dropbox.com/scl/fo/gwhkwjg232hd6us8yvr0k/ABiZ84dcbZEb9PYiznBRMZU?rlkey=whab6c638wj8w4hyo2jyvjign&dl=0 with a possible fix.
-
@dc42 fantastic ,
i will give the new update a try again -
i run the following commands from the console for tests :
Write / Read Single Coil using Functions 5 & 1 M260.1 P1 A1 F{0x05} R{0x002A} B1 M261.1 P1 A1 F{0x01} R{0x002A} B1 Write / Read multiple Coils using Functions 15 & 1 M260.1 P1 A1 F{0x0F} R{0x002A} B1:1:1:1 M261.1 P1 A1 F{0x01} R{0x002A} B4 M260.1 P1 A1 F{0x0F} R{0x002A} B0:0:0:0 M261.1 P1 A1 F{0x01} R{0x002A} B4 Write / Read Single Coil using Functions 15 & 1 M260.1 P1 A1 F{0x0F} R{0x002A} B1 M261.1 P1 A1 F{0x01} R{0x002A} B1 M260.1 P1 A1 F{0x0F} R{0x002A} B0 M261.1 P1 A1 F{0x01} R{0x002A} B1
From the R/W Coil tests, Only Single WRITE (Command below) to the coil using Function 5 does not work. It actually doesn't WRITE anything at all to the coil .
M260.1 P1 A1 F{0x05} R{0x002A} B1
-
@developeralgo222 please try the latest binary at https://www.dropbox.com/scl/fo/gwhkwjg232hd6us8yvr0k/ABiZ84dcbZEb9PYiznBRMZU?rlkey=whab6c638wj8w4hyo2jyvjign&dl=0.
-
@dc42 great , let me give it a try