| | |
| | | import HslCommunication.Core.Types.OperateResultExOne; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.zy.acs.common.utils.News; |
| | | import com.zy.acs.conveyor.core.constant.DeviceField; |
| | | import com.zy.acs.conveyor.core.constant.PlcAlarmDefinition; |
| | | import com.zy.acs.conveyor.core.constant.StationStatusField; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.conveyor.core.constant.*; |
| | | import com.zy.acs.conveyor.core.model.SafeSignal; |
| | | import com.zy.acs.conveyor.core.model.StaProtocol; |
| | | import com.zy.acs.conveyor.core.properties.DevpSlave; |
| | | import com.zy.acs.conveyor.core.service.DevpS7Service; |
| | |
| | | private SiemensS7Net siemensS7Net; |
| | | |
| | | private Map<Integer, StaProtocol> station; |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | | |
| | | private static final int WRITE_RETRY_MAX = 5; |
| | | |
| | |
| | | // 读取PLC故障 |
| | | readPlcAlarms(staNos, staNoSize); |
| | | |
| | | // 读取安全交互信号 |
| | | readSaleSingle(slave.getPutSta(), slave.getTakeSta()); |
| | | |
| | | |
| | | // 定期更新数据库(降低频率) |
| | | updateDatabaseIfNeeded(); |
| | | } |
| | |
| | | staProtocol.setStaNo((int) siemensS7Net.getByteTransform().TransInt16( |
| | | content, offset + StationStatusField.FINAL_TARGET.getOffset())); |
| | | |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool( |
| | | boolean[] status0 = siemensS7Net.getByteTransform().TransBool( |
| | | content, offset + StationStatusField.STATUS_WORD.getOffset(), |
| | | StationStatusField.STATUS_WORD.getByteLength()); |
| | | |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool( |
| | | content, offset + StationStatusField.STATUS_WORD.getOffset(), |
| | | 1); |
| | | |
| | | staProtocol.setAutoing(status[0]); |
| | | staProtocol.setLoading(status[1]); |
| | |
| | | staProtocol.setFullPlt(status[5]); |
| | | staProtocol.setHigh(status[6]); |
| | | staProtocol.setLow(status[7]); |
| | | |
| | | boolean[] status2 = siemensS7Net.getByteTransform().TransBool( |
| | | content, offset + StationStatusField.STATUS_WORD.getOffset() + 1, |
| | | 1); |
| | | staProtocol.setMid(status2[0]); |
| | | staProtocol.setStartup(status2[1]); |
| | | staProtocol.setSegApply(status2[2]); |
| | | staProtocol.setApplyErr(status2[3]); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read( |
| | | DeviceField.BARCODE.buildAddress(), |
| | | (short) ( DeviceField.BARCODE.getByteLength() * DeviceField.BARCODE.getArrLength())); |
| | | (short) (DeviceField.BARCODE.getByteLength() * DeviceField.BARCODE.getArrLength())); |
| | | |
| | | if (!result.IsSuccess) { |
| | | log.warn("读取条码失败 [id:{}]", slave.getId()); |
| | |
| | | byte[] content = result.Content; |
| | | for (int i = 0; i < DeviceField.BARCODE.getArrLength(); i++) { |
| | | int[] seg = DeviceField.BARCODE.getSeg(); |
| | | Short staNo = siemensS7Net.getByteTransform().TransInt16( |
| | | content, seg[0]+i * DeviceField.BARCODE.getByteLength()); |
| | | int staNo = siemensS7Net.getByteTransform().TransInt16( |
| | | content, seg[0] + i * DeviceField.BARCODE.getByteLength()); |
| | | String barcode = siemensS7Net.getByteTransform().TransString( |
| | | content, seg[1]+i * DeviceField.BARCODE.getByteLength(), |
| | | DeviceField.BARCODE.getByteLength()-seg[1], "UTF-8"); |
| | | content, seg[1] + i * DeviceField.BARCODE.getByteLength(), |
| | | DeviceField.BARCODE.getByteLength() - seg[1], "UTF-8"); |
| | | |
| | | if (!Cools.isEmpty(barcode)&& staNo !=null) { |
| | | if (!Cools.isEmpty(barcode) && staNo != 0) { |
| | | StaProtocol staProtocol = station.get(staNo); |
| | | if (staProtocol == null) { |
| | | log.warn("扫码站点不存在 [id:{}] [staNo:{}]", slave.getId(), staNo); |
| | |
| | | * 读取重量信息 |
| | | */ |
| | | private void readWeight() { |
| | | if ( slave.getWeight() == null || ! slave.getWeight()) { |
| | | if (slave.getWeight() == null || !slave.getWeight()) { |
| | | return; |
| | | } |
| | | |
| | |
| | | return; |
| | | } |
| | | byte[] content = result.Content; |
| | | for (int i = 0; i < DeviceField.WEIGHT.getArrLength() ; i++) { |
| | | for (int i = 0; i < DeviceField.WEIGHT.getArrLength(); i++) { |
| | | int[] seg = DeviceField.WEIGHT.getSeg(); |
| | | Short staNo = siemensS7Net.getByteTransform().TransInt16( |
| | | content, seg[0]+i * DeviceField.WEIGHT.getByteLength()); |
| | | int staNo = siemensS7Net.getByteTransform().TransInt16( |
| | | content, seg[0] + i * DeviceField.WEIGHT.getByteLength()); |
| | | Double weight = (double) siemensS7Net.getByteTransform().TransSingle( |
| | | content, seg[1] + i * DeviceField.WEIGHT.getByteLength()); |
| | | if (!Cools.isEmpty(weight)&& staNo !=null) { |
| | | if (!Cools.isEmpty(weight) && staNo != 0) { |
| | | StaProtocol staProtocol = station.get(staNo); |
| | | if (staProtocol == null) { |
| | | log.warn("称重站点不存在 [id:{}] [staNo:{}]", slave.getId(), staNo); |
| | |
| | | } |
| | | staProtocol.setWeight(BigDecimal.valueOf(weight).setScale(4, RoundingMode.HALF_UP).doubleValue()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读取外形检测错误 |
| | | */ |
| | | private void readDimensionErrors() { |
| | | if ( slave.getStaNosError() == null || !slave.getStaNosError()) { |
| | | if (slave.getStaNosError() == null || !slave.getStaNosError()) { |
| | | return; |
| | | } |
| | | |
| | |
| | | byte[] content = result.Content; |
| | | for (int i = 0; i < DeviceField.DIMENSION_WORD.getArrLength(); i++) { |
| | | int[] seg = DeviceField.DIMENSION_WORD.getSeg(); |
| | | Short staNo = siemensS7Net.getByteTransform().TransInt16( |
| | | int staNo = siemensS7Net.getByteTransform().TransInt16( |
| | | content, seg[0]); |
| | | if ( staNo !=null) { |
| | | if (staNo != 0) { |
| | | StaProtocol staProtocol = station.get(staNo); |
| | | if (staProtocol == null){ |
| | | if (staProtocol == null) { |
| | | log.warn("异常站点不存在 [id:{}] [staNo:{}]", slave.getId(), staNo); |
| | | continue; |
| | | } |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool( |
| | | content, seg[1]+i * DeviceField.DIMENSION_WORD.getByteLength(), |
| | | content, seg[1] + i * DeviceField.DIMENSION_WORD.getByteLength(), |
| | | 1); |
| | | //未使用,预留 |
| | | // boolean[] status1 = siemensS7Net.getByteTransform().TransBool( |
| | |
| | | } |
| | | |
| | | /** |
| | | * 读取安全交互信号 |
| | | */ |
| | | private void readSaleSingle(List<DevpSlave.Sta> putSta, List<DevpSlave.Sta> takeSta) { |
| | | int staNoSize = putSta.size(); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read( |
| | | SafeSignalField.SAFE_SIGNAL_FROM_CONVEYOR.buildAddress(), |
| | | (short) (staNoSize * SafeSignalField.SAFE_SIGNAL_FROM_CONVEYOR.getByteLength())); |
| | | |
| | | if (!result.IsSuccess) { |
| | | log.warn("读取PLC安全交互信息异常 [id:{}]", slave.getId()); |
| | | return; |
| | | } |
| | | |
| | | byte[] content = result.Content; |
| | | for (int i = 0; i < staNoSize; i++) { |
| | | Integer put = putSta.get(i).getStaNo(); |
| | | Integer take = takeSta.get(i).getStaNo(); |
| | | StaProtocol staProtocolPut = station.get(put); |
| | | StaProtocol staProtocolTake = station.get(take); |
| | | if (staProtocolPut == null || staProtocolTake == null) { |
| | | log.warn("站点不存在 [id:{}] [staNo:{},{}]", slave.getId(), put, take); |
| | | continue; |
| | | } |
| | | |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool( |
| | | content, i * SafeSignalField.SAFE_SIGNAL_FROM_CONVEYOR.getByteLength(), 1); |
| | | |
| | | boolean[] status2 = siemensS7Net.getByteTransform().TransBool( |
| | | content, i * SafeSignalField.SAFE_SIGNAL_FROM_CONVEYOR.getByteLength() + 2, 1); |
| | | |
| | | staProtocolPut.setHeartbeat(status[0]); |
| | | staProtocolPut.setAllowTake(status[1]); |
| | | staProtocolPut.setAllowPut(status[2]); |
| | | staProtocolPut.setInComplete(status[3]); |
| | | staProtocolPut.setOutComplete(status[4]); |
| | | |
| | | staProtocolTake.setHeartbeat(status2[0]); |
| | | staProtocolTake.setAllowTake(status2[1]); |
| | | staProtocolTake.setAllowPut(status2[2]); |
| | | staProtocolTake.setInComplete(status2[3]); |
| | | staProtocolTake.setOutComplete(status2[4]); |
| | | // |
| | | if (status[3]){ |
| | | redis.push(RedisConveyorConstant.CONVEYOR_SAFE_FLAG, new SafeSignal(i,(short)0,true)); |
| | | } |
| | | if (status2[4]){ |
| | | redis.push(RedisConveyorConstant.CONVEYOR_SAFE_FLAG, new SafeSignal(i, (short) 0,false)); |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 按需更新数据库(降低更新频率) |
| | | */ |
| | | private void updateDatabaseIfNeeded() { |