|  |  |  | 
|---|
|  |  |  | import com.core.common.SpringUtils; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasDevp; | 
|---|
|  |  |  | import com.zy.asrs.service.BasDevpService; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.core.DevpThread; | 
|---|
|  |  |  | import com.zy.core.cache.MessageQueue; | 
|---|
|  |  |  | import com.zy.core.cache.OutputQueue; | 
|---|
|  |  |  | 
|---|
|  |  |  | private void read() throws InterruptedException { | 
|---|
|  |  |  | OperateResultExOne<byte[]> result = melsecMcNet.Read("D101", (short) 30); | 
|---|
|  |  |  | if (result.IsSuccess) { | 
|---|
|  |  |  | for (int i = 1; i <= 7; i++) { | 
|---|
|  |  |  | StaProtocol staProtocol = station.get(i); | 
|---|
|  |  |  | // 站点数据 | 
|---|
|  |  |  | for (int i = 0; i < staNos.size(); i++) { | 
|---|
|  |  |  | Integer siteId = staNos.get(i); // 站点编号 | 
|---|
|  |  |  | StaProtocol staProtocol = station.get(siteId); | 
|---|
|  |  |  | if (null == staProtocol) { | 
|---|
|  |  |  | staProtocol = new StaProtocol(); | 
|---|
|  |  |  | staProtocol.setSiteId(i); | 
|---|
|  |  |  | station.put(i, staProtocol); | 
|---|
|  |  |  | staProtocol.setSiteId(siteId); | 
|---|
|  |  |  | station.put(siteId, staProtocol); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | staProtocol.setWorkNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2));     // 工作号 | 
|---|
|  |  |  | staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+40));   // 目标站 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 根据实时信息更新数据库 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | List<BasDevp> basDevps = new ArrayList<>(); | 
|---|
|  |  |  | for (int i = 1; i <= 7; i++) { | 
|---|
|  |  |  | StaProtocol staProtocol = station.get(i); | 
|---|
|  |  |  | for (Integer siteId : staNos) { | 
|---|
|  |  |  | StaProtocol staProtocol = station.get(siteId); | 
|---|
|  |  |  | basDevps.add(staProtocol.toSqlModel()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (null == staProtocol) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OperateResult write = melsecMcNet.Write("D10" + staProtocol.getSiteId(), staProtocol.getWorkNo());    // 工作号 | 
|---|
|  |  |  | OperateResult write = melsecMcNet.Write("D1" + Utils.zerofill(String.valueOf(staNos.indexOf(staProtocol.getSiteId())+1), 2), staProtocol.getWorkNo());    // 工作号 | 
|---|
|  |  |  | Thread.sleep(400); | 
|---|
|  |  |  | OperateResult write1 = melsecMcNet.Write("D12" + staProtocol.getSiteId(), staProtocol.getStaNo());    // 目标站 | 
|---|
|  |  |  | OperateResult write1 = melsecMcNet.Write("D1" + Utils.zerofill(String.valueOf(staNos.indexOf(staProtocol.getSiteId())+21), 2), staProtocol.getStaNo());    // 目标站 | 
|---|
|  |  |  | if (!write.IsSuccess || !write1.IsSuccess) { | 
|---|
|  |  |  | staProtocol = station.get(staProtocol.getSiteId()); | 
|---|
|  |  |  | if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { | 
|---|