New Modbus TCP LIB plus i2c slave

While working with modbus for a project at work I have been messing around with Modbus at home with my arduino boards. I received some help from users in this forum during my testing and I thank you.

As a result of my working with Modbus TCP over the past several weeks I have developed this Modbus TCP library that someone might find useful.

MBeasy Modbus TCP library with examples and documentation (in the code) is attached. Call this v1.0

This has only been tested with Arduino 1.0.5 on UNO R3 and Ethernet boards. So, if you are using a different setup you may have to tweak some of the code. There is Test code for each of 3 included classes. I have also include wiring schematics and other images for reference.

This is my first public offering of an arduino class, so if I did something wrong in the setup of the files, please let me know.

-=Ryan
ps. the SHA-1 hash for the zip file is: b4ee63912b9c07dc4dcabf0b511ab033d4e9e40b

MBeasyModbusLIBs_SHA1(b4ee63912b9c07dc4dcabf0b511ab033d4e9e40b ).zip (609 KB)

I think what you have done is good at putting things together.
In Modicon hardware the 1XXX are digital inputs read only bits and 3XXX are analog inputs read only these are seperate memory from coils and registers.
I am using your tcp lib with a Mega 2560 board with 6 relays on pins 31 - 41 and it seems to work well
My question is in how to handle the 4XXX holding registers. Is there a way to save the values in these so that upon power loss you can continue on?

Moorsby, thanks for the feedback. Glad it is working for you.

I will double check the modbus spec, but I thought the coils were read/write, hence the write coil function.

As for storing register data to survive a power cycle, my first thought is to wire up some 32K EEPROMs (24CL256) chips on i2c and store the register data there, on power up, check if there is any data in the eeproms and reload the registers. I will look in to that.

-=Ryan

Coils are read/ write. Inputs are read only and are in a different memory location than outputs.
I am wanting to write 32 bit float into 2 consecutive holding registers.
Does Mudbus lib support this? or is write only integer?

moorsb,

Yes you can write and read floats. The BitArray LIB that is part of the EasyMB LIB has 2 function for floats, one for reading and one for writing.

BTW, I did test the storing of register data to EEProm to survive a power cycle and works great. I will post the code when I can.

Thanks
-=Ryan

Ryan

Coils in Modicon PLC are discrete bits 0XXXX that if they are used in the "traffic cop" they would be tied to real world Outputs like motor starter coils, or pilot lights. It they were not used in the traffic cop, then they were bool memory bits used for logic coils in the ladder diagrams. They are read/write.

Inputs in Modicon are discrete bits 1XXXX that were only used in the traffic cop, driven by real world discrete devices
push buttons, limit switches hence you could not write to them, unless you used something called a force which over rode the status of an input device. This is a different area of memory than Coils

Holding Registers 4XXXX are 16 bits. If they were used in the traffic cop they would be tied to real world Analog Outputs
4 - 20 ma, 0 - 10v or BCD Read Outs to send a setpoint to some device. If they were not used in the traffic cop, then they would be used to store data, which was battery backed so if upon power loss you would not loose your setpoints.
These are read/write

Input Registers 3XXXX used for Analog 16bits input were read only not the same memory location as 4XXXX these were used to
read temp, pressure 0 - 4095 int

The plc was the modbus slave device and had to be polled for data using modbus.
Later on they gave the plc the ability to be the master.

I am studying as an automation engineer and I was assigned my last year's project with the genesis 32 program and an arduino uno(which I had bought already) to build an OPC SERVER and a SCADA network.Are you familiar with this program? Or something relevant?

I would like to ask you about the arduino uno and the modbus protocol of the OPC server I am creating.Are they going to communicate just fine? or totally not?

Also I would like to program it in the ladder language. I found only a library with ladder logic but not the same drawings and a compatible interface.

Thank you in advance,

It seems to me that there is some confusion about Modicon memory allocation. I was trying to clarify how the memory is used in the plc side of things. The modbus function codes deal with different area of memory in the plc. It seems that some have let them over lap when it comes to input words and bits this is 2 different area of the plc memory in Modicon.
OPC server is nice if you are in Windows, I have not seen any free ones thou.
ladder logic on Ardunio ?? Who does that?

I'm wondering if you have ever tried to use your lib with a wifi shield? I'm working on a project where I want to add modbus, but want it to be on wireless. Any thoughts on getting your lib to work in this way? I have a Wifly shied from Sparkfun.

chrysliol:
I am studying as an automation engineer and I was assigned my last year's project with the genesis 32 program and an arduino uno(which I had bought already) to build an OPC SERVER and a SCADA network.Are you familiar with this program? Or something relevant?

I would like to ask you about the arduino uno and the modbus protocol of the OPC server I am creating.Are they going to communicate just fine? or totally not?

Also I would like to program it in the ladder language. I found only a library with ladder logic but not the same drawings and a compatible interface.

Thank you in advance,

chrysliol ,

Sorry I missed this post from 1/2 a year ago. My understanding is that OPC and Modbus are 2 different protocols. MBeasy LIB has no OPC functionality.

-=Ryan

yeti195:
I'm wondering if you have ever tried to use your lib with a wifi shield? I'm working on a project where I want to add modbus, but want it to be on wireless. Any thoughts on getting your lib to work in this way? I have a Wifly shied from Sparkfun.

yeti195,

I have successfully use MBeasy LIB with 2 Arduino boards connected serially through MAX487 chips. As for wireless, MBeasy would most likely not need to be modified, but the code using it would be responsible for sending and receiving the modbus data. I have a bunch of different wireless devices I have played around with on my arduinos. I will, soon, test MBeasy using one of these devices. I do not, however, have the wiFly device from sparkfun.

Thanks
-=Ryan