我目前正在研究 ASTM 协议,以向医疗仪器发送订单测试请求。但是我无法正确地向设备发送消息。更明确地说,我想例如发送这些帧:
String h1, s2, s3, s4, s5, s6 = "";
h1 = "H|@^\\|ODM-IdfDGIWA-36|||GeneXpert PC^GeneXpert^4.8|||||LIS||P|1394-97|20070521100245";
s2 = "P|1";
s3 = "O|1|SID-818||^^^TestId-12|S|20070812140500|||||A||||ORH||||||||||Q";
s4 = "O|2|SID-818||^^^TestId-14|S|20070812140600|||||A||||ORH||||||||||Q";
s5 = "O|3|SID-818||^^^TestId-16|S|20070812140700|||||A||||ORH||||||||||Q";
s6 = "L|1|F";
Run Code Online (Sandbox Code Playgroud)
这是我现在的做法:
writeMeBytes(outToServer, h1.getBytes());
writeMeBytes(outToServer, s2.getBytes());
writeMeBytes(outToServer, s3.getBytes());
writeMeBytes(outToServer, s4.getBytes());
writeMeBytes(outToServer, s5.getBytes());
writeMeBytes(outToServer, s6.getBytes());
public static void writeMeBytes(DataOutputStream dos, byte [] b){
if (b.length >0){
int j = 0;
while (j <= b.length-1) {
try {
dos.write(b[j++]);
} catch (IOException ex) {
Logger.getLogger(SimpleServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我把它变成字节,然后一个字节一个字节地发送。 …