如何将消息转换为基于 tcp/ip 和 Java 套接字的 (copco) 开放协议?
How to convert message to (copco) open protocol based on tcp/ip with Java sockets?
我正在尝试开发扭矩软件。我通过 java 套接字连接到设备,但我不知道如何使用扭矩建立会话。
建立沟通步骤:
我(客户端):发送- MID 0001
扭矩(服务器):发送- MID 0002
为此,我必须将消息 MID 0001 转换为 OPEN 协议,根据文档结果 is:002000010000000000000
当我发送此消息时,服务器不应答。
也许我的消息没有转换为 Open 协议?
我正在尝试以字节或字符串形式发送消息。
任何人都知道如何使用 alpha 开放协议和 Java 与 Stanley 扭矩建立连接?
我的客户代码:
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();
}
}
}
这是输出:
Message sent to the server : 002000010000000000000
Message received from the server : null
Process finished with exit code 0
请帮帮我。
我自己找到了解决方案。消息中的最后一个零是结束消息零,我不得不这样写消息:
"00200001000000000000[=10=]"
我正在尝试开发扭矩软件。我通过 java 套接字连接到设备,但我不知道如何使用扭矩建立会话。 建立沟通步骤:
我(客户端):发送- MID 0001
扭矩(服务器):发送- MID 0002
为此,我必须将消息 MID 0001 转换为 OPEN 协议,根据文档结果 is:002000010000000000000
当我发送此消息时,服务器不应答。
也许我的消息没有转换为 Open 协议?
我正在尝试以字节或字符串形式发送消息。 任何人都知道如何使用 alpha 开放协议和 Java 与 Stanley 扭矩建立连接?
我的客户代码:
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();
}
}
}
这是输出:
Message sent to the server : 002000010000000000000
Message received from the server : null
Process finished with exit code 0
请帮帮我。
我自己找到了解决方案。消息中的最后一个零是结束消息零,我不得不这样写消息:
"00200001000000000000[=10=]"