| | |
| | | } else if(siteId<4000){ |
| | | if (siteId == 2110) { |
| | | if (resultArm5.IsSuccess) { |
| | | // 转换为字符串 |
| | | String resultString = siemensS7Net.getByteTransform().TransString(resultArm5.Content, 2, 254,"UTF-8"); |
| | | // 去除可能的空字符 |
| | | // resultString = resultString.TrimEnd('\0'); |
| | | // System.out.println("2110Barcode:"+resultString); |
| | | staProtocol.setBarcode(resultString); |
| | | staProtocol.setBarcode(parseS7String(resultArm5)); |
| | | } else { |
| | | staProtocol.setBarcode(""); |
| | | } |
| | | } else if (siteId == 2120){ |
| | | if (resultArm6.IsSuccess) { |
| | | // 转换为字符串 |
| | | String resultString = siemensS7Net.getByteTransform().TransString(resultArm6.Content, 2, 254,"UTF-8"); |
| | | // 去除可能的空字符 |
| | | // resultString = resultString.TrimEnd('\0'); |
| | | // System.out.println("2120Barcode:"+resultString); |
| | | staProtocol.setBarcode(resultString); |
| | | staProtocol.setBarcode(parseS7String(resultArm6)); |
| | | } else { |
| | | staProtocol.setBarcode(""); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private String parseS7String(OperateResultExOne<byte[]> result) { |
| | | |
| | | if (result == null || !result.IsSuccess || result.Content == null) { |
| | | return ""; |
| | | } |
| | | |
| | | byte[] buf = result.Content; |
| | | |
| | | if (buf.length < 2) { |
| | | return ""; |
| | | } |
| | | |
| | | // S7 字符串格式: |
| | | // buf[0] = 最大长度 |
| | | // buf[1] = 当前真实长度 |
| | | int realLen = buf[1] & 0xFF; |
| | | |
| | | if (realLen <= 0) { |
| | | return ""; |
| | | } |
| | | |
| | | // 防止 PLC 写错长度导致越界 |
| | | if (realLen > buf.length - 2) { |
| | | realLen = buf.length - 2; |
| | | } |
| | | |
| | | String value = siemensS7Net.getByteTransform() |
| | | .TransString(buf, 2, realLen, "UTF-8"); |
| | | |
| | | return value == null ? "" : value.trim(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置入库标记 |
| | | */ |