Thanks! I wondered if you might explain how you read/write to your ModBus coils/registers. It appears to be a regular data array, but only contains 16 slots (differing from typical ModBus with 9999 slots in the data array). Which ones would be your discrete inputs and outputs and which ones would be your analog input/output registers?
@peekay123
Thanks! I wondered if you might explain how you read/write to your ModBus coils/registers. It appears to be a regular data array, but only contains 16 slots (differing from typical ModBus with 9999 slots in the data array). Which ones would be your discrete inputs and outputs and which ones would be your analog input/output registers?
@peekay123 sorry for the long delay (months) for testing the library, but I have had serious problems with my health. I am getting back there, so I hope I will be able to test it the coming weeks.
Are there any good resources that anyone knows for me to learn how to simply join the bus as a slave and serial.println() all the messages as they pass by? I have a MAXRS485 module, @peekay123ās lib, wired as I have seen in other threads but I havenāt seen anything that shows simple āsnoopingā so I can start mapping out physical button pushes to modbus messages.
Couldnāt quite tell from this thread, but have you also implemented Modbus Master functionality? Or is there any library that has implemented it for the Particle Photon/Core?
Hmmm @peekay123 looks like you that library you ported does have master functionalityā¦ did you port the whole thing or just the slave parts? Or were the changes you made common to both? Thanks!
Oh sorry for the miscommunicationā¦ Iām just a little confused because Iām looking at the 2nd library you ported (ModBus_RS485_Slave), and it, along with the library it came from (Modbus-Master-Slave-for-Arduino) appear to have code to create modbus masters, though not all function codes are implemented. Is there any reason this master functionality shouldnāt also work on the photon?
@beck, did you have any luck getting this to work? I have this library working on an Arduino, but would like to get it working on my Photon. I have flashed it to my Photon, but the device is not responding to any serial data I send to using QModBus as a test utility.
@peekay123 I tried compiling your port locally, but was getting an āError: You are building with the Photon as a targetā. I commented out the lines in ModbusRtu.h that throw this error:
#if PLATFORM_ID == 0 // Core
#error "*** You are building with the Core as a target ***"
#elif PLATFORM_ID == 6 // Photon
#error "*** You are building with the Photon as a target ***"
#endif
and now it compiles fine, but I was curious as to why they are in there in the first place?
@beck, @peekay123,I connected my USB-FTDI cable to the RX/TX pins and was able to query some input registers. I moved millis() to the first word of the array so I can at least watch something move. This evening I will try hooking up my MAX485 chips and see if I can achieve a multidrop system (and test the DE/RE fuct of the max485 chipā¦). I have this working with Arduino, so shouldnāt be too bad. Once proved to my PC with a 232-485 converter I will connect it to an industrial PLC (I have a Panasonic FP-X) and see if that works. Iāll keep you in the loop
@adamg thanks! I have this running right now as well, seems like all the slave function codes work.
The only thing that I found a bit confusing is that in the slave, the Modbus data address offset isnāt implemented (if it were, coils 0000-270E would map to memory locations 1-9999). Consequently, in the slave input data array (au16data) thereās no distinguishing what type of data (coil, register, etc) each memory location holds, and leaves it up to the master to know what kind of data is where.
Whats also a little confusing is that the address of discrete inputs and coils are mapped to bits in the input data array, such that coils 1-16 map to bits 0-15 of au16data[0], 17-32 map to bits 0-15 of au16data[1], and so on. As a result, you could write 7 to register 0, and read it either as holding register 0 = 8, or coil 4 = 1 and coil 3 = 1.
Not a big deal for me, since Iām mostly interested in the master, but would probably be worth implementing (I might do it if I have time)