| | |
| | | |
| | | import HslCommunication.Core.Types.OperateResult; |
| | | import HslCommunication.Core.Types.OperateResultExOne; |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | |
| | | |
| | | private List<ZyStationStatusEntity> statusList; |
| | | private List<ZyStationStatusEntity> barcodeStatusList; |
| | | private final SiemensS7Net siemensNet; |
| | | private final DeviceConfig deviceConfig; |
| | | private SiemensS7Net siemensNet; |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | | |
| | | public ZyStationRealConnect(SiemensS7Net siemensNet, DeviceConfig deviceConfig) { |
| | | this.siemensNet = siemensNet; |
| | | public ZyStationRealConnect(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | | this.redisUtil = redisUtil; |
| | | } |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | boolean connected = false; |
| | | siemensNet = new SiemensS7Net(SiemensPLCS.S1200, deviceConfig.getIp()); |
| | | OperateResult connect = siemensNet.ConnectServer(); |
| | | if (connect.IsSuccess) { |
| | | connected = true; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<ZyStationStatusEntity> getStatus() { |
| | | public List<ZyStationStatusEntity> getStatus(Integer deviceNo) { |
| | | if (statusList == null) { |
| | | BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); |
| | | if (basDevpService == null) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public CommandResponse sendCommand(StationCommand command) { |
| | | public CommandResponse sendCommand(Integer deviceNo, StationCommand command) { |
| | | CommandResponse commandResponse = new CommandResponse(false); |
| | | if (null == command) { |
| | | commandResponse.setMessage("命令为空"); |
| | |
| | | return commandResponse; |
| | | } |
| | | |
| | | @Override |
| | | public CommandResponse sendOriginCommand(String address, short[] data) { |
| | | CommandResponse commandResponse = new CommandResponse(false); |
| | | if (null == data || data.length == 0) { |
| | | commandResponse.setMessage("数据为空"); |
| | | return commandResponse; |
| | | } |
| | | |
| | | OperateResult write = siemensNet.Write(address, data); |
| | | if (write.IsSuccess) { |
| | | log.info("写入原始命令成功。地址={},数据={}", address, JSON.toJSON(data)); |
| | | commandResponse.setResult(true); |
| | | } else { |
| | | log.error("写入原始命令失败。地址={},数据={}", address, JSON.toJSON(data)); |
| | | commandResponse.setResult(false); |
| | | } |
| | | return commandResponse; |
| | | } |
| | | |
| | | @Override |
| | | public byte[] readOriginCommand(String address, int length) { |
| | | OperateResultExOne<byte[]> result = siemensNet.Read(address, (short) length); |
| | | if (result.IsSuccess) { |
| | | return result.Content; |
| | | } |
| | | return new byte[0]; |
| | | } |
| | | |
| | | private ZyStationStatusEntity findStatusEntity(Integer stationId) { |
| | | for (ZyStationStatusEntity statusEntity : statusList) { |
| | | if (statusEntity.getStationId().equals(stationId)) { |
| | |
| | | } |
| | | return -1; |
| | | } |
| | | } |
| | | } |