RS-485 modbus library


#21

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!


#22

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


#23

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


#24

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!


#25

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


#26

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


#27

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.


#28

@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


#29

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


#30

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!


#31

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


#32

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?


#33

@beck, you’ll just have to try it! :wink:


#34

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


#35

working on it! hopefully by tomorrow i’ll have tried it out


#36

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


#37

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


#38

@beck, that looks like code I left behind for testing! Those should be warnings, not errors. Oy!


#39

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


#40

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