Member Login
member
passwd
remember me on
this computer.

- join now -
- forgot username or password? -

Search

Jump to a Date

Sponsored Communities
Cool stuff
Select a topic of interest:
...and press:
Neat Stuff
Control.com Stuff

Visit our shop for nerds in control lifestyle products.

Fortune
Court, n.:
A place where they dispense with justice.
-- Arthur Train
RSS Feed
RSS feed Use this link to get an RSS feed of the Control.com article flow, for private, non-commercial use only:
www.control.com/rss/
To get a personalized feed, become a member at no cost.
Select a Page Style
Select one of the following styles:
- BluFu
- Classic
(cookies required)
advertisement
from the Automation List department...
Modbus Requests and Java
Communications systems and equipment. topic
Posted by gishac on 26 May, 2008 - 12:36 pm
Hi, I'm trying to read data from a PM500 power meter, I'm using java to get connected, the connection is fine. the problem is I don't know the correct format to send the request to the device, the code is the following:

InetAddress ipaddress = InetAddress.getByAddress("192.168.8.42", new byte[]{(byte)192, (byte)168, (byte)8, (byte)42});
Socket xocket = new Socket(ipaddress, 771);
OutputStream output = xocket.getOutputStream();
BufferedInputStream input = new BufferedInputStream(xocket.getInputStream());
byte buffer[] = new byte[261];
DataOutputStream dos = new DataOutputStream(output);

//Here is the problem, the request I want to do is
// 01 03 03 00 00 62 C4 67, and I don't know how to build the request buffer
dos.writeByte(1); // device id
dos.writeShort(3);// function
dos.writeByte(0x0300);//register to start
dos.writeByte(0x0062); // register to end
dos.writeByte(0xC467); // crc
output.flush();
int totalRead = input.read(buffer, 0, 261);

The response I always get is -1208011111411632105115321111171163211110232114971101031010

Any idea of how to build the request buffer correctly or some code sample? I tried using jamod but I get lot of errors when I send the request, so I decided used my own code.

thanks in advance

gishac


Posted by rbk on 27 May, 2008 - 8:14 pm
Try to rebuild the code in a new the 552 series.


Posted by gishac on 28 May, 2008 - 9:19 pm
I must use PM500 series. Any idea of how to send the request???


Posted by Dave on 2 July, 2008 - 12:42 am
Hi gishac,

I'm trying to do the same thing... I found this tutorial that helps you to make a java applet that can connect to your device...
http://ltxfaq.custhelp.com/cgi-bin/ltxfaq.cfg/php/enduser/std_adp. php?p_faqid=943&p_created=1075227796&p_sid=NoP2jG7j&p_accessi bility=0&p_redirect=&p_lva=&p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZw X2dyaWRzb3J0PSZwX3Jvd19jbnQ9MSZwX3Byb2RzPTAmcF9jYXRzPSZwX3B2PSZwX2N2PSZwX 3NlYXJjaF90eXBlPWFuc3dlcnMuYV9pZCZwX3BhZ2U9MSZwX3NlYXJjaF90ZXh0PTk0Mw**&a mp;p_li=&p_topview=1

But the only problem I'm having is that I receive the data in ASCII and I have to change it to Decimal.


Posted by Jon Parise on 6 August, 2008 - 12:37 am
Hey,

I was able to create a Java Modbus library just by working from the online specs. If you need to understand what the packets contain you should really take a look at them.

It is fairly straight forward to create the packets once you know what they look like.

Let me know if you have questions.

From Control Engineering magazine...
Related articles from Control Engineering magazine
Above articles copyright 2008 Reed Business Information. Subject to its Terms of Use.
Your use of this site is subject to the terms and conditions set forth under Legal Notices and the Privacy Policy. Please read those terms and conditions carefully. Subject to the rights expressly reserved to others under Legal Notices, the content of this site and the compilation thereof is © 1999-2008 Control Technology Corporation. All rights reserved.

Users of this site are benefiting from open source technologies, including PHP, MySQL and Apache. Be happy.

Internet Explorer 6.0 Fix

Advertisement
Our Advertisers
Help keep our servers running...
Patronize our advertisers!