Go Down

Topic: New Modbusmq project: Testers needed! (Read 7163 times) previous topic - next topic

marioquark

i'm working on Modbusmq, a modification of the libmodbus library (https://launchpad.net/libmodbus 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.

that's the code: http://bazaar.launchpad.net/~marioquark-yahoo/modbusmq/modbusmq/files

thank you,
marioquark

marioquark

i am locked:
timing in TCP management doesn't work as it sould: replies are sent with a delay i don't want. this make timeout occur.

probably this happens due to a too big transmission buffer: i can't resize it! :( nor i can set the TCP_NODELAY option (library doesn't offer this).

any suggestion?

please help me, i think my project could be very useful!

marioquark

my libraty is finished and it seems to work perfectly...  ;D

Arnonh

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

marioquark

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


modbusmq is a ModBus ( http://en.wikipedia.org/wiki/Modbus ) 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

chris.moe

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

marioquark

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

chris.moe

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?

chris.moe

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!

chris.moe

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

Jason Goldenberg

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

hgs75

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

chris.moe

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

Loren.R

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.

LAVco

wow great to see MODBUS/TCP functional.  this library will certainly come in handy.
Common sense is not so common...

Go Up