New Modbusmq project: Testers needed!

nice work
can you please explain a bit a about how to use it?

ok. i'll write down a few lines, then i'll make a wiki for it:

modbusmq is a ModBus ( Modbus - Wikipedia ) TCP slave (server): briefly, it holds a data map, which can be queried by Modbus clients (PC or other) with a standard protocol.

requirements:

  • Arduino Ethernet Shield

usage:
Arduino side

  • paste the code in a new project in the Arduino IDE
  • change the network params, if needed: IP, Gateway.
  • change the slave Address, if needed
  • set or unset the DEBUG flag to have debug messages through serial line
    PC side:
  • start a modbus client to query Arduino IP, with the correct slave modbus address (there are many freeware, eg: ModScan)

TODO:

  • test two slaves in the same network.
  • test two masters (clients) for the same slave

Hello,

I just tested the Modbusmq and so far it works fine. But I'm struggling a little with all the pointers.

I already managed to send a modbus command from a PC, which sets different bits to true.

But now I want to switch relais, which are connected to a PCF8574. For this I normally use the command:

PCF8574Write(B11111110);

Now I tried to convert the "mb_mapping->tab_coil_status" to a value which I can send with PCF8574Write. But without success. It is too long ago, that I have done somethink with pointers. I tried the following:

for (n=0;n<8;n++)
{
PCFStatus1[n] = byte(*(mb_mapping->tab_coil_status + n));

DEBUG_PRINTLN(n);
delay(200);
}

This seems to me not very efficient and it is also not working.

Can someone help?

BR,

Chris

PCF8574Write(B11111110);

what command is it? a function from you? from a library?

if you have to copy bytes to/from a vector, use the memcpy() standard C function. reference: http://www.cplusplus.com/reference/clibrary/cstring/memcpy/

maybe
memcpy(PCFStatus1, mb_mapping->tab_coil_status, n);

bye
quark

Sounds very promising!

But I still have some problems. I tried the following:

byte PCFStatus1;

memcpy(PCFStatus1, mb_mapping.tab_coil_status, 8);
PCF8574Write(PCFStatus1);

Here the function:
//Write data to PCF8574
void PCF8574Write(byte _data )
{
Wire.beginTransmission(PCF8574_ADDR);
Wire.send(_data);
Wire.endTransmission();
}

But I get the following error:

error: invalid conversion from 'uint8_t' to 'void*'

I do not understand it, why void*?

Any idea?

Hello,

can you give some explanations for the following (is there already some wiki):

If data are correct received, how to use them in the main loop?

I assume there are the following buffers/memorys:
mb_mapping->nb_coil_status
mb_mapping->nb_input_status
mb_mapping->nb_holding_registers
mb_mapping->nb_input_registers

I have also seen some functions like "get_byte_from_bits".

Is there somewhere a more detailed explanation? Maybe in the libmodbus library?

For my problem to write data to the PCF8574 can I use the "get_byte_from_bits" function? But how exactly?

Thank you for your help!

Got it running with the following code:

int PCFStatus1;

// Gets the byte value from many input/coil status.
PCFStatus1 = get_byte_from_bits(mb_mapping.tab_coil_status, 0, 8);

PCF8574Write(byte(PCFStatus1));

I am having trouble getting the modbus sketch to even work on my arduino mega and ethernet shield. Where do I edit the network settings. I tried following the example, but I cannot even ping the arduino. Is there some setup for the wiznet chip? Any help would be appreciated. I am trying to get RC servo control using modbus words.

Thanks

Hello, it works fine (in my initial test), but the DEBUG flag has to be disabled because if it is enables the Arduino hangs :-/, so I can't debug or use the serial port for interchange data.

Any idea to make it work with debug flag?.

I got it working with the DEBUG flag, but it starts working only after having the serial monitor started.

I made the following network settings:
const byte gateway[] = { 192, 168, 2, 254 };
const byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
const byte ip[] = { 192, 168, 2, 100 }; // Arduino has this IP

You have to use the same subnet (192.168.2.x) as your computer uses.

BR,

Chris

Can anyone give me an example how to read an input on the Arduino, and map the I/O status to be polled by the Master?

I am not sure how the mapping is handled.

wow great to see MODBUS/TCP functional. this library will certainly come in handy.

How do you turn on the debug flag?

Also, how do I setup registers to read and write, can someone post a simple example?

Does this only work with the "official" ethernet shield. Seems there are some variants out there now and I would like to buy something to test this with as I have lots of industrial Modbus gear at the office.

Thanks!

Can someone show me how to setup say 8 modbus words to be read from a "client" and make those control 8 rc servos?

or just any basic modbus tcp program. I see the library, but i want to get a look at a real example.

thanks..

Hello,

I just have updated from Arduino 0018 to 0021, but the modbusmq is not working anymore. Seems to be a problem with the new ethernet library. Any ideas? Is there needed an update of the modbusmq?

BR,
chris

I am having the same issue.
Works with 018, but can't even ping the IP when using 021.

Sure would be nice to find a fix for this.

I think there is a problem with calling

Client client = server.available();

as a global

so change that line to

Client client = 0;

please tell me if this helps
for me it seams to fix the problem

It works with:

Client client = 0;

But now I have the same problem with the DEBUG flag. It has to be disabled because if it is enables the Arduino hangs.

hgs75 do you get it working with debug flag?

No i also couldn't get it to work with the DEBUG flag set.
but i thought it was because i used it with conjunction with i2c
so i just disabled DEBUG and moved on