配置:
<template type="0500">
<field num="3" type="NUMERIC" length="6">920000</field>
<field num="11" type="NUMERIC" length="6" />
<field num="24" type="NUMERIC" length="3" />
<field num="41" type="ALPHA" length="8" />
<field num="42" type="ALPHA" length="15" />
</template>
代码:
MessageFactory mfact = ConfigParser
.createFromClasspathConfig("config.xml");
mfact.setTraceNumberGenerator(new SimpleTraceGenerator((int) (System.currentTimeMillis() % 100000)));
m = mfact.newMessage(0x500);
m.setValue(24, 109, IsoType.NUMERIC, 3);
m.setValue(41, "10986312", IsoType.ALPHA, 8);
m.setValue(42, "000001106020132", IsoType.ALPHA, 15);
String strMsg = new String(msg.writeData());
strMsg
给了我这个结果:
05 00 20 20 01 00 00 C0 00 00 92 00 00 04 42 18 10 91 09 86 31 20 00 00 11 06 02 01 32
但结果应该是:
05 00 20 20 01 00 00 C0 00 00 92 00 00 04 42 18 01 09 31 30 39 38 36 33 31 32 30 30 30 30 30 31 31 30 36 30 32 30 31 33 32
在哪里:
field 24 => 109 should be 0109
field 41 => 10986312 should be in hex 3130393836333132
feild 42 => 000001106020132 should be in hex 303030303031313036303230313332
字段 41 和 42 都是字母数字特殊字符字段。
在使用 TCP/IP 发送到主机之前,我应该使用HexCodec.hexEncode
部分消息的整个消息吗?