Sending data/Binary file in the form of XML through Modbus

J

Thread Starter

Jaiganesh

I need to communicate between two devices through serial interface (RS-485) with Modbus RTU. I am going to represent the data, object file (compiled file), Binary file in an XML format. This XML file will be sent to other device through serial interface (RS-485) using Modbus RTU. Is this possible to do this... Can anyone help me in this regard?

if Modbus ASCII and RTU is going to send some Text data/file why cant we send the same in the format of XML through Modbus?
 
M

Michael T Mellish

Modbus Protocol does not have a GENERIC Message frame or File transfer function. This is not a problem for PLC systems since as Modbus slaves, they do not understand files or have a generic message decoding & response capability.

If two Computers wish to share files over a serial link, there are a wide variety of services which can be used for this purpose which incude parcing the file, and reassembling it (KERMIT for example), which would be far easier than trying to do this with Modbus.

If, however, for some reason Modbus must be used (because of other messages traffice & slave nodes), then your best bet would be the use of the function code 16, which would allow you to write 200 bytes of data PER message, from one host system to another. You would have to parse the XML file into blocks of up to 200 bytes, build the write command, and manage the transmission of multiple messages to transfer the file. The standard function code 16 allows 64K addressable words (128K individual bytes) so using the startig memory address starting at zero and incrementing it by 100 with each transaction, a file of up to 128K bytes could be transferred. If you need larger files, then you have to "Stretch" the modbus definition. For example if you increment the starting address by only 1, but transmit 200 bytes each time, than the file size could be 200 x 64K = 13.1 megabytes file sizes. The computer being writen to would treat the starting address as the message number (1 to 64K) and be programmed by you to reassemble the file.

Feel free to contact me if you need more help.
Regards
Michael
 
Hello Sir,
Thanx for the nice answer given by you. in your answer i am not able to get the second portion of the answer( with example). i understood the concept of "writing multiple registers" from the Modbus Application Protocol Sepcification document.but how it will suit here. also can we use "Read File Record/Write file record" (20/21 function codes) for sending and receiving data's in an XML format. actually our scenario is given below.

1) The data to be sent from one device to another will be represented in XML format (a simple text file., say abc.xml).
2)A "C" source code will be compiled and its object code (say helloworld.o) will also be represented in XML format along with the data's)mentioned above.
3)These data's needs to be sent to other device through Modbus RTU.

Is it possible. Also once i received the data in XML format I should use HTTP server/Client as a higher layer protocol. is it possible because i will also get SOAP/XML format messages from the other device. Can u please guide me.

Thanx in advance.
 
M

Michael Mellish

As I previously stated, there is no file read or write function under Modbus. Your response refers to function codes 20 & 21 as "Read File Reference & Write File Reference. In fact these commands are:

20 (14Hex) Read General Reference
21 (15Hex) Write General Reference

These commands allow the user to read & write 6xxxxx series references (an extended data area of Modicon PLCs which can be internally used as a sort of file memory). I do not see how this will be any help in reading or writing XML files.

It sounds like your second reply clearly indicates that this XML transfer is between two computer devices, operating over a network? Is this the case? If so, why are you attempting to use the "Modbus RTU Protocol"? There is no native Modbus command that can move the data as a file, breaking it down, transmitting it as a series of packets, and reassembling at the other end. If you use Modbus, you will have to create the following functionality:
1. Break down the file into packets not to exceed 200 bytes per packet.
2. Encapsulate each of the 200 byte packets as Modicon write register commands (i.e. add destination Modbus Address/ 1byte value 1-249), function code (16 decimal / 10 hex = write multiple registers), starting address (two bytes, value depends on how you are managing the counting of packets), qty = 2 bytes value 200 decimal, and than the error check (CRC-16 two bytes).
3. Transmit the packets to from sender to receiving unit ONE packet at a time. As the response indicates that packet is received, send the next one.
4. Assemble the file from the received packets on the other end.

This approach does not care about the file format, and as I said earlier, it can handle about any size file normally found in automation applications. It is, however, alot of work to perform a file transfer, which is the reason I ask if your really must use Modbus RTU protocol. For file transfer over serial port, there are easier, faster and more secure methods.

Regards
<Michael>
 
A

Alex Pavloff

Jaiganesh wrote:
> I need to communicate between two devices through serial interface
(RS-485)
> with Modbus RTU. I am going to represent the data, object file (compiled
> file), Binary file in an XML format. This XML file will be sent to other
> device through serial interface (RS-485) using Modbus RTU. Is this
possible
> to do this... Can anyone help me in this regard?

The Modbus RTU and TCP specifications have no mention of file transfer. As such, any file transfer operations are device-specific.

>if Modbus ASCII and RTU is going to send some Text data/file why cant we
>send the same in the format of XML through Modbus?

I don't understand your point. Even if you could send the XML data, how is the device on the other end going to interpret it? Why are you using XML?

Alex Pavloff
Software Engineer
Eason Technology
 
Hello Sir,
Actually the two devices are nothing but communication between PLC and PC. PC and PLC communicates with eachother through Modbus RTU (Serial Line RS-232/RS485).so i thought of using Modbus RTU. As i said the format of data will be in XML because PLC will be running in Linux and PC will be running in windows. inorder to have a generic format i am using XML. so that in future if i add any ethernet interface between PC and PLC i can directly use my software without much modification.So is it possible? Also i noticed from ur reply that implementation will be a overhead.is there any other solution for this requirement? please clarify?

Thanx in advance
Jaiganesh
 
This sounds like a nightmare dreamt up by a pointy-haired boss...

The only sensible way I can see to have both Modbus and XML on the same wire is to use Modbus TCP rather than Modbus RTU.

TCP can support Modbus, numerous file transfer protocols including http, soap/xml, etc. It can run over serial cable or Ethernet.


The other possibility is that you have a proprietary extension to Modbus RTU, where it forgets it's Modbus and just transfers the file(s). Disgusting, but possibly effective.


Jiri
--
Jiri Baum <jiri @baum.com.au> http://www.csse.monash.edu.au/~jirib
MAT LinuxPLC project --- http://mat.sf.net --- Machine Automation Tools
 
Jaiganesh:
> Actually the two devices are nothing but communication between PLC and
> PC. PC and PLC communicates with eachother through Modbus RTU (Serial
> Line RS-232/RS485).so i thought of using Modbus RTU. As i said the
> format of data will be in XML because PLC will be running in Linux and
> PC will be running in windows.

It's very difficult to transfer XML data over Modbus RTU.

Probably better to configure the serial line for PPP and use Modbus/TCP for the control data. The XML data can then be sent using some other
protocol (there are a lot of them around, pick one).

> so that in future if i add any ethernet interface between PC and PLC i
> can directly use my software without much modification.

This is another reason to go the PPP route - when you switch to Ethernet, there will be no change to the software at all. Merely change the configuration.

Jiri
--
Jiri Baum <jiri @baum.com.au> http://www.csse.monash.edu.au/~jirib
MAT LinuxPLC project --- http://mat.sf.net --- Machine Automation Tools
 
Now you've done it... (it's Slovak, not Czech)

Anyway, since google doesn't know about it, it has to be very new or
very obscure, probably both.


The page bills XmmcBUS as a modern unified communication system for
industrial automation, based on XML and http.

The image on http://xmmcbus.europe.webmatrixhosting.net (which is in
English for no apparent reason) presents it as something rather less
(and much more sensible).

One of the other pages mentions that all they've managed to implement is
a translator that can do Modbus "Read Multiple Registers" - and that's
it.


Looking at the XML format, it looks pretty much like what Curt was
suggesting the other day, only done in XML. It's probably at about the
same level of being a standard, too.

Jiri
--
Jiri Baum <[email protected]> http://www.csse.monash.edu.au/~jirib
MAT LinuxPLC project --- http://mat.sf.net --- Machine Automation Tools

 
Top