Hello,
Thank you for great API. It works perfectly fine.
I would like to write my own code. Just a simple one to send data to send a input register response to Vijeo Citect over Modbus TCP. Jamod does it very well but when I use my own code nothing happens.
My code :
import java.io.*;
import java.net.*;
public class Modbus extends Thread {
Socket s=null;
InputStream is=null;
byte[] b = new byte [12];
int i;
byte[] sb = new byte [11];
OutputStream os=null;
Modbus(Socket so) {
s=so;
}
public void run() {
try {
os = s.getOutputStream();
is = s.getInputStream();
is.read(b);
for(int l=0;l<12;l++) {
System.out.println(""+b[l]);
}
sb[0] = b[0];
sb[1] = b[1];
sb[5] = 5;
sb[6] = b[6];
sb[7] = b[7];
sb[8] = 2;
sb[9] = 00;
sb[10] = 01;
os.write(sb);
os.flush();
}
catch (Exception e) {
System.out.println("Error "+e);
}
finally {
try {
s.close();
}
catch (Exception e) {
System.out.println("Error "+e);
}
}
}
public static void main (String args[]) {
ServerSocket ss = null;
Socket socket = null;
try {
ss = new ServerSocket(502);
System.out.println("Listening");
while(true) {
socket = ss.accept();
System.out.println("Connection established");
new Modbus(socket).start();
}
}
catch (Exception e) {
System.out.println("hata "+e);
}
finally {
try {
socket.close();
ss.close();
}
catch (Exception e) {
System.out.println("Error "+e);
}
}
}
}
It does not work for a reason. Any idea why ?
I receive request as
00
00
00
00
00
06
00
03
00
00
00
01
Thanks