i'm working on Modbusmq, a modification of the libmodbus library (libmodbus in Launchpad by Stephane Raimbault) for the Arduino platform. for now, it's a Modbus TCP slave.
any tester and debugger is appreciated to help me makin' a stable program.
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)
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.
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*'
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?
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.
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.
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.
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?