我目前正在制定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";
以下是我现在的表现:
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);
}
}
}
}
我将其转换为字节,然后逐字节发送。
除了接收方没有看到任何变化外。
根据@Muhammad答案更新
这就是我向GeneXpert DX系统发送订单所做的工作
public class SimpleServer {
private static ServerSocket server;
private static Socket connection;
public static void main(String args[]) throws IOException, InterruptedException {
server = new ServerSocket(12221);
boolean stopped = false;
System.out.println(" start... ");
connection = server.accept();
System.out.println("wait for connection");
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connection.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connection.getOutputStream());
String currentMsg = "";
int clientIntMessage;
String h1, s2, s3, s4, s5, s6 = "";
h1 = "1H|@^\\|ODM-IdfDGIWA-36|||GeneXpert PC^GeneXpert^4.8|||||LIS||P|1394-97|20070521100245" + ProtocolASCII.LF
+ "P|1" + ProtocolASCII.LF
+ "O|1|SID-818||^^^TestId-12|S|20070812140500|||||A||||ORH||||||||||Q" + ProtocolASCII.LF
+ "L|1|F" + ProtocolASCII.LF;
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";
String retmsg = h1;
//logException("OrderMessae :" + retmsg);
retmsg = ProtocolASCII.STX + retmsg + ProtocolASCII.CR + ProtocolASCII.ETX + ProtocolMessage.getCheckSum(retmsg) + ProtocolASCII.CR + ProtocolASCII.LF;
clientIntMessage = inFromClient.read();
//while (clientIntMessage != ProtocolASCII.EOT) {
while (true) {
currentMsg += String.valueOf(Character.toChars(clientIntMessage));
if (clientIntMessage == ProtocolASCII.ENQ) {
outToClient.writeBytes("" + ProtocolASCII.ACK);
System.out.println(" <--- LIS [ACK] on DX [ENQ]");
} else if (clientIntMessage == ProtocolASCII.ACK) {
System.out.println(" ---> DX [ACK]");
// Send your order message here
outToClient.writeBytes(retmsg);
} else if (clientIntMessage == ProtocolASCII.CR) {
System.out.println(currentMsg);
outToClient.writeBytes("" + ProtocolASCII.ACK);
} else if (clientIntMessage == ProtocolASCII.NAK) {
System.out.println(" ---> DX sent [NAK] ");
System.out.println(" --- LIS now wait 10 sec... ");
Thread.sleep(10000);
outToClient.writeBytes("" + ProtocolASCII.ENQ);
System.out.println(" <--- LIS [ENQ] ");
} else if (clientIntMessage == ProtocolASCII.EOT) {
System.out.println(" ---> DX END OF TRANSMISSION");
outToClient.writeBytes("" + ProtocolASCII.ENQ);
System.out.println(" <--- LIS [ENQ] ");
}
if (stopped) {
break;
}
clientIntMessage = inFromClient.read();
}
connection.close();
stopped = true;
}}
这是我从控制台得到的结果:
start...
wait for connection
<--- LIS [ACK] on DX [ENQ]
1H|@^\|ODM-rQTcjIWA-66||GeneXpert PC^GeneXpert^4.8|||||LIS||P|1394-97|20180314003724
Q|1|ALL||||||||||O@N
L|1|N
B5
---> DX [EOT]
<--- LIS [ENQ]
---> DX [ACK]
---> DX sent [NAK]
--- LIS now wait 10 sec...
DX是机器软件,LIS是主机。 每当我尝试发送ENQ时,机器都会用NAK回答我。
更新2
它似乎工作。但是现在Windows事件向我显示了一个错误,为什么我的记录命令没有出现在GeneXpert DX主机记录列表中。标题记录已首先发送。
答案 0 :(得分:3)
在回答之前,让我们讨论双向的机制。
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";
首先,查看上面的字符串消息,没有任何标记编号,因为到目前为止我所做的每台计算机都需要标记号。例如:
1H|\^&|||CS-2500^00-08^22029^^^CP^BV981798||||||||E1394-97
2P|1|||00000152556|^JOHN^ABC||19440601|M|||||^Dr.Shaukat Khanum Hospital|||||||||^^^EAST
3O|1|000038^01^0012586236^B||^^^051^^100.00¥^^^044^^100.00|R|201803081225236|||||N
4L|1|N
因此,每个代码必须包含 NUMBERING 。
第二次,机器首次发送以下查询:
1H|\^&|||CS-2500^^22029^^^CP^BV981798||||||||E1394-9711
2Q|1|000038^01^ 0012365845B||^^^040^PT-INN\^^^050^APTT-FS|0|201803081227007F
3L|1|NF9
在,查询(2Q)标记,000038
机架ID,01
机架序列号,001H18074618
样本ID(从条形码读取),可以从主机或LIS验证更多信息机器供应商提供的手册。
第三次,当我们收到此消息时,我们会为上面描述的机器(下面再次写入)提供其他校验和信息。同样,这个校验和可以在机器的主机或LIS手册中找到。
1H|\^&|||CS-2500^00-08^22029^^^CP^BV981798||||||||E1394-97
2P|1|||00000152556|^JOHN^ABC||19440601|M|||||^Dr.Shaukat Khanum Hospital|||||||||^^^EAST
3O|1|000038^01^12345678^B||^^^051^^100.00¥^^^044^^100.00|R|201803081225236|||||N
4L|1|N
校验和计算示例。请注意,它可能因机器而异。
public static String getCheckSum(String msg) {
int sum = 0;
for (int i = 0; i < msg.length(); i++) {
sum += msg.charAt(i);
}
sum += 16; //adding CR and ETX AND ETB
sum = sum % 256;
String checksum = Integer.toHexString(sum).toUpperCase();
if (checksum.length() == 1) {
checksum = "0" + checksum;
}
//System.out.println("\n Check Sum is ="+checksum);
return checksum;
}
这是我们发送给机器的完整信息:
String retmsg = "3O|1|" + rackId + "^" + positionNumber + "^" + sampleId + "^B||" + testIds + "|" + priority + "|" + sysDate + "|||||" + orderType + "";
logException("OrderMessae :" + retmsg);
retmsg = ProtocolASCII.STX + retmsg + ProtocolASCII.CR + ProtocolASCII.ETX + ProtocolMessage.getCheckSum(retmsg) + ProtocolASCII.CR + ProtocolASCII.LF;
最后但并非最不重要,我不知道机器是什么,因为我没有手册,但我觉得你不需要逐个发送每条消息。您可以一次发送所有内容。
这是发送和接收来自机器的消息的代码片段。
while (clientIntMessage != ProtocolASCII.EOT) {
clientIntMessage = inFromClient.read();
currentMsg += String.valueOf(Character.toChars(clientIntMessage));
// System.out.println(currentMsg);
if (clientIntMessage == ProtocolASCII.ENQ) {
outToClient.writeBytes("" + ProtocolASCII.ACK);
System.out.println("[ACK] on Analyzer [ENQ]");
} else if (clientIntMessage == ProtocolASCII.ACK) {
System.out.println("Analyzer [ACK]");
// Send your order message here
outToClient.writeBytes(retmsg);
}
} else if (clientIntMessage == ProtocolASCII.LF) {
outToClient.writeBytes("" + ProtocolASCII.ACK);
} else if (clientIntMessage == ProtocolASCII.NAK) {
System.out.println(" Analyzer sent [NAK] ");
}
}
ProtocolASCII.ACK 为'\006'
, ProtocolASCII.ENQ 为'\005'
, ProtocolASCII.EOT 为{ {1}}。
代码几乎是自我解释的,我在生产中使用它。
您能告诉我们您正在连接哪台机器吗?如果我已经集成,它可能会有所帮助。
谢谢。如果需要进一步的帮助,请告诉我。
供您参考:
'\004'
<强>更新强>
来自您的评论:
public class ProtocolASCII {
public static char STX = '\002';
public static char ETX = '\003';
public static char ETB = '\027';
public static char EOT = '\004';
public static char ENQ = '\005';
public static char ACK = '\006';
public static char NAK = '\025';
public static char CR = '\r';
public static char LF = '\n';
public static char MOR = '>';
public static char FS = '\034';
public static char GS = '\035';
public static char RS = '\036';
public static char SFS = '\027';
public static char VT = 0x0B; //END OF BLOCK 011
}
其中 testIds 是要执行的测试列表。
示例多重订单发送String retmsg = "3O|1|" + rackId + "^" + positionNumber + "^" + sampleId + "^B||" + testIds + "|" + priority + "|" + sysDate + "|||||" + orderType + "";
从LIS手册或公司工程师处获取测试代码并相应地制作模式。
更新2
4O|1||4^1^ 12345678^B|^^^^WBC\^^^^RBC\^^^^HGB\^^^^HCT\^^^^MCV\^^^^MCH\^^^^MCHC\^^^^PLT\^^^^RDW-SD\^^^^RDW-CV\^^^^PDW\^^^^MPV\^^^^P-LCR\^^^^PCT\^^^^NEUT#\^^^^LYMPH#\^^^^MONO#\^^^^EO#\^^^^BASO#\^^^^NEUT%\^^^^LYMPH%\^^^^MONO%\^^^^EO%\^^^^BASO%\^^^^NRBC#\^^^^NRBC%\^^^^IG#\^^^^IG%|||||||N||||||||||||||F