[英]How to convert message to (copco) open protocol based on tcp/ip with Java sockets?
I am trying to develop software for torque. 我正在尝试开发扭矩软件。 I connect to device by java sockets, but I don't know how to establish session with torque.
我通过java套接字连接到设备,但是我不知道如何用扭矩建立会话。 Establish communication steps:
建立沟通步骤:
me(client):send- MID 0001 我(客户):发送-MID 0001
torque(server):send- MID 0002 扭矩(服务器):发送-MID 0002
To do this I have to convert message MID 0001 to OPEN Protocol, according to documentation the result is:002000010000000000000 When I send this message server don't answer. 为此,我必须将消息MID 0001转换为OPEN协议,根据文档,结果是:002000010000000000000当我发送此消息时,服务器不应答。
Maybe my message isn't converted to Open protocol good? 也许我的消息没有转换为开放协议好吗?
I was trying with sending message as bytes or string. 我正在尝试以字节或字符串形式发送消息。 Anyone know how to establish connection with Stanley torque using alpha open protocol and Java?
有人知道如何使用Alpha开放协议和Java与Stanley扭矩建立连接吗?
My client code: 我的客户代码:
public class MyClientSocket {
private static Socket socket;
public static void main(String args[]) {
try {
String host = "192.168.1.15";
int port = 4545;
InetAddress address = InetAddress.getByName(host);
socket = new Socket(address, port);
//Send the message to the server
DataOutputStream os = new DataOutputStream(socket.getOutputStream());
String sendMessage = "002000010000000000000";
byte[] bytes = sendMessage.getBytes(StandardCharsets.US_ASCII);
os.write(bytes);
// os.writeUTF(sendMessage);
System.out.println("Message sent to the server : " + sendMessage);
//Get the return message from the server
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String message = br.readLine();
System.out.println("Message received from the server : " + message);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
this is output: 这是输出:
Message sent to the server : 002000010000000000000
Message received from the server : null
Process finished with exit code 0
Please help me. 请帮我。
I found solution by myself. 我自己找到了解决方案。 The last zero in message is end message zero and i had to wrote message like this:
消息中的最后一个零是结束消息零,我不得不这样写消息:
"00200001000000000000\0"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.