简体   繁体   中英

Send data to rs232/usb-adapter via socket in java

I want to send this hex command block:

1B 40 26 0D

over a java socket and a proxy (serproxy) to a machine with RS232. I have following code:

DataOutputStream outToServer  = new DataOutputStream(this.clientsocket.getOutputStream());
String command5 = "\u001b\u0040\u0026\u240D";
outToServer.writeUTF(command5);
outToServer.flush();

Socket and serproxy are correctly configured. Anybody with an idea?

The writeUTF function writes the length of the string before its characters. What you can use is plain write:

byte[] bytes = {0x1B, 0x40, ...};
out.write(bytes)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM