自动化立体仓库 - WCS系统
999
zhangc
9 天以前 cf4c19268b9d5d65c3723cab869d1879954cff2d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
package com.zy.core.thread.impl;
 
import HslCommunication.Core.Types.OperateResult;
import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasLift;
import com.zy.asrs.entity.DeviceDataLog;
import com.zy.asrs.service.BasLiftService;
import com.zy.asrs.service.DeviceDataLogService;
import com.zy.asrs.utils.Utils;
import com.zy.common.ExecuteSupport;
import com.zy.common.model.NavigateNode;
import com.zy.common.service.CommonService;
import com.zy.common.utils.LiftUtils;
import com.zy.common.utils.NavigatePositionConvert;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.action.ForkLiftAction;
import com.zy.core.action.LiftAction;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.ForkLiftTaskModeType;
import com.zy.core.enums.LiftCommandModeType;
import com.zy.core.enums.LiftProtocolStatusType;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.model.CommandResponse;
import com.zy.core.model.LiftSlave;
import com.zy.core.model.command.LiftCommand;
import com.zy.core.model.protocol.LiftProtocol;
import com.zy.core.model.protocol.LiftStaProtocol;
import com.zy.core.thread.LiftThread;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
import java.util.*;
 
@Slf4j
@SuppressWarnings("all")
public class NyLiftThread implements LiftThread {
 
    private SiemensS7Net siemensS7Net;
    private LiftSlave slave;
    private LiftProtocol liftProtocol;
    private RedisUtil redisUtil;
    private List<LiftStaProtocol> liftStaProtocols = new ArrayList<>();
 
    public static final HashMap<Integer, Integer> liftLevMap = new HashMap<Integer, Integer>() {{
        put(1, 101);
        put(2, 102);
        put(3, 103);
        put(4, 104);
        put(5, 105);
        put(6, 106);
        put(7, 107);
        put(8, 108);
        put(9, 109);
        put(10, 1023);
        put(11, 1032);
    }};
 
    public static final HashMap<Integer, List<String>> liftNodeMap = new HashMap<Integer, List<String>>() {{
        put(1, new ArrayList<String>(){{add("0200201");add("0200101");}});
        put(2, new ArrayList<String>(){{add("0200202");add("0200102");}});
        put(3, new ArrayList<String>(){{add("0200203");add("0200103");}});
        put(4, new ArrayList<String>(){{add("0200204");add("0200104");}});
        put(5, new ArrayList<String>(){{add("0200205");add("0200105");}});
        put(6, new ArrayList<String>(){{add("0200206");add("0200106");}});
        put(7, new ArrayList<String>(){{add("0200207");add("0200107");}});
        put(8, new ArrayList<String>(){{add("0200208");add("0200108");}});
        put(9, new ArrayList<String>(){{add("0200209");add("0200109");}});
    }};
 
    public NyLiftThread(LiftSlave slave, RedisUtil redisUtil) {
        this.slave = slave;
        this.redisUtil = redisUtil;
        //初始化站点
        for (LiftSlave.Sta sta : this.slave.getSta()) {
            LiftStaProtocol liftStaProtocol = new LiftStaProtocol();
            liftStaProtocol.setStaNo(sta.getStaNo());//站点号
            liftStaProtocol.setLev(sta.getLev());//站点楼层
            String locNo = Utils.getLocNo(this.slave.getStaRow(), this.slave.getStaBay(), sta.getLev());
            liftStaProtocol.setLocNo(locNo);//站点库位号
            liftStaProtocol.setLiftNo(sta.getLiftNo());//提升机号
            liftStaProtocols.add(liftStaProtocol);
        }
    }
 
    @Override
    public void run() {
        News.info("{}号提升机线程启动", slave.getId());
        this.connect();
        while (true) {
            try {
                read();
                Thread.sleep(500);
                execute();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
    private void execute() {
        LiftAction liftAction = SpringUtils.getBean(LiftAction.class);
        if (liftAction == null) {
            return;
        }
 
        Object object = redisUtil.get(RedisKeyType.LIFT_FLAG.key + slave.getId());
        if (object == null) {
            return;
        }
 
        Integer taskNo = Integer.valueOf(String.valueOf(object));
        if (taskNo != 0) {
            //存在任务需要执行
            boolean result = liftAction.executeWork(slave.getId(), taskNo);
        }
    }
 
    @Override
    public List<LiftStaProtocol> getLiftStaProtocols() {
        return this.liftStaProtocols;
    }
 
    private void read() {
        try {
            readStatus();
 
            //提升机处于运行状态,将标记置为true
            if (liftProtocol.getRun()) {
                liftProtocol.setPakMk(true);
            }
        } catch (Exception e) {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】读取提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
        }
    }
 
    private void readStatus() {
        try {
            //获取提升机数据
            OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB82.4.0", (short) 10);
            if (result1.IsSuccess) {
                if (null == liftProtocol) {
                    liftProtocol = new LiftProtocol();
                    liftProtocol.setLiftNo(slave.getId());
                    liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
 
                    InnerLiftExtend innerLiftExtend = new InnerLiftExtend();
                    liftProtocol.setExtend(innerLiftExtend);
                }
 
                //----------读取提升机状态-----------
                //读取4.0-4.7数据
                boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result1.Content, 0, 1);
                //读取5.0-5.7数据
                boolean[] status2 = siemensS7Net.getByteTransform().TransBool(result1.Content, 1, 1);
                //模式
                liftProtocol.setModel(status1[0]);
                //忙闲
                liftProtocol.setRun(!status1[1]);
                //前超限
                liftProtocol.setFrontOverrun(status1[4]);
                //后超限
                liftProtocol.setBackOverrun(status1[5]);
                //左超限
                liftProtocol.setLeftOverrun(status1[6]);
                //右超限
                liftProtocol.setRightOverrun(status1[7]);
                //超高
                liftProtocol.setOverHeight(status2[0]);
                //超重
                liftProtocol.setOverWeight(status2[1]);
                //有托盘
                liftProtocol.setHasTray(status2[5]);
                //有小车
                liftProtocol.setHasCar(status2[6]);
                //设备故障
                liftProtocol.setErrorCode(status2[7]?"1":"0");
                //目的地址
                liftProtocol.setDistAddress(siemensS7Net.getByteTransform().TransInt16(result1.Content, 4));
                //已完成任务号
                liftProtocol.setCompleteTaskNo(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result1.Content, 6)));
                //当前楼层
                short lev = siemensS7Net.getByteTransform().TransInt16(result1.Content, 8);
                liftProtocol.setLev((int) lev);
 
                //************补充扩展字段*************
                InnerLiftExtend liftExtend = (InnerLiftExtend) liftProtocol.getExtend();
                //任务号
                liftExtend.setLiftTaskNo(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result1.Content, 2)));
                liftProtocol.setExtend(liftExtend);
 
                boolean ready = true;
                if (!liftProtocol.getModel() || liftProtocol.getRun()) {
                    ready = false;
                }
                liftProtocol.setReady(ready);//就绪状态
 
 
            }else {
                OutputQueue.LIFT.offer(MessageFormat.format("【{0}】{1}读取提升机状态信息失败", DateUtils.convert(new Date()), slave.getId()));
                throw new CoolException(MessageFormat.format( "读取提升机状态信息失败 ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort()));
            }
            Thread.sleep(200);
 
            //获取提升机站点数据
            OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB82.14.0", (short) (10 * liftStaProtocols.size()));
            if (result1.IsSuccess) {
                for (int i = 0; i < this.liftStaProtocols.size(); i++) {
                    LiftStaProtocol liftStaProtocol = liftStaProtocols.get(i);
                    int i1 = 0 + (i * 10);
                    int i2 = 1 + (i * 10);
                    //读取x4.0-x4.7数据
                    boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result2.Content, i1, 1);
                    //读取x5.0-x5.7数据
                    boolean[] status2 = siemensS7Net.getByteTransform().TransBool(result2.Content, i2, 1);
                    //模式
                    liftStaProtocol.setModel(status1[0]);
                    //忙闲
                    liftStaProtocol.setBusy(!status1[1]);
                    //有托盘
                    liftStaProtocol.setHasTray(status1[2]);
                    //前超限
                    liftStaProtocol.setFrontOverrun(status1[4]);
                    //后超限
                    liftStaProtocol.setBackOverrun(status1[5]);
                    //左超限
                    liftStaProtocol.setLeftOverrun(status1[6]);
                    //右超限
                    liftStaProtocol.setRightOverrun(status1[7]);
                    //超高
                    liftStaProtocol.setOverHeight(status2[0]);
                    //超重
                    liftStaProtocol.setOverWeight(status2[1]);
                    //有小车
                    liftStaProtocol.setHasCar(status2[6]);
                    //设备故障
                    liftStaProtocol.setDeviceError(status2[7]);
                    //任务号
                    liftStaProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result2.Content, 2));
                    //已完成任务号
                    liftStaProtocol.setCompleteTaskNo(siemensS7Net.getByteTransform().TransInt16(result2.Content, 6));
                }
            }
 
            if (System.currentTimeMillis() - liftProtocol.getDeviceDataLog() > 1000 * 5) {
                //采集时间超过5s,保存一次数据记录
                //保存数据记录
                DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
                DeviceDataLog deviceDataLog = new DeviceDataLog();
                deviceDataLog.setOriginData(Base64.getEncoder().encodeToString(result1.Content));
                deviceDataLog.setWcsData(JSON.toJSONString(liftProtocol));
                deviceDataLog.setType("lift");
                deviceDataLog.setDeviceNo(slave.getId());
                deviceDataLog.setCreateTime(new Date());
                deviceDataLogService.insert(deviceDataLog);
 
                //更新采集时间
                liftProtocol.setDeviceDataLog(System.currentTimeMillis());
            }
 
            //将提升机状态保存至数据库
            BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class);
            BasLift basLift = basLiftService.selectOne(new EntityWrapper<BasLift>()
                    .eq("lift_no", slave.getId()));
            if (basLift == null) {
                basLift = new BasLift();
                //提升机号
                basLift.setLiftNo(liftProtocol.getLiftNo());
                basLift.setStatus(1);
                basLiftService.insert(basLift);
            }
            //任务号
            basLift.setWrkNo(liftProtocol.getTaskNo());
            //修改时间
            basLift.setUpdateTime(new Date());
            //设备状态
            basLift.setDeviceStatus(JSON.toJSONString(liftProtocol));
            if (basLiftService.updateById(basLift)) {
                OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), liftProtocol.getLiftNo()));
            }
 
        } catch (Exception e) {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】读取提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
        }
    }
 
    @Override
    public LiftProtocol getStatus() {
        return getStatus(true);
    }
 
    @Override
    public LiftProtocol getStatus(boolean clone) {
        if (this.liftProtocol == null) {
            return null;
        }
        return clone ? this.liftProtocol.clone() : this.liftProtocol;
    }
 
    @Override
    public CommandResponse move(LiftCommand command) {
        return write(command);
    }
 
    @Override
    public CommandResponse palletInOut(LiftCommand command) {
        return write(command);
    }
 
    private CommandResponse write(LiftCommand command) {
        CommandResponse response = new CommandResponse(false);
        if (null == command) {
            News.error("提升机写入命令为空");
            response.setMessage("提升机写入命令为空");
            return response;
        }
 
        List<Short> shorts = JSON.parseArray(command.getBody(), Short.class);
        short[] array = new short[shorts.size()];//获取命令报文
        for (int i = 0; i < shorts.size(); i++) {
            array[i] = shorts.get(i);
        }
 
        if (command.getTaskNo() != null) {
            array[3] = command.getTaskNo().shortValue();
        }
 
        OperateResult result = siemensS7Net.Write("DB83.0", array);
        if (result != null && result.IsSuccess) {
            liftProtocol.setSendTime(System.currentTimeMillis());//指令下发时间
            News.info("提升机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            response.setMessage(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            response.setResult(true);
            return response;
        } else {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}],次数:{}", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            News.error("写入提升机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            response.setMessage(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}],次数:{}", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            return response;
        }
    }
 
    @Override
    public CommandResponse lock(LiftCommand command) {
        return new CommandResponse(true);
    }
 
    @Override
    public CommandResponse unlock(LiftCommand command) {
        return new CommandResponse(true);
    }
 
    @Override
    public CommandResponse reset(LiftCommand command) {
        return new CommandResponse(false);
    }
 
    @Override
    public boolean isIdle() {
        // 判断提升机是否自动、就绪、空闲
        if (this.liftProtocol.getModel()
                && this.liftProtocol.getTaskNo() == 0
                && !this.liftProtocol.getRun()
                && this.liftProtocol.getReady()
                && this.liftProtocol.getPakMk()
                && this.liftProtocol.getErrorCode().equals("0")
                && (this.liftProtocol.getProtocolStatusType().equals(LiftProtocolStatusType.IDLE)
                || this.liftProtocol.getProtocolStatusType().equals(LiftProtocolStatusType.WAITING))
        ) {
            return true;
        }
        return false;
    }
 
    @Override
    public boolean isDeviceIdle() {
        return isDeviceIdle(null);
    }
 
    @Override
    public boolean isDeviceIdle(ExecuteSupport support) {
        if (null != support) {
            Boolean judgement = support.judgement();
            if (judgement != null && !judgement) {
                return true;
            }
        }
 
        // 判断提升机是否自动、就绪、空闲
        if (this.liftProtocol.getModel()
                && !this.liftProtocol.getRun()
                && this.liftProtocol.getReady()
                && this.liftProtocol.getErrorCode().equals("0")
        ) {
            return true;
        }
        return false;
    }
 
    @Override
    public synchronized boolean setProtocolStatus(LiftProtocolStatusType status) {
        this.liftProtocol.setProtocolStatus(status);
        return true;
    }
 
    @Override
    public synchronized boolean setSyncTaskNo(Integer taskNo) {
        this.liftProtocol.setTaskNo(taskNo);
        return true;
    }
 
    @Override
    public boolean isLock(ExecuteSupport support) {
        if (support != null) {
            return support.judgement();
        }
        return true;
    }
 
    @Override
    public int generateDeviceTaskNo(int taskNo, ForkLiftTaskModeType type) {
        int deviceTaskNo = taskNo;
        try {
            CommonService commonService = SpringUtils.getBean(CommonService.class);
            deviceTaskNo = commonService.getWorkNo(8);
        } catch (Exception e) {
            return taskNo;
        }
        return deviceTaskNo;
    }
 
    @Override
    public String getLiftLocNo(int lev) {
        return Utils.getLocNo(slave.getRow(), slave.getBay(), lev);
    }
 
    @Override
    public String getLiftStandByLocNo(int lev, boolean in) {
        if (in) {
            return Utils.getLocNo(slave.getStandByInRow(), slave.getStandByInBay(), lev);
        }
        return Utils.getLocNo(slave.getStandByOutRow(), slave.getStandByOutBay(), lev);
    }
 
    @Override
    public List<NavigateNode> getLiftStaNodes(int lev) {
        List<NavigateNode> targetNodes = new ArrayList<>();
        List<String> list = liftNodeMap.get(lev);
        NavigateNode targetNode = NavigatePositionConvert.locNoToNode(list.get(0));//目标节点
        NavigateNode targetLastNode = NavigatePositionConvert.locNoToNode(list.get(1));//目标节点前一站
        targetNodes.add(targetNode);
        targetNodes.add(targetLastNode);
        return targetNodes;
    }
 
    @Override
    public Integer getLevToStaNo(int lev) {
        return liftLevMap.get(lev);
    }
 
    @Override
    public List<LiftCommand> getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode) {
        /**
         * 任务类型
         1=移托盘;升降机将源站台托盘移到目标站台
         2=换层,升降机移到目标层,等待
         3=入库托盘,升降机将源站台托盘移到目标层数;
         4=出库托盘,升降机将源站台托盘移到目标站台
         */
        short taskMode = 2;
 
        Integer sourceData = liftLevMap.get(sourceLev);
        Integer targetData = liftLevMap.get(targetLev);
 
        // 开始任务
        short[] array = new short[4];
        //任务类型
        array[0] = taskMode;
        //源站台编号
        array[1] = sourceData.shortValue();
        //目标站台编号
        array[2] = targetData.shortValue();
        //任务号
        array[3] = taskNo.shortValue();
 
        LiftCommand command = new LiftCommand();
        command.setLiftNo(slave.getId());
        command.setBody(JSON.toJSONString(array));
        command.setMode(mode.id);
        command.setOriginLev(sourceLev);
        command.setTargetLev(targetLev);
 
        ArrayList<LiftCommand> list = new ArrayList<>();
        list.add(command);
        return list;
    }
 
    @Override
    public List<LiftCommand> getMoveWithShuttleCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode) {
        /**
         * 任务类型
         1=移托盘;升降机将源站台托盘移到目标站台
         2=换层,升降机移到目标层,等待
         3=入库托盘,升降机将源站台托盘移到目标层数;
         4=出库托盘,升降机将源站台托盘移到目标站台
         5=车和托盘升降
         */
        short taskMode = 5;
 
        Integer sourceData = liftLevMap.get(sourceLev);
        Integer targetData = liftLevMap.get(targetLev);
 
        // 开始任务
        short[] array = new short[4];
        //任务类型
        array[0] = taskMode;
        //源站台编号
        array[1] = sourceData.shortValue();
        //目标站台编号
        array[2] = targetData.shortValue();
        //任务号
        array[3] = taskNo.shortValue();
 
        LiftCommand command = new LiftCommand();
        command.setLiftNo(slave.getId());
        command.setBody(JSON.toJSONString(array));
        command.setMode(mode.id);
        command.setOriginLev(sourceLev);
        command.setTargetLev(targetLev);
 
        ArrayList<LiftCommand> list = new ArrayList<>();
        list.add(command);
        return list;
    }
 
    @Override
    public List<LiftCommand> getPalletInCommand(Integer taskNo, Integer sourceLev, Integer targetLev) {
        /**
         * 任务类型
         1=移托盘;升降机将源站台托盘移到目标站台
         2=换层,升降机移到目标层,等待
         3=入库托盘,升降机将源站台托盘移到目标层数;
         4=出库托盘,升降机将源站台托盘移到目标站台
         */
        short taskMode = 3;
 
        // 开始任务
        short[] array = new short[4];
        //任务类型
        array[0] = taskMode;
        //源站台编号
        array[1] = sourceLev.shortValue();
        //目标站台编号
        array[2] = targetLev.shortValue();
        //任务号
        array[3] = taskNo.shortValue();
 
        LiftCommand command = new LiftCommand();
        command.setLiftNo(slave.getId());
        command.setBody(JSON.toJSONString(array));
        command.setMode(LiftCommandModeType.PALLET_IN.id);
        command.setOriginLev(sourceLev);
        command.setTargetLev(targetLev);
 
        ArrayList<LiftCommand> list = new ArrayList<>();
        list.add(command);
        return list;
    }
 
    @Override
    public List<LiftCommand> getPalletOutCommand(Integer taskNo, Integer sourceLev, Integer targetLev) {
        /**
         * 任务类型
         1=移托盘;升降机将源站台托盘移到目标站台
         2=换层,升降机移到目标层,等待
         3=入库托盘,升降机将源站台托盘移到目标层数;
         4=出库托盘,升降机将源站台托盘移到目标站台
         */
        short taskMode = 4;
 
        // 开始任务
        short[] array = new short[4];
        //任务类型
        array[0] = taskMode;
        //源站台编号
        array[1] = sourceLev.shortValue();
        //目标站台编号
        array[2] = targetLev.shortValue();
        //任务号
        array[3] = taskNo.shortValue();
 
        LiftCommand command = new LiftCommand();
        command.setLiftNo(slave.getId());
        command.setBody(JSON.toJSONString(array));
        command.setMode(LiftCommandModeType.PALLET_OUT.id);
        command.setOriginLev(sourceLev);
        command.setTargetLev(targetLev);
 
        ArrayList<LiftCommand> list = new ArrayList<>();
        list.add(command);
        return list;
    }
 
    @Override
    public List<LiftCommand> getLockCommand(Integer taskNo, Boolean lock) {
        return null;
    }
 
    @Override
    public List<LiftCommand> getShuttleSignalCommand(Integer taskNo, Boolean signal) {
        return null;
    }
 
    @Override
    public boolean connect() {
        boolean result = false;
        //-------------------------提升机连接方法------------------------//
        siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp());
        OperateResult connect = siemensS7Net.ConnectServer();
        if(connect.IsSuccess){
            result = true;
            OutputQueue.LIFT.offer(MessageFormat.format( "【{0}】提升机plc连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            log.info("提升机plc连接成功 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort());
        } else {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】提升机plc连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            log.error("提升机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort());
        }
        siemensS7Net.ConnectClose();
        //-------------------------提升机连接方法------------------------//
        return result;
    }
 
    @Override
    public void close() {
        siemensS7Net.ConnectClose();
    }
 
    /**
     * 扩展字段
     */
    @Data
    private class InnerLiftExtend {
 
        /**
         * 提升机内部工作号
         */
        private String liftTaskNo;
 
    }
 
}