多单位版国产化地质资料管理系统
zs
2026-02-04 fe02f176b512a9d6a4e12437d929e04e99bb7567
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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
package com.zbooksoft.gdmis.common;
 
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
 
public class ShelveOpForAndroid {
 
    public static String IMS_START_SYMBOL = "START";// 操作起始标识
    public static String IMS_OP_VERSION = "01";// 接口版本
    public static String IMS_OP_COMM_LEFTOPEN = "LEFTOPEN";// 操作命令-左开
    public static String IMS_OP_COMM_RIGHTOPEN = "RIGHTOPEN";// 操作命令-右开
    public static String IMS_OP_COMM_VENTILATION = "VENTILATION";// 操作命令-通风
    public static String IMS_OP_COMM_OPENSTATUS = "OPENSTATUS";// 查询命令-查询开架是否成功
    public static String IMS_OP_COMM_CLOSED = "CLOSED";// 操作命令-合拢
    public static String IMS_OP_COMM_LIGHT = "LIGHT";// 操作命令-亮灯,XY定位灯
    public static String IMS_OP_COMM_STOP = "STOP";// 操作命令-停止
    public static String IMS_END_SYMBOL = "END";// 操作结束标识
    public static String IMS_SEPARATE_SYMBOL = "*";// 操作结束标识
 
    private static int socketConnTimeout = 2000;// socket连接时间
    private static int socketSoTimeout = 2000;// 连接时长
 
    /*只用于八益样品间-密集架电源通电断电命令 on 2018.1.2 by chenb */
    //密集架通电
    public static byte[] IMS_OP_COMM_TD = {(byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x06, (byte) 0x01, (byte) 0x05,
            (byte) 0x00, (byte) 0x00, (byte) 0xff, (byte) 0x00};
    //密集架断电
    public static byte[] IMS_OP_COMM_DD = {(byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x06, (byte) 0x01, (byte) 0x05,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
 
 
    /**
     * @param ip         安卓屏IP
     * @param port       端口 10086
     * @param column     列号
     * @param actionType 动作
     * @return
     */
    public static int shelveOperate(String ip, int port, int column, String actionType) {
        if (ip != null && port != -1 && column != -1) {
            try {
                if (!"3".equals(actionType)) {
                    ShelveOpForAndroid.stop(ip, port);
                    try {
                        Thread.sleep(1500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                switch (actionType) {
                    case "3":// 停止
                        ShelveOpForAndroid.stop(ip, port);
                        return 1;
                    case "4":// 左移
                        ShelveOpForAndroid.rightOpen(ip, port, column);
                        return 1;
                    case "5":// 右移
                        ShelveOpForAndroid.leftOpen(ip, port, column);
                        return 1;
                    case "6":// 通风
                        ShelveOpForAndroid.vent(ip, port);
                        return 1;
                    case "7":// 合拢
                        ShelveOpForAndroid.close(ip, port);
                        return 1;
                    default:
                        return 1;
                }
            } catch (Exception e) {
                e.printStackTrace();
                return 1;
            }
        } else {
            return 1;
        }
    }
 
 
    /**
     * 密集架列左开
     *
     * @param ip      固定列ip
     * @param port    固定列端口
     * @param channel 列号
     */
    public static boolean leftOpen(String ip, int port, int channel) {
        System.out.println("leftopen");
        Socket socketForIms = new Socket();
        SocketAddress address = new InetSocketAddress(ip, port);
        OutputStream os = null;
        InputStream is = null;
        String str = "";
        try {
            try {
                socketForIms.connect(address, socketConnTimeout);
                socketForIms.setSoTimeout(socketSoTimeout);
                os = socketForIms.getOutputStream();
            } catch (Exception e) {
                //log.error("设备连接失败", e);
                e.printStackTrace();
                throw e;
                // return false;
            }
            StringBuffer comm = new StringBuffer();
            comm.append(IMS_START_SYMBOL);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_VERSION);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_COMM_LEFTOPEN);
            comm.append(IMS_SEPARATE_SYMBOL);
            String strCol = "01";
            if (channel < 1 || channel > 99) {
                //    log.error("密集架左开-列号不对");
                return false;
            } else if (channel < 10) {
                strCol = "0" + String.valueOf(channel);
            } else {
                strCol = String.valueOf(channel);
            }
            comm.append(strCol);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_END_SYMBOL);
            //log.info("密集架操作命令:" + comm.toString());
            os.write(ShelveOpForAndroid.stringToAscii(comm.toString()));
            os.flush();
            is = socketForIms.getInputStream();
            try {
                byte[] buf = new byte[1024];
                int numReadedBytes = is.read(buf, 0, buf.length);
                str = new String(buf, 0, numReadedBytes, StandardCharsets.US_ASCII);
            } catch (Exception e) {
                //log.error("获取密集架左开的返回值失败:", e1);
                e.printStackTrace();
            }
            //log.info("密集架左开成功");
        } catch (Exception e) {
            //log.error("密集架左开失败", e);
            e.printStackTrace();
            return false;
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (socketForIms != null) {
                try {
                    socketForIms.close();
                    socketForIms = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        //log.info("密集架左开返回值:" + str);
        return true;
    }
 
    /**
     * 密集架列右开
     *
     * @param ip      固定列ip
     * @param port    固定列端口
     * @param channel 列号
     * @throws
     */
    public static boolean rightOpen(String ip, int port, int channel) {
        Socket socketForIms = new Socket();
        SocketAddress address = new InetSocketAddress(ip, port);
        OutputStream os = null;
        InputStream is = null;
        String str = "";
        try {
            try {
                socketForIms.connect(address, socketConnTimeout);
                socketForIms.setSoTimeout(socketSoTimeout);
                os = socketForIms.getOutputStream();
            } catch (Exception e) {
                e.printStackTrace();
                throw e;
                // return false;
            }
            StringBuffer comm = new StringBuffer();
            comm.append(IMS_START_SYMBOL);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_VERSION);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_COMM_RIGHTOPEN);
            comm.append(IMS_SEPARATE_SYMBOL);
            String strCol = "01";
            if (channel < 1 || channel > 99) {
                //log.error("密集架右开-列号不对");
                return false;
            } else if (channel < 10) {
                strCol = "0" + String.valueOf(channel);
            } else {
                strCol = String.valueOf(channel);
            }
            comm.append(strCol);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_END_SYMBOL);
            //log.info("密集架操作命令:" + comm.toString());
            os.write(ShelveOpForAndroid.stringToAscii(comm.toString()));
            os.flush();
            is = socketForIms.getInputStream();
            try {
                byte[] buf = new byte[1024];
                int numReadedBytes = is.read(buf, 0, buf.length);
                str = new String(buf, 0, numReadedBytes, StandardCharsets.US_ASCII);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //log.info("密集架右开成功");
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (socketForIms != null) {
                try {
                    socketForIms.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        //log.info("密集架右开返回值:" + str);
        return true;
    }
 
    /**
     * 密集架通风
     *
     * @param ip   固定列ip
     * @param port 固定列端口
     */
    public static boolean vent(String ip, int port) {
        Socket socketForIms = new Socket();
        SocketAddress address = new InetSocketAddress(ip, port);
        OutputStream os = null;
        InputStream is = null;
        String str = "";
        try {
            try {
                socketForIms.connect(address, socketConnTimeout);
                socketForIms.setSoTimeout(socketSoTimeout);
                os = socketForIms.getOutputStream();
            } catch (Exception e) {
                e.printStackTrace();
                throw e;
                // return false;
            }
            StringBuffer comm = new StringBuffer();
            comm.append(IMS_START_SYMBOL);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_VERSION);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_COMM_VENTILATION);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append("00");
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_END_SYMBOL);
            //log.info("密集架操作命令:" + comm.toString());
            os.write(ShelveOpForAndroid.stringToAscii(comm.toString()));
            os.flush();
            is = socketForIms.getInputStream();
            try {
                byte[] buf = new byte[1024];
                int numReadedBytes = is.read(buf, 0, buf.length);
                str = new String(buf, 0, numReadedBytes, StandardCharsets.US_ASCII);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //log.info("密集架通风成功");
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (socketForIms != null) {
                try {
                    socketForIms.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        //log.info("密集架通风返回值:" + str);
        return true;
    }
 
    /**
     * 密集架开架状态查询
     *
     * @param ip
     * @param port
     * @return 返回 true 代表开架成功,反之开架中或者开架失败
     */
    public static boolean openstatus(String ip, int port) {
        Socket socketForIms = new Socket();
        SocketAddress address = new InetSocketAddress(ip, port);
        OutputStream os = null;
        InputStream is = null;
        String str = "";
        try {
            try {
                socketForIms.connect(address, socketConnTimeout);
                socketForIms.setSoTimeout(socketSoTimeout);
                os = socketForIms.getOutputStream();
            } catch (Exception e) {
                e.printStackTrace();
                //log.error("设备连接失败", e);
                throw e;
                // return false;
            }
            StringBuffer comm = new StringBuffer();
            comm.append(IMS_START_SYMBOL);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_VERSION);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_COMM_OPENSTATUS);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append("00");
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_END_SYMBOL);
            //log.info("密集架操作命令:" + comm.toString());
            os.write(ShelveOpForAndroid.stringToAscii(comm.toString()));
            os.flush();
            is = socketForIms.getInputStream();
            try {
                byte[] buf = new byte[1024];
                int numReadedBytes = is.read(buf, 0, buf.length);
                str = new String(buf, 0, numReadedBytes, StandardCharsets.US_ASCII);
            } catch (Exception e1) {
                //log.error("获取密集架开架是否成功的返回值失败:", e1);
                e1.printStackTrace();
            }
        } catch (Exception e) {
            //log.error("密集架开架状态查询失败", e);
            e.printStackTrace();
            return false;
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    //log.error("密集架开架状态接口OutputStream关闭失败", e);
                    e.printStackTrace();
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    //log.error("密集架开架状态接口InputStream关闭失败", e);
                    e.printStackTrace();
                }
            }
            if (socketForIms != null) {
                try {
                    socketForIms.close();
                } catch (IOException e) {
                    //log.error("密集架开架状态接口Socket关闭失败", e);
                    e.printStackTrace();
                }
            }
        }
        //log.info("密集架开架状态返回值:" + str);
        if ("ok".equals(str)) {
            return true;
        } else {
            return false;
        }
    }
 
    /**
     * 密集架合拢
     *
     * @param ip   固定列ip
     * @param port 固定列端口
     */
    public static boolean close(String ip, int port) {
        Socket socketForIms = new Socket();
        SocketAddress address = new InetSocketAddress(ip, port);
        OutputStream os = null;
        InputStream is = null;
        String str = "";
        try {
            try {
                socketForIms.connect(address, socketConnTimeout);
                socketForIms.setSoTimeout(socketSoTimeout);
                os = socketForIms.getOutputStream();
            } catch (Exception e) {
                e.printStackTrace();
                throw e;
                // return false;
            }
            StringBuffer comm = new StringBuffer();
            comm.append(IMS_START_SYMBOL);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_VERSION);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_COMM_CLOSED);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append("00");
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_END_SYMBOL);
            //log.info("密集架操作命令:" + comm.toString());
            os.write(ShelveOpForAndroid.stringToAscii(comm.toString()));
            os.flush();
            is = socketForIms.getInputStream();
            try {
                byte[] buf = new byte[1024];
                int numReadedBytes = is.read(buf, 0, buf.length);
                str = new String(buf, 0, numReadedBytes, StandardCharsets.US_ASCII);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //log.info("密集架合拢成功");
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (socketForIms != null) {
                try {
                    socketForIms.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        //log.info("密集架合拢返回值:" + str);
        return true;
    }
 
 
    /**
     * xy灯
     *
     * @param ip   安卓屏ip
     * @param port 安卓屏端口
     * @param col  列
     * @param face 面 0左面 1右面
     * @param jie  节
     * @param ceng 层
     * @param open 0关1开
     * @return
     * @throws IOException
     * @throws InterruptedException
     */
    public static boolean light(String ip, int port, int col, int face, int jie, int ceng, int open)
            throws IOException, InterruptedException {
        Socket socketForIms = new Socket();
        SocketAddress address = new InetSocketAddress(ip, port);
        OutputStream os = null;
        InputStream is = null;
        String str = "";
        try {
            try {
                socketForIms.connect(address, socketConnTimeout);
                socketForIms.setSoTimeout(socketSoTimeout);
                os = socketForIms.getOutputStream();
            } catch (Exception e) {
                e.printStackTrace();
                throw e;
                // return false;
            }
            StringBuffer comm = new StringBuffer();
            comm.append(IMS_START_SYMBOL);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_VERSION);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_COMM_LIGHT);
            comm.append(IMS_SEPARATE_SYMBOL);
            String strCol = "01";
            if (col < 1 || col > 99) {
                //log.error("密集架右开-列号不对");
                return false;
            } else if (col < 10) {
                strCol = "0" + String.valueOf(col);
            } else {
                strCol = String.valueOf(col);
            }
            comm.append(strCol);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append("0" + face);
            comm.append(IMS_SEPARATE_SYMBOL);
            String strjie = "01";
            if (jie < 1 || jie > 99) {
                return false;
            } else if (jie < 10) {
                strjie = "0" + String.valueOf(jie);
            } else {
                strjie = String.valueOf(jie);
            }
            comm.append(strjie);
            comm.append(IMS_SEPARATE_SYMBOL);
            String strceng = "01";
            if (ceng < 1 || ceng > 99) {
                return false;
            } else if (ceng < 10) {
                strceng = "0" + String.valueOf(ceng);
            } else {
                strceng = String.valueOf(ceng);
            }
            comm.append(strceng);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append("0" + open);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_END_SYMBOL);
            //log.info("密集架操作命令:" + comm.toString());
            System.out.println(comm.toString());
            os.write(ShelveOpForAndroid.stringToAscii(comm.toString()));
            os.flush();
            is = socketForIms.getInputStream();
            try {
                byte[] buf = new byte[1024];
                int numReadedBytes = is.read(buf, 0, buf.length);
                str = new String(buf, 0, numReadedBytes, StandardCharsets.US_ASCII);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //log.info("密集架右开成功");
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (socketForIms != null) {
                try {
                    socketForIms.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return true;
    }
 
 
    /**
     * 密集架停止
     *
     * @param ip   固定列ip
     * @param port 固定列端口
     */
    public static boolean stop(String ip, int port) {
        Socket socketForIms = new Socket();
        SocketAddress address = new InetSocketAddress(ip, port);
        OutputStream os = null;
        InputStream is = null;
        String str = "";
        try {
            try {
                socketForIms.connect(address, socketConnTimeout);
                socketForIms.setSoTimeout(socketSoTimeout);
                os = socketForIms.getOutputStream();
            } catch (Exception e) {
                e.printStackTrace();
                throw e;
                // return false;
            }
            StringBuffer comm = new StringBuffer();
            comm.append(IMS_START_SYMBOL);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_VERSION);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_OP_COMM_STOP);
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append("00");
            comm.append(IMS_SEPARATE_SYMBOL);
            comm.append(IMS_END_SYMBOL);
            //log.info("密集架操作命令:" + comm.toString());
            os.write(ShelveOpForAndroid.stringToAscii(comm.toString()));
            os.flush();
            is = socketForIms.getInputStream();
            try {
                byte[] buf = new byte[1024];
                int numReadedBytes = is.read(buf, 0, buf.length);
                str = new String(buf, 0, numReadedBytes, StandardCharsets.US_ASCII);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //    log.info("密集架停止成功");
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (socketForIms != null) {
                try {
                    socketForIms.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        //log.info("密集架停止返回值:" + str);
        return true;
    }
 
    public static byte[] stringToAscii(String value) {
        try {
            return value.getBytes("US-ASCII");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
 
    /**
     * 密集架通电
     *
     * @param ip   固定列ip
     * @param port 固定列端口
     */
    public static boolean openPws(String ip, int port) {
        Socket socketForIms = new Socket();
        SocketAddress address = new InetSocketAddress(ip, port);
        OutputStream os = null;
        InputStream is = null;
        String str = "";
        try {
            try {
                socketForIms.connect(address, socketConnTimeout);
                socketForIms.setSoTimeout(socketSoTimeout);
                os = socketForIms.getOutputStream();
            } catch (Exception e) {
                e.printStackTrace();
                throw e;
                // return false;
            }
            //log.info("密集架操作命令:" + IMS_OP_COMM_TD.toString());
            os.write(IMS_OP_COMM_TD);
            os.flush();
            is = socketForIms.getInputStream();
            try {
                byte[] buf = new byte[1024];
                int numReadedBytes = is.read(buf, 0, buf.length);
                str = new String(buf, 0, numReadedBytes, StandardCharsets.US_ASCII);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //log.info("密集架通电成功");
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (socketForIms != null) {
                try {
                    socketForIms.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        //log.info("密集架通电返回值:" + str);
        return true;
    }
 
    /**
     * 密集架通电
     *
     * @param ip   固定列ip
     * @param port 固定列端口
     */
    public static boolean closePws(String ip, int port) {
        Socket socketForIms = new Socket();
        SocketAddress address = new InetSocketAddress(ip, port);
        OutputStream os = null;
        InputStream is = null;
        String str = "";
        try {
            try {
                socketForIms.connect(address, socketConnTimeout);
                socketForIms.setSoTimeout(socketSoTimeout);
                os = socketForIms.getOutputStream();
            } catch (Exception e) {
                //log.error("设备连接失败", e);
                throw e;
                // return false;
            }
            //log.info("密集架操作命令:" + IMS_OP_COMM_TD.toString());
            os.write(IMS_OP_COMM_DD);
            os.flush();
            is = socketForIms.getInputStream();
            try {
                byte[] buf = new byte[1024];
                int numReadedBytes = is.read(buf, 0, buf.length);
                str = new String(buf, 0, numReadedBytes, StandardCharsets.US_ASCII);
            } catch (Exception e1) {
                //log.error("获取密集架断电的返回值失败:", e1);
            }
            //log.info("密集架断电成功");
        } catch (Exception e) {
            //log.error("密集架断电失败", e);
            return false;
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    //log.error("密集架断电接口OutputStream关闭失败", e);
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    //    log.error("密集架断电接口InputStream关闭失败", e);
                }
            }
            if (socketForIms != null) {
                try {
                    socketForIms.close();
                } catch (IOException e) {
                    //log.error("密集架断电接口Socket关闭失败", e);
                }
            }
        }
        //log.info("密集架断电返回值:" + str);
        return true;
    }
 
    /**
     * 根据档案id打开对应密集架
     * @param ip 固定列ip
     * @param archivesId 档案id
     * @param port 固定列端口
     *//*
    public static boolean openByArchivesId(String ip, int port,String colnum,Ams_archives doc) {
        // 先停止密集架
        stop(ip, port);
        try {
            Thread.sleep(1500);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (XUtil.isNotEmpty(colnum) &&doc!=null) {
                if ("0".equals(doc.store_lr)) {
                    System.out.println("left open");
                    //如果所在密集架在L面,左开
                    return leftOpen(ip, port, Integer.valueOf(colnum));
                }else {
                    //如果所在密集架在R面,右开
                    return rightOpen(ip, port, Integer.valueOf(colnum));
                }
        }else {
            return false;
        }
    }*/
 
    /**
     * @Title: main @Description: @param args @return void 返回类型 @throws
     */
    public static void main(String[] args) {
        try {
            ShelveOpForAndroid.light("127.0.0.1", 10086, 2, 1, 4, 2, 1);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}