string over modbus

hello,

I'm trying to send a string over modbus from the arduino to a scada application. can someone tell me how to send the string to the ModbusDevice from the ModbusSlave (arduino) using the modbus.h library?

thanks for the help!

First of all: provide a link to the library you're using. There is a bunch of libraries for ModBus on Arduino and many of them have files with almost the same name.

ModBus does not support the transfer of strings but only numerical values. There are even defined register ranges for digital inputs and outputs as well as the analog variants. And ModBus slaves cannot "send" a string or any other information, the bus master asks for the information and the slave just answers.

If you need to transfer a string you can use a series of registers and set the content as your string has characters and let the master ask for all registers. Then the master can reconstruct the string from this information. If you start with a length byte (just like a Pascal string) you might be able to implement that more or less efficiently.

You might think about changing the protocol if you really need to transfer strings over you bus.

hello!

thanks for the quick reply. the library i used is:Google Code Archive - Long-term storage for Google Code Project Hosting.

do you know the differences between these libraries? since modbus is relatively easy i wonder why there are so many versions.

mainly i need to read/write analog and digital signals and my scada software supports modbus so i think i'm stuck. it also supports OPC and i saw that there is an OPC library and server as well, i wonder if that is a proper/faster way to go.

the serial string i need to read contains a number and a time. maybe it's easier to convert these to integers and pass them to the master as such instead of passing the string as a whole to the master. i believe it is possible to go from char to int?

wonder what your opinion is :slight_smile: thanks for the help!

do you know the differences between these libraries? since modbus is relatively easy i wonder why there are so many versions.

ModBus is easy only in the first view. If you look at the many details of the standard you get a lot of potential to do things wrong. Most of the libraries out there do parts of the standard wrongly. Most of them implement either the master or the slave part which also increases the number you find when looking for it.

mainly i need to read/write analog and digital signals and my scada software supports modbus so i think i'm stuck.

For this kind of data ModBus is probably ideal. It's not so good for string data as I wrote in my first answer.

t also supports OPC and i saw that there is an OPC library and server as well, i wonder if that is a proper/faster way to go.

I don't know OPC very well but from what I know it's an IP protocol. Although for ModBus there exists also an IP specification (ModBus TCP) most Arduino implementations use the most widely used RTU physical layer (based on RS-485). Which one does your Scada system use?

the serial string i need to read contains a number and a time. maybe it's easier to convert these to integers and pass them to the master as such instead of passing the string as a whole to the master. i believe it is possible to go from char to int?

If you want to transfer it over ModBus is definitely easier to use integers. Where did you get the data from? Was it already a string or do you create the string in the Arduino? Tell a bit more about the data you want to transfer maybe we can give you some hints.