| | |
| | | return String.valueOf(barcode); |
| | | } |
| | | |
| | | public void setBarcode(String barcode) { |
| | | @Override |
| | | public boolean setBarcode(String barcode) { |
| | | this.lastBarcode = String.valueOf(this.barcode); |
| | | this.barcode.delete(0, this.barcode.length()); |
| | | this.barcode.append(barcode); |
| | |
| | | OutputQueue.BARCODE.poll(); |
| | | } |
| | | OutputQueue.BARCODE.offer(jsonObject); |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void run() { |
| | | this.connect(); |
| | | while (true) { |
| | | try { |
| | | DeviceBarcodeService deviceBarcodeService = SpringUtils.getBean(DeviceBarcodeService.class); |
| | | if (deviceBarcodeService == null) { |
| | | continue; |
| | | } |
| | | |
| | | DeviceBarcode deviceBarcode = deviceBarcodeService.getOne(new LambdaQueryWrapper<DeviceBarcode>() |
| | | .eq(DeviceBarcode::getDeviceId, device.getId()) |
| | | .eq(DeviceBarcode::getHostId, device.getHostId()) |
| | | .eq(DeviceBarcode::getStatus, 1)); |
| | | if (deviceBarcode == null) { |
| | | continue; |
| | | } |
| | | |
| | | JSONObject connect = JSON.parseObject(deviceBarcode.getConnect()); |
| | | String address = connect.getString("address"); |
| | | Short length = connect.getShort("length"); |
| | | |
| | | // 条码扫描器 |
| | | OperateResultExOne<byte[]> result = null; |
| | | result = siemensS7Net.Read(address, length); |
| | | if (result.IsSuccess) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result.Content, 0, length, "UTF-8"); |
| | | setBarcode(barcode); |
| | | } |
| | | } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | // this.connect(); |
| | | // while (true) { |
| | | // try { |
| | | // DeviceBarcodeService deviceBarcodeService = SpringUtils.getBean(DeviceBarcodeService.class); |
| | | // if (deviceBarcodeService == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // DeviceBarcode deviceBarcode = deviceBarcodeService.getOne(new LambdaQueryWrapper<DeviceBarcode>() |
| | | // .eq(DeviceBarcode::getDeviceId, device.getId()) |
| | | // .eq(DeviceBarcode::getHostId, device.getHostId()) |
| | | // .eq(DeviceBarcode::getStatus, 1)); |
| | | // if (deviceBarcode == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // JSONObject connect = JSON.parseObject(deviceBarcode.getConnect()); |
| | | // String address = connect.getString("address"); |
| | | // Short length = connect.getShort("length"); |
| | | // |
| | | // // 条码扫描器 |
| | | // OperateResultExOne<byte[]> result = null; |
| | | // result = siemensS7Net.Read(address, length); |
| | | // if (result.IsSuccess) { |
| | | // String barcode = siemensS7Net.getByteTransform().TransString(result.Content, 0, length, "UTF-8"); |
| | | // setBarcode(barcode); |
| | | // } |
| | | // } catch (Exception e) { |
| | | //// e.printStackTrace(); |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | } |