RS-485 modbus library

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?

Thank you!

@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?

Thank you!

@mulderne, I ported this library for another member and never actually used it. You may want to look at the top of ModbusRtu.h for more details. :smile:

Thank you! I downloaded both files, but I havenā€™t had time enough to check them! I will give you feedback wherever I can! Thank you again!

@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.

@GrtVHecke, health is everything so be well and welcome back!

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.

@peekay123 thanks for porting this library!

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?

Thanks!
-Ben

@beck, my involvement stopped at porting only, no extra functionality. You may need to search the Community. :smile:

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!

@beck, I ported the two libs at different times for different members.

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, youā€™ll just have to try it! :wink:

@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.

working on it! hopefully by tomorrow iā€™ll have tried it out

Alright, thanks. I plan on poking at it tonight as well

@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, that looks like code I left behind for testing! Those should be warnings, not errors. Oy!

@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 :slight_smile:

@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)