簡體   English   中英

如何使用Java套接字將基於tcp / ip的消息轉換為(copco)開放協議?

[英]How to convert message to (copco) open protocol based on tcp/ip with Java sockets?

我正在嘗試開發扭矩軟件。 我通過java套接字連接到設備,但是我不知道如何用扭矩建立會話。 建立溝通步驟:

我(客戶):發送-MID 0001

扭矩(服務器):發送-MID 0002

為此,我必須將消息MID 0001轉換為OPEN協議,根據文檔,結果是:002000010000000000000當我發送此消息時,服務器不應答。
也許我的消息沒有轉換為開放協議好嗎?

在此處輸入圖片說明 在此處輸入圖片說明

我正在嘗試以字節或字符串形式發送消息。 有人知道如何使用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\0"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM