自动化立体仓库 - WCS系统
#
mrzhssss
2022-09-22 110f3977b399dd117ce1af49ca792d602e2ba9a9
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
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using com.force.json;
using System.Net;
using System.Net.NetworkInformation;
using Oracle.ManagedDataAccess.Client;
 
namespace WCS
{
    public class Common
    {
        /// <summary>
        /// 系统路径
        /// </summary>
        public static string filepath = System.Reflection.Assembly.GetExecutingAssembly().Location;
        //public static string exepath = Application.ExecutablePath;
        //public static string path = filepath.Substring(0, filepath.LastIndexOf('\\'));
 
        /// <summary>
        /// 系统配置文件
        /// </summary>
        public static string sysinipath = filepath.Substring(0, filepath.LastIndexOf('\\')) + "\\System.ini";
        //public static string cmdinipath = filepath.Substring(0, filepath.LastIndexOf('\\')) + "\\Command.ini";
        //public static string inipath = filepath.Substring(0, filepath.LastIndexOf('\\')) + "\\labels\\";
        //public static string pbdpath = filepath.Substring(0, filepath.LastIndexOf('\\')) + "\\report.pbd";
 
        /// <summary>
        /// 公司名称
        /// </summary>
        public static string gs_companyName = "";
 
        /// <summary>
        /// 系统图片路径
        /// </summary>
        public static string picpath = filepath.Substring(0, filepath.LastIndexOf('\\')) + "\\image\\";
 
        /// <summary>
        /// 系统信号,弹出提示框后根据选择传值回主窗口,后期考虑窗口间传参
        /// </summary>
        public static bool sysinfo = false;
        //public static bool logout = false;
        //public static bool sameinfo = false;
 
        /// <summary>
        /// ASRS数据库连接字符串
        /// </summary>
        public static string sqlcon = "Initial Catalog=klsasrs2;Persist Security Info=True;User ID=sa;Password=sa@123;";
        //public static string sqlcon = "Initial Catalog=jsasrs;Persist Security Info=True;User ID=;Password=klsasrs@zy;";
 
        /// <summary>
        /// ERP数据库连接字符串
        /// </summary>
        public static string erpcon = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dm01db01-vip.dssyebs.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME = PROD)));User Id=HSTORE;Password=HSTORE;";
 
        /// <summary>
        /// 数据库服务器IP
        /// </summary>
        public static string serverIp = "127.0.0.1";
 
        /// <summary>
        /// WMS接口
        /// </summary>
        public static string HttpUrl = "";
 
        //public static string servername = ".";
        //public static string login = "asrs";
        //public static string psw = "asrs";
        //public static int crnwriteadd = 80;
        /// <summary>
        /// 定义FORM窗体f1
        /// </summary>
        public static Form f1 = null;
 
        /// <summary>
        /// 堆垛机数量
        /// </summary>
        public static int ci_crn_count = 3;
        /// <summary>
        /// 站点数量
        /// </summary>
        public static int ci_sta_count = 36;
        /// <summary>
        /// PLC数量
        /// </summary>
        public static int ci_plc_count = 1;
        /// <summary>
        /// 磅秤数量
        /// </summary>
        public static int ci_scale_count = 1;
        /// <summary>
        /// 条码扫描器数量
        /// </summary>
        public static int ci_barcode_count = 1;
        /// <summary>
        /// LED显示屏
        /// </summary>
        public static int ci_led_count = 5;
 
        /// <summary>
        /// 台车数量
        /// </summary>
        public static int ci_rgv_count = 0;
 
        /// <summary>
        /// WCS服务器Socket IP
        /// </summary>
        public static string gs_wcs_ip = "";
        /// <summary>
        /// WCS服务器Socket端口
        /// </summary>
        public static int gs_wcs_port = 10001;
 
        //public static int ci_plc_error_count = 7;// 91;
 
        /// <summary>
        /// 站点错误数
        /// </summary>
        public static int ci_plcerrcount = 100;
        public static string[] plcerr;// = new string[ci_plcerrcount];
        public static string[] gs_PlcErrDesc;// = new string[ci_plcerrcount];
        //public static int ci_plcerrrecord = 30;
        //public static int[] gi_plc_err = new int[ci_plcerrrecord];
        /// <summary>
        /// S7写数据到西门子PLC互锁标志,同一时间只允许一个写入
        /// </summary>
        public static bool writeFlag = true;
 
        /// <summary>
        /// 磅秤重量上限
        /// </summary>
        public static double ci_scale_maxwt = 1000;
        /// <summary>
        /// 磅秤重量下限
        /// </summary>
        public static double ci_scale_minwt = 30;
 
        /// <summary>
        /// 堆垛机入库站站点编号数组
        /// </summary>
        public static int[] crn_inStns = new int[8] { 104,106,117,120,124,131,133,136 };
 
        /// <summary>
        /// 堆垛机出库站站点编号数组
        /// </summary>
        public static int[] crn_outStns = new int[4] { 101,110, 113,127 };
 
        //public static bool[] plctag = new bool[2];
        //public static bool[] stasts = new bool[16];
        //public static bool[] stasts1 = new bool[4];
        //public static int[] gi_wrkno_pick = new int[5];
        //public static string[] gi_sts=new string[4];
 
        #region 常量定义区
        //堆垛机内部状态参数状态字
        public static long ch_crn_sdms = 1;         //手动模式
        public static long ch_crn_zdms = 2;         //自动模式
        public static long ch_crn_dnms = 4;         //电脑模式
        public static long ch_crn_sdz = 8;          //手动中
        public static long ch_crn_zdz = 16;         //自动中
        public static long ch_crn_dnmsz = 32;       //电脑模式中
        public static long ch_crn_jt = 64;          //急停
        public static long ch_crn_yc = 128;         //异常
        public static long ch_crn_dndmz = 256;      //电脑待命中
        public static long ch_crn_dnmljs = 512;     //电脑命令正确接收
        public static long ch_crn_rkz = 1024;       //入库中
        public static long ch_crn_ckz = 2048;       //出库中
        public static long ch_crn_kdkz = 4096;      //库对库中
        public static long ch_crn_zdzz = 8192;      //站对站中
        public static long ch_crn_yxz = 16384;      //移行中
        public static long ch_crn_dcqhjd = 32768;   //堆垛机取货阶段
 
        // {CRN STATUS2}
        public static long ch_crn_dcfhjd = 1;       //堆垛机放货阶段
        public static long ch_crn_dckx = 2;         //堆垛机空闲
        public static long ch_crn_zxyddw = 4;       //走行原点定位
        public static long ch_crn_sjyddw = 8;       //升降原点定位
        public static long ch_crn_zxzdw = 16;       //走行在定位
        public static long ch_crn_cyzzj = 32;       //叉牙在中间
        public static long ch_crn_cyzzd = 64;       //叉牙在左端
        public static long ch_crn_cyzyd = 128;      //叉牙在右端
        public static long ch_crn_sjsdw = 256;      //升降上定位
        public static long ch_crn_sjxdw = 512;      //升降下定位
        public static long ch_crn_plcdlbz = 1024;   //plc电力不足
        public static long ch_crn_sjtycyw = 2048;   //升降台有物        
 
        //public static bool[] gl_crn_status = new bool[ci_crn_count];
 
        //plc状态字
        public static int ch_d1 = 1;
        public static int ch_d2 = 2;
        public static int ch_d3 = 4;
        public static int ch_d4 = 8;
        public static int ch_d5 = 16;
        public static int ch_d6 = 32;
        public static int ch_d7 = 64;
        public static int ch_d8 = 128;
        public static int ch_d9 = 256;
        public static int ch_d10 = 512;
        public static long ch_d11 = 1024;
        public static long ch_d12 = 2048;
        public static long ch_d13 = 4096;
        public static long ch_d14 = 8192;
        public static long ch_d15 = 16384;
        public static long ch_d16 = 32768;
 
        //堆垛机工作模式
        /// <summary>
        /// 手动模式
        /// </summary>
        public static int ci_CRN_MANUAL = 1;
        /// <summary>
        /// 自动模式
        /// </summary>
        public static int ci_CRN_AUTO = 2;
        /// <summary>
        /// 连线模式
        /// </summary>
        public static int ci_CRN_ONLINE = 3;
 
        //堆垛机io状态
        public static int ci_CRN_LINK = 1;
        public static int ci_CRN_RESET = 2;
        public static int ci_CRN_CLEAR = 3;
        public static int ci_CRN_HOME = 4;
        public static int ci_CRN_STN = 5;
        public static int ci_CRN_SHELF = 6;
        public static int ci_CRN_INQUIRY = 7;
        public static int ci_CRN_STORE = 7;
        public static int ci_CRN_RETRIEVE = 8;
        public static int ci_CRN_MOVE = 10;
        public static int ci_CRN_STNTOSTN = 11;
        public static int ci_CRN_LOCTOLOC = 12;
 
        //堆垛机状态
        /// <summary>
        /// 初始化
        /// </summary>
        public static int ci_CRN_STS_INIT = -1;
        /// <summary>
        /// 空闲,无任务
        /// </summary>
        public static int ci_CRN_STS_IDLE = 0;
        /// <summary>
        /// 取货定位中
        /// </summary>
        public static int ci_CRN_STS_FETCH_MOVING = 1;
        /// <summary>
        /// 取货中
        /// </summary>
        public static int ci_CRN_STS_FETCH = 2;
        /// <summary>
        /// 取货完成,放货定位中
        /// </summary>
        public static int ci_CRN_STS_RELEASE_MOVING = 3;
        /// <summary>
        /// 放货中
        /// </summary>
        public static int ci_CRN_STS_RELEASE = 4;
        /// <summary>
        /// 回原点中
        /// </summary>
        public static int ci_CRN_STS_HP = 5;
        /// <summary>
        /// 去反原点中
        /// </summary>
        public static int ci_CRN_STS_OHP = 6;
        /// <summary>
        /// 库位移转中
        /// </summary>
        public static int ci_CRN_STS_LOC_MOVE = 7;
        /// <summary>
        /// 任务完成,等待WCS确认
        /// </summary>
        public static int ci_CRN_STS_TASK_FINISH = 90;
 
        //public static int ci_CRN_SETTING = 0;
        //public static int ci_CRN_STS_IDLE = 1;
        public static int ci_CRN_STS_STORE_MOVE = 2; //{ STORE COMMAND }
        public static int ci_CRN_STS_RETRIEVE_MOVE = 3; //{ RETRIEVE COMMAND }
        public static int ci_CRN_STS_MOVING = 4; //{ MOVE COMMAND }
        public static int ci_CRN_STS_STORE_OK = 5;
        public static int ci_CRN_STS_RETRIEVE_OK = 6;
        public static int ci_CRN_STS_MOVING_OK = 7;
        public static int ci_CRN_STS_ERROR = 8;
        public static int ci_CRN_STS_ERROR_IDLE = 9;
        //public static int ci_CRN_STS_OHP = 10;
        public static int ci_CRN_STS_STOP = 11;
        public static int ci_CRN_STS_STNCHG_MOVE = 12;
        public static int ci_CRN_STS_STNCHG_OK = 13;
        public static int ci_CRN_STS_LOCATION_MOVE = 14;
        public static int ci_CRN_STS_LOCATION_MOVE_OK = 16;
        public static int ci_CRN_STS_HP_POSITION = 15; ///20061007
 
        //工作状态
        public static int ci_WRK_STORE_SETDATA = 1;
        public static int ci_WRK_STORE_SETPLC = 2;
        public static int ci_WRK_STORE_SETCRN = 3;
        public static int ci_WRK_STORE_OK = 4;
        public static int ci_WRK_STORE_UPDDB = 5;
        public static int ci_WRK_STORE_exit = 6;
        public static int ci_WRK_STNMOVE_OK = 7;
 
        public static int ci_WRK_RETRIEVE_SETDATA = 11;
        public static int ci_WRK_RETRIEVE_SETCRN = 12;
        public static int ci_WRK_RETRIEVE_OK = 14;
        public static int ci_WRK_RETRIEVE_UPDDB = 15;
 
        public static int ci_plc_MAX = 10;          //PLC最大队列数
 
        //plc工作命令类型
        public static int ci_PLC_SETID = 1;
        public static int ci_PLC_SETDEST = 2;
        public static int ci_PLC_SETIDDEST = 3;
 
        //COMUCATION I/O BUFFER SIZE
        public static int ci_crn_MAXBUFSIZE = 4096;
        public static int ci_barcode_MAXBUFSIZE = 4096;
        //public static int ci_MAXINCOUNT = 35;
        //public static int ci_MAXOUTCOUNT = 50;
 
        /// <summary>
        /// CRANE SLEEP TIME
        /// </summary>
        public static int ci_CRNtimeInterval = 300;
        /// <summary>
        /// PLC SLEEP TIME
        /// </summary>
        public static int ci_PLCtimeInterval = 300;
        /// <summary>
        /// Barcode Scanner SLEEP TIME
        /// </summary>
        public static int ci_BarcodetimeInterval = 200;
        /// <summary>
        /// LED SLEEP TIME
        /// </summary>
        public static int ci_LedtimeInterval = 200;
 
        /// <summary>
        /// 系统运行中
        /// </summary>
        public static int ch_CMD_START = 1;
        /// <summary>
        /// 系统暂停中
        /// </summary>
        public static int ch_CMD_PAUSE = 10;
        /// <summary>
        /// 系统关闭中
        /// </summary>
        public static int ch_CMD_CLOSE = 100;
        #endregion
 
        //-------------------------------------------------------------变量定义---------------------------------------------------------------------------
        /// <summary>
        /// 下发堆垛机命令后,等待一个周期,再判断堆垛机是否空闲
        /// </summary>
        public static int gi_cycle_flag = 0;
 
        /// <summary>
        /// 堆垛机IP
        /// </summary>
        public static string[] gs_crn_ip = new string[ci_crn_count];
        /// <summary>
        /// PLC输送设备IP
        /// </summary>
        public static string[] gs_plc_ip = new string[ci_plc_count];
        /// <summary>
        /// 磅秤端口号,串口
        /// </summary>
        public static int[] gi_scale_port = new int[ci_scale_count];
        /// <summary>
        /// 磅秤设备IP
        /// </summary>
        public static string[] gs_scale_ip = new string[ci_scale_count];
        /// <summary>
        /// 条码设备串口端口
        /// </summary>
        public static int[] gs_barcode_port = new int[ci_barcode_count];
        /// <summary>
        /// 条码设备IP
        /// </summary>
        public static string[] gs_barcode_ip = new string[ci_barcode_count];
        /// <summary>
        /// 条码设备IP
        /// </summary>
        public static string[] gs_led_ip = new string[ci_led_count];
        /// <summary>
        /// 磅秤称重数据
        /// </summary>
        public static double[] gd_gross_wt = new double[ci_scale_count];
        /// <summary>
        /// 条码扫描数据
        /// </summary>
        public static string[] gs_barcode_data = new string[ci_barcode_count];
        /// <summary>
        /// LED待发送数据
        /// </summary>
        public static string[] gs_led_data = new string[ci_led_count];
        public static string[] gs_led_data_pre = new string[ci_led_count];
 
        ///// <summary>
        ///// LED页数
        ///// </summary>
        //public static int[] gi_led_Pages = new int[ci_led_count];
 
        /// <summary>
        /// LED页码
        /// </summary>
        public static int[] gi_led_PageNumber = new int[ci_led_count];
 
        /// <summary>
        /// LED显示当前页码
        /// </summary>
        public static int[] gi_led_CurPageNumber = new int[ci_led_count];
 
        /// <summary>
        /// LED显示循环次数
        /// </summary>
        public static int[] gi_led_Counts = new int[ci_led_count];
 
        ///// <summary>
        ///// LED显示效果
        ///// </summary>
        //public static int[] gi_led_ShowStyle = new int[ci_led_count];
 
        /// <summary>
        /// 台车位置
        /// </summary>
        public static int[] gi_RGVPos = new int[ci_rgv_count];
 
        /// <summary>
        /// 扫描超时时间判断
        /// </summary>
        public static double gd_scanTimeout = 4;
 
        ///// <summary>
        ///// PLC工作模式,0--入库,1--出库
        ///// </summary>
        //public static int gi_PLCModel = 0;
        ///// <summary>
        ///// PLC手工完成出库信号,工作档将12->14
        ///// </summary>
        //public static int gi_PLCClear = 0;
 
        /// <summary>
        /// 1号站条码扫描判断有没有扫到,计时判断
        /// </summary>
        public static DateTime barcodeTime = DateTime.Now;
        public static int barcodeFlag = 0;
        //public static string gs_barcode = "";
 
        #region LED参数
        /// <summary>
        /// 显示屏宽度
        /// </summary>
        public static int SCREEN_WIDTH = 96;
        /// <summary>
        /// 显示屏高度
        /// </summary>
        public static int SCREEN_HEIGHT = 48;
        public static int CONTROLLER_TYPE = 850;                        //控制器类型
        public static int SCREEN_TYPE = 1;                              //显示屏类型
        public static int SCREEN_PIXELMODE = 1;                         //点阵类型
        public static int SCREEN_DATADA = 0;                            //数据极性
        public static int SCREEN_DATAOE = 0;                            //OE极性
        public static int SCREEN_ROWORDER = 0;                          //行序模式
        public static int SCREEN_FREQPAR = 0;                           //扫描点频        
 
        public static string SCREEN_COMM = "COM1";                      //串口
        public static int SCREEN_BAUD = 57600;                          //串口波特率
        public static string SCREEN_STATUSFILE = "C:\\ScreenStatus.ini";  //显示屏状态保存文件
 
        public static int SCREEN_SENDMODE = 2;                          //通讯模式,0:串口 2:网络 4:wifi
        public const int SENDALLPROGRAM = 41456;                        //发送所有节目信息。
        /// <summary>
        /// 发送数据给控制卡时互斥作用,每次只能发送一条过去
        /// </summary>
        public static bool m_bSendBusy = false;
        #endregion
 
        //public static string barrec = "";        
        public static int[] areamode = new int[4];
        //public static bool insesheettag = false;
        //public static string[] gs_barcode_tmp = new string[5];
        public static string[] crncmd = new string[ci_crn_count];
        public static int[] crnwrkno = new int[ci_crn_count];
        //public static int[] pickquereseq = new int[12];
        //public static int bk = 1;
 
        public static Form form1 = null;
        public static Form form2 = null;
        //public static bool stnmove = true;
        //public static bool crnmove = true;
        //public static bool crnallow = true;
 
        public static int gi_Online_Flag = 10;
        public static bool[] gb_crn_status = new bool[ci_crn_count];
        //public static int gi_wrkfileh = 0;
        public static string[] gs_crnlastio = new string[ci_crn_count];
        public static int[] gi_crnstn = new int[ci_crn_count];
        public static string[] gs_crn_data_pre = new string[ci_crn_count];
        public static int[] gi_crn_wrkno = new int[ci_crn_count];
        public static string[] gs_crn_err_pre = new string[ci_crn_count];
        //public static int[] clrled = new int[10];
        public static int gi_buffer_count = 16;
        public static int gi_trolleypos_count = 2;
        //public static int[] stnbuffer = new int[gi_buffer_count];//
        public static int[] trolleypos = new int[gi_trolleypos_count];//2个,14,29
        //public static int[] ci_stnbuffer = new int[gi_buffer_count];
        public static int[] gi_stabuffer = new int[gi_buffer_count];
        //public static int[] gi_crn_actsts = new int[ci_crn_count];
        public static int[] gi_stn_iotype = new int[ci_sta_count];
 
        public static int[] g_ari_staion = new int[ci_sta_count];
        public static string[] g_ars_staion_name = new string[ci_sta_count];
        public static int[] g_ari_staion_plc_no = new int[ci_sta_count];
        public static Control[] g_ari_staion_Component_seq = new Control[ci_sta_count];
        public static int[] g_ari_station_idaddr = new int[ci_sta_count];
        public static int[] g_ari_station_stsaddr = new int[ci_sta_count];
        public static int[] g_ari_station_destaddr = new int[ci_sta_count];
        public static string[] gs_plc_data_pre = new string[ci_sta_count];
        public static int[] gi_crn_iotype = new int[ci_crn_count];
        public static int[] gi_loctype = new int[ci_sta_count];
 
        //堆垛机变量
        //public static string[,] crnstsvalue = new string[ci_crn_count, 33];
        public static string[] crnerrlist = new string[ci_crn_count];
        //public static string[] crnip = new string[ci_crn_count];
 
        public static int[] crn_i_crnno = new int[ci_crn_count];
        public static int[] crn_i_crn_sts = new int[ci_crn_count];
 
        /// <summary>
        /// 堆垛机命令
        /// </summary>
        public static string[] gs_crncmd = new string[ci_crn_count];
        public static string[] crn_s_commandstr = new string[ci_crn_count];
        public static int[] crn_i_kind = new int[ci_crn_count];
        public static int[] crn_i_Wrkno = new int[ci_crn_count];
        public static int[] crn_i_fstn = new int[ci_crn_count];
        public static int[] crn_i_tstn = new int[ci_crn_count];
        public static string[] crn_s_Flocno = new string[ci_crn_count];
        public static string[] crn_s_Tlocno = new string[ci_crn_count];
        public static int[] crn_i_Errcod = new int[ci_crn_count];
        public static bool[] gi_Yanshi_Flag = new bool[ci_crn_count];
        /// <summary>
        /// 是否在原点,1=原点
        /// </summary>
        public static int[] crn_i_onHP = new int[ci_crn_count];
 
        ////////////////////---------------------------堆垛机变量表--------------------------
        #region 堆垛机(CRN)状态信息
        /// <summary>
        /// 堆垛机工作模式,0 = 离线模式,1=手动模式中,2=自动模式中,3=电脑连线模式中
        /// </summary>
        public static int[] Mode = new int[ci_crn_count];
 
        /// <summary>
        /// 堆垛机当前任务号
        /// </summary>
        public static int[] TaskNo = new int[ci_crn_count];
 
        /// <summary>
        /// SRM工位1当前任务执行状态,0=空闲,1=取货定位中,2=取货中,3=取货完成,放货定位中,
        /// 4=放货中,5=回原点中,6=去反原点中,7=库位移转,90=任务完成,WCS未确认,99=报警
        /// </summary>
        public static int[] CrnState = new int[ci_crn_count];
 
        ///// <summary>
        ///// 堆垛机当前列号
        ///// </summary>
        //public static int[] CurBay = new int[ci_crn_count];
 
        ///// <summary>
        ///// 堆垛机当前层号
        ///// </summary>
        //public static int[] CurLev = new int[ci_crn_count];
 
        /// <summary>
        /// 堆垛机当前货叉位置,0=货叉原位,1=货叉在左侧,2=货叉在右侧
        /// </summary>
        public static int[] ForkPos = new int[ci_crn_count];
 
        /// <summary>
        /// 堆垛机当前载货台定位位置,1=下定位,2=上定位,0=不在定位
        /// </summary>
        public static int[] LiftPos = new int[ci_crn_count];
 
        /// <summary>
        /// 堆垛机走行定位位置,1=在定位,0=不在定位
        /// </summary>
        public static int[] WalkPos = new int[ci_crn_count];
 
        /// <summary>
        /// =1 堆垛机任务完成信号
        /// </summary>
        public static int[] TaskFinish = new int[ci_crn_count];
 
        /// <summary>
        /// SRM工位1任务完成处理标记,防止重复处理。默认为0,timer1根据F1TaskFinish处理工作档状态后赋值1
        /// 堆垛机线程中下发确认信息后,重置为0
        /// </summary>
        public static int[] TaskFlag = new int[ci_crn_count];
 
        /// <summary>
        /// =1 堆垛机载货台有货
        /// </summary>
        public static int[] Loaded = new int[ci_crn_count];
 
        /// <summary>
        /// 堆垛机异常码
        /// </summary>
        public static int[] AlarmCode = new int[ci_crn_count];
 
        /// <summary>
        /// 堆垛机走行速度(m/min)
        /// </summary>
        public static float[] WalkSpeed = new float[ci_crn_count];
 
        /// <summary>
        /// 堆垛机升降速度(m/min)
        /// </summary>
        public static float[] LiftSpeed = new float[ci_crn_count];
 
        /// <summary>
        /// 堆垛机叉牙速度(m/min)
        /// </summary>
        public static float[] ForkSpeed = new float[ci_crn_count];
 
        /// <summary>
        /// 堆垛机累计走行距离(km)
        /// </summary>
        public static float[] XDistance = new float[ci_crn_count];
 
        /// <summary>
        /// 堆垛机累计升降距离(km)
        /// </summary>
        public static float[] YDistance = new float[ci_crn_count];
 
        /// <summary>
        /// 堆垛机累计走行时长(H)
        /// </summary>
        public static float[] XDuration = new float[ci_crn_count];
 
        /// <summary>
        /// 堆垛机累计升降时长(H)
        /// </summary>
        public static float[] YDuration = new float[ci_crn_count];
 
        ///// <summary>
        ///// 1=SRM处于报警状态
        ///// </summary>
        //public static int[] AlarmStatus = new int[ci_crn_count];
 
 
        ///// <summary>
        ///// SRM工位1当前货叉位置,[1:左近,2:中位,3:右近,4:左远,5:右远]
        ///// </summary>
        //public static int[] F1PosZ = new int[ci_crn_count];
 
        ///// <summary>
        ///// SRM当前列坐标,单位mm
        ///// </summary>
        //public static double[] PosXmm = new double[ci_crn_count];
 
        ///// <summary>
        ///// SRM当前层坐标,单位mm
        ///// </summary>
        //public static double[] PosYmm = new double[ci_crn_count];
 
        ///// <summary>
        ///// SRM工位1当前货叉坐标,单位mm
        ///// </summary>
        //public static double[] F1PosZmm = new double[ci_crn_count];
 
        ///// <summary>
        ///// SRM工位2当前任务执行状态,0=位置,1=空闲,2=检查任务数据,3=定位到取货位,7=取货完成,
        ///// 8=等待调度柜允许,9=移动到放货位置,10=放货中,13=搬运完成,14=空载避让,15=检查任务数据
        ///// 20=检查源位置,21=检查目标位置,50=移动任务,98=任务完成,WCS未确认,99=报警
        ///// </summary>
        //public static int[] F2State = new int[ci_crn_count];
 
        #endregion
 
        #region 堆垛机状态字定义
        /// <summary>
        /// 手动模式
        /// </summary>
        public static bool[] crn_sdms = new bool[ci_crn_count];
        /// <summary>
        /// 自动模式
        /// </summary>
        public static bool[] crn_zdms = new bool[ci_crn_count];
        /// <summary>
        /// 电脑模式
        /// </summary>
        public static bool[] crn_dnms = new bool[ci_crn_count];
        /// <summary>
        /// 手动中
        /// </summary>
        public static bool[] crn_sdz = new bool[ci_crn_count];
        /// <summary>
        /// 自动中
        /// </summary>
        public static bool[] crn_zdz = new bool[ci_crn_count];
        /// <summary>
        /// 电脑模式中
        /// </summary>
        public static bool[] crn_dnmsz = new bool[ci_crn_count];
        /// <summary>
        /// 急停
        /// </summary>
        public static bool[] crn_jt = new bool[ci_crn_count];
        /// <summary>
        /// 异常
        /// </summary>
        public static bool[] crn_yc = new bool[ci_crn_count];
        /// <summary>
        /// 保留
        /// </summary>
        public static bool[] crn_dndmz = new bool[ci_crn_count];
        /// <summary>
        /// 任务完成
        /// </summary>
        public static bool[] crn_dnmljs = new bool[ci_crn_count];
        /// <summary>
        /// 入库中
        /// </summary>
        public static bool[] crn_rkz = new bool[ci_crn_count];
        /// <summary>
        /// 出库中
        /// </summary>
        public static bool[] crn_ckz = new bool[ci_crn_count];
        /// <summary>
        /// 库到库
        /// </summary>
        public static bool[] crn_kdkz = new bool[ci_crn_count];
        /// <summary>
        /// 站到站
        /// </summary>
        public static bool[] crn_zdzz = new bool[ci_crn_count];
        /// <summary>
        /// 去原点
        /// </summary>
        public static bool[] crn_yxz = new bool[ci_crn_count];
        /// <summary>
        /// 去反原点
        /// </summary>
        public static bool[] crn_dcqhjd = new bool[ci_crn_count];
        /// <summary>
        /// 放货阶段
        /// </summary>
        public static bool[] crn_dcfhjd = new bool[ci_crn_count];
        /// <summary>
        /// 吊车空闲
        /// </summary>
        public static bool[] crn_dckx = new bool[ci_crn_count];
        /// <summary>
        /// 走行原点定位
        /// </summary>
        public static bool[] crn_zxyddw = new bool[ci_crn_count];
        /// <summary>
        /// 升降原点定位
        /// </summary>
        public static bool[] crn_sjyddw = new bool[ci_crn_count];
        /// <summary>
        /// 走行在定位
        /// </summary>
        public static bool[] crn_zxzdw = new bool[ci_crn_count];
        /// <summary>
        /// 叉牙在中间
        /// </summary>
        public static bool[] crn_cyzzj = new bool[ci_crn_count];
        /// <summary>
        /// 叉牙在左端
        /// </summary>
        public static bool[] crn_cyzzd = new bool[ci_crn_count];
        /// <summary>
        /// 叉牙在右端
        /// </summary>
        public static bool[] crn_cyzyd = new bool[ci_crn_count];
        /// <summary>
        /// 升降上定位
        /// </summary>
        public static bool[] crn_sjsdw = new bool[ci_crn_count];
        /// <summary>
        /// 升降下定位
        /// </summary>
        public static bool[] crn_sjxdw = new bool[ci_crn_count];
        /// <summary>
        /// 保留
        /// </summary>
        public static bool[] crn_plcdlbz = new bool[ci_crn_count];
        /// <summary>
        /// 升降台有物
        /// </summary>
        public static bool[] crn_sjtycyw = new bool[ci_crn_count];
        /// <summary>
        /// 当前排数
        /// </summary>
        public static int[] crn_dqps = new int[ci_crn_count];
        /// <summary>
        /// 当前层数
        /// </summary>
        public static int[] crn_dqcs = new int[ci_crn_count];
        /// <summary>
        /// 走行镭射距离
        /// </summary>
        public static double[] crn_zxlsz = new double[ci_crn_count];
        /// <summary>
        /// 升降镭射距离
        /// </summary>
        public static double[] crn_sjlsz = new double[ci_crn_count];
        public static int[] crn_dnmlyc = new int[ci_crn_count];
        /// <summary>
        /// 设备异常码
        /// </summary>
        public static int[] crn_ycmm = new int[ci_crn_count];
        public static int[] crn_yczm = new int[ci_crn_count];
 
        //public static int[] crn_zxlsz1 = new int[ci_crn_count];
        //public static int[] crn_zxlsz2 = new int[ci_crn_count];
        //public static int[] crn_sjlsz1 = new int[ci_crn_count];
        //public static int[] crn_sjlsz2 = new int[ci_crn_count];
        #endregion
 
        public static string[] crncmdtext = new string[ci_crn_count];
        //定义plc变量
        //public struct sta
        //{
        public static int PlcMaxQuereCount = 10;//plc最大队列存储数量
        public static string[,] s_cmd = new string[4, PlcMaxQuereCount];
        //public static Queue<string> PlcAQueue = new Queue<string>();
        //public static Queue<string> PlcBQueue = new Queue<string>();
 
        public static string[,] plc_s_dev_no = new string[ci_plc_count, ci_sta_count];
        public static string[,] plc_s_type_mk = new string[ci_plc_count, ci_sta_count];
        public static string[,] plc_s_term_mk = new string[ci_plc_count, ci_sta_count];
        public static int[,] plc_i_status = new int[ci_plc_count, ci_sta_count];
        public static int[,] plc_i_plc_no = new int[ci_plc_count, ci_sta_count];
        public static int[,] plc_i_Wrk_no = new int[ci_plc_count, ci_sta_count];
        public static int[,] plc_i_ctn_type = new int[ci_plc_count, ci_sta_count];
        public static int[,] plc_i_pakmk = new int[ci_plc_count, ci_sta_count];
        public static int[,] plc_i_buff_count = new int[ci_plc_count, ci_sta_count];
        public static string[,] plc_s_stn_status = new string[ci_plc_count, ci_sta_count];
        public static string[,] plc_s_from_stn = new string[ci_plc_count, ci_sta_count];
        public static string[,] plc_s_next_stn = new string[ci_plc_count, ci_sta_count];
        public static string[,] plc_s_t_station = new string[ci_plc_count, ci_sta_count];
        public static string[,] plc_s_autoing = new string[ci_plc_count, ci_sta_count];
        public static string[,] plc_s_loading = new string[ci_plc_count, ci_sta_count];
        /// <summary>
        /// 可入
        /// </summary>
        public static string[,] plc_s_canining = new string[ci_plc_count, ci_sta_count];
        /// <summary>
        /// 可出
        /// </summary>
        public static string[,] plc_s_canouting = new string[ci_plc_count, ci_sta_count];
        /// <summary>
        /// 空板信号
        /// </summary>
        public static string[,] plc_s_inreq1 = new string[ci_plc_count, ci_sta_count];
        /// <summary>
        /// 满托信号
        /// </summary>
        public static string[,] plc_s_inreq2 = new string[ci_plc_count, ci_sta_count];
        /// <summary>
        /// 货物类型
        /// </summary>
        public static string[,] plc_s_loctype = new string[ci_plc_count, ci_sta_count];
        /// <summary>
        /// 报警
        /// </summary>
        public static string[,] plc_s_error = new string[ci_plc_count, ci_sta_count];
        public static string[,] plc_s_modeallow = new string[ci_plc_count, ci_sta_count];
 
        //public static string[] s_plc_err_count1 = new string[ci_plcerrcount];
        //public static string[] s_plc_err_count2 = new string[ci_plcerrcount];
 
        //public struct fieldds//字段描述
        //{
        //    public int index;
        //    public string dataname;
        //    public string datadesc;
        //}
 
 
        //public Common()
        //{
        //}
 
        //public static string Proc_GetNum(string str)
        //{
        //    string result = "";
        //    try
        //    {
        //        for (int i = 0; i < str.Length; i++)
        //        {
        //            if (str[i] == '0' || str[i] == '1' || str[i] == '2' || str[i] == '3' || str[i] == '4' || str[i] == '6' || str[i] == '7' || str[i] == '8' || str[i] == '9')
        //            {
        //                result = result.Trim() + str[i];
        //            }
        //        }
        //    }
        //    catch (Exception t)
        //    {
 
        //    }
        //    return result;
        //}
 
        /// <summary>
        /// 增加plc命令队列
        /// </summary>
        /// <param name="plcno">plc号</param>
        /// <param name="cmd">指令</param>
        public static void AddPlcQuereCmd(int plcno, string cmd)
        {
            if (cmd == "") { return; };
            for (int j = PlcMaxQuereCount - 1; j >= 0; j--)
            {
                if (s_cmd[plcno, j] == "" || s_cmd[plcno, j] == null)
                {
                    s_cmd[plcno, j] = cmd;
                    break;
                }
            }
            AdjPlcQuere(plcno);
        }
 
        /// <summary>
        /// 得到plc指令队列的数量
        /// </summary>
        /// <param name="plcno">plc号</param>
        /// <returns>队列的数量</returns>
        public static int GetPlcQuereCount(int plcno)
        {
            int count = 0;
            for (int i = 0; i < ci_plc_MAX; i++)
            {
                if (s_cmd[plcno, i] != "" && s_cmd[plcno, i] != null)
                {
                    count++;
                }
            }
            return count;
        }
 
        /// <summary>
        /// 从plc队列中取最先进的一笔指令
        /// </summary>
        /// <param name="plcno">plc号</param>
        /// <returns>对应最先进的指令</returns>
        public static string GetPlcQuereCmd(int plcno)
        {
            string cmd = "";
            for (int i = 0; i < PlcMaxQuereCount; i++)
            {
                if (s_cmd[plcno, i] != "" && s_cmd[plcno, i] != null)
                {
                    cmd = s_cmd[plcno, i];
                    s_cmd[plcno, i] = "";
                    break;
                }
            }
            AdjPlcQuere(plcno);
            return cmd;
        }
 
        /// <summary>
        /// 调整队列存储
        /// </summary>
        /// <param name="plcno">plc号</param>
        public static void AdjPlcQuere(int plcno)
        {
            string s_tmep1 = "", s_tmep2 = "";
            for (int j = PlcMaxQuereCount - 1; j >= 0; j--)
            {
                s_tmep1 = s_cmd[plcno, j];
                if (j > 0)
                {
                    s_tmep2 = s_cmd[plcno, j - 1];
                    if (s_tmep1 != "" && s_tmep2 == "")
                    {
                        s_cmd[plcno, j - 1] = s_tmep1;
                        s_cmd[plcno, j] = "";
                    }
                }
            }
        }
 
        /// <summary>
        /// 根据堆垛机状态值得到状态名称
        /// </summary>
        /// <param name="i_sts">堆垛机状态值</param>
        /// <returns>堆垛机状态</returns>
        public static string GetCrnStsName(int i_sts)
        {
            string crnstsname = "";
            switch (i_sts)
            {
                case -1:
                    crnstsname = "初始化";
                    break;
                case 0:
                    crnstsname = "空闲";
                    break;
                case 1:
                    crnstsname = "取货定位中";
                    break;
                case 2:
                    crnstsname = "取货中";
                    break;
                case 3:
                    crnstsname = "取货完成,放货定位中";
                    break;
                case 4:
                    crnstsname = "放货中";
                    break;
                case 5:
                    crnstsname = "回原点中";
                    break;
                case 6:
                    crnstsname = "去反原点中";
                    break;
                case 7:
                    crnstsname = "库位移转";
                    break;
                case 90:
                    crnstsname = "任务完成,WCS未确认";
                    break;
                case 99:
                    crnstsname = "报警";
                    break;
                default:
                    crnstsname = "未知";
                    break;
            }
            return crnstsname;
        }
 
        /// <summary>
        /// 站点初始化,PLC读写地址定义
        /// </summary>
        public static void InitSta()
        {
            int i;
            for (i = 1; i <= ci_sta_count; i++)
            {
                    //站点号
                    g_ari_staion[i - 1] = i + 100;
                    g_ars_staion_name[i - 1] = (i + 100).ToString();
                    g_ari_staion_plc_no[i - 1] = 1;
                    //工作号  目标库位  状态
                    g_ari_station_idaddr[i - 1] = (i - 1) * 4;    //工作号地址
                    g_ari_station_destaddr[i - 1] = (i - 1) * 4 + 2;      //目标站地址
                    g_ari_station_stsaddr[i - 1] = i + 149;    //状态位地址
 
                //else if (i > 5 && i <= 10)
                //{
                //    g_ari_staion[i - 1] = i + 194;
                //    g_ars_staion_name[i - 1] = (i + 194).ToString();
                //    g_ari_staion_plc_no[i - 1] = 1;
 
                //    g_ari_station_idaddr[i - 1] = (i - 1) * 4;
                //    g_ari_station_destaddr[i - 1] = (i - 1) * 4 + 2;
                //    g_ari_station_stsaddr[i - 1] = i + 59;
                //}
              
                //初始化站点中各个值的数据。
                plc_s_dev_no[g_ari_staion_plc_no[i - 1] - 1, i - 1] = g_ari_staion[i - 1].ToString();
                plc_s_autoing[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
                plc_s_loading[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
                plc_s_canining[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
                plc_s_canouting[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
                plc_s_inreq1[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
                plc_s_inreq2[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
                plc_s_loctype[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
                plc_s_error[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
                plc_i_buff_count[g_ari_staion_plc_no[i - 1] - 1, i - 1] = 0;
                plc_i_Wrk_no[g_ari_staion_plc_no[i - 1] - 1, i - 1] = 0;
                plc_s_stn_status[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
                plc_s_next_stn[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "0";
                plc_i_pakmk[g_ari_staion_plc_no[i - 1] - 1, i - 1] = 0;
 
                gi_stn_iotype[i - 1] = 0;   //初始化站点出入形态
            }
        }
 
        /// <summary>
        /// 堆垛机初始化
        /// </summary>
        public static void InitCrn()
        {
            int i;
            for (i = 1; i <= ci_crn_count; i++)
            {
                crn_i_crnno[i - 1] = i;
                //crn_i_crn_sts[i - 1] = ci_CRN_SETTING;
                gs_crncmd[i - 1] = "";
                crn_i_kind[i - 1] = 0;
                crn_i_Wrkno[i - 1] = 0;
                crn_i_fstn[i - 1] = 0;
                crn_i_tstn[i - 1] = 0;
                crn_s_Flocno[i - 1] = "";
                crn_s_Tlocno[i - 1] = "";
                //crn_i_Errcod[i - 1] = 0;
                crn_i_onHP[i - 1] = 0;
 
                gs_crnlastio[i - 1] = "I";
                gs_crncmd[i - 1] = "";
                crn_s_commandstr[i - 1] = "";
                gi_crn_iotype[i - 1] = 0;
 
                gb_crn_status[i - 1] = true;
 
                AlarmCode[i - 1] = 0;
                TaskFlag[i - 1] = 0;
                CrnState[i - 1] = -1;
            }
        }
 
        /// <summary>
        /// 条码、LED、磅秤数据初始化
        /// </summary>
        public static void InitDev()
        {
            int i;
            for (i = 0; i < ci_barcode_count; i++)
            {
                gs_barcode_data[i] = "";
            }
            for (i = 0; i < ci_led_count; i++)
            {
                gs_led_data[i] = "";
                gs_led_data_pre[i] = "";
                gi_led_PageNumber[i] = 1;
                //gi_led_Pages[i] = 1;
                gi_led_Counts[i] = 0;
                gi_led_CurPageNumber[i] = 1;
            }
            for (i = 0; i < ci_scale_count; i++)
            {
                gd_gross_wt[i] = 0;
            }
        }
 
        /// <summary>
        /// 得到站序号
        /// </summary>
        /// <param name="stn"></param>
        /// <returns></returns>
        public static int GetStnSeq(int stn)
        {
            int retval = 0;
            for (int i = 0; i <= ci_sta_count - 1; i++)
            {
                if (g_ari_staion[i] == stn)
                {
                    retval = i;
                    return retval;
                    //break;
                }
            }
            return 0;
        }
 
        ////得到区域模式地址
        //public static int GetBufAddrByStn(int stn)
        //{
        //    int addr = 0;
        //    switch (stn)
        //    {
        //        case 1:
        //            addr = 4107;
        //            break;
        //        case 2:
        //            addr = 4110;
        //            break;
        //        default:
        //            break;
        //    }
        //    return addr;
        //}
 
        //public static string InttoStringYN(int i, int j)
        //{
        //    if (i == 1)
        //    {
        //        if (j == 1)
        //        {
        //            return "出";
        //        }
        //        else
        //        {
        //            return "入";
        //        }
        //    }
        //    else
        //    {
        //        if (j == 1)
        //        {
        //            return "入";
        //        }
        //        else
        //        {
        //            return "出";
        //        }
        //    }
        //}        
 
        ///// <summary>
        ///// 十六进制转十进制
        ///// </summary>
        ///// <param name="s_data"></param>
        ///// <param name="i_len"></param>
        ///// <returns></returns>
        //public static int funi_htoi(string s_data, int i_len)
        //{
        //    int i_sum = 0, i_tmp = 0, x = 0;
        //    s_data = s_data.ToUpper();
        //    if (s_data == "" || s_data == null)
        //    {
        //        return 0;
        //    }
        //    for (x = 0; x < i_len; x++)
        //    {
 
        //        i_tmp = Convert.ToInt32(s_data[x]);
        //        if (i_tmp > 58) i_tmp = i_tmp - 7;
        //        i_sum = i_sum * 16 + i_tmp - 48;
        //    }
        //    return i_sum;
        //}
 
        ///// <summary>
        ///// 判断是否4位十六进制是否正确
        ///// </summary>
        ///// <param name="data"></param>
        ///// <returns></returns>
        //public static bool fun_chkhex(string data)
        //{
        //    string s_str = data.PadLeft(4, '0');
        //    int i_asc = 0, i_count = 0;
        //    for (int i = 0; i < s_str.Length; i++)
        //    {
        //        i_asc = Convert.ToInt32(s_str[i]);
        //        if ((i_asc > 47 && i_asc < 58) || (i_asc > 64 && i_asc < 71))
        //        {
 
        //        }
        //        else
        //        {
        //            i_count++;
        //        }
        //    }
        //    if (i_count > 0)
        //    {
        //        return false;
        //    }
        //    else
        //    {
        //        return true;
        //    }
        //}
 
        /// <summary>
        /// 十六进制转十进制
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static double fun_hextodec(string data)
        {
            string cptr = "";
            string s_str = data.Trim();
            int len = s_str.Length;
            double nsum = 0;
            int k = 1;
            for (int i = 0; i < len; i++)
            {
                cptr = s_str.Substring(len - i - 1, 1);
                if (cptr == "A")
                {
                    cptr = "10";
                }
                else if (cptr == "B")
                {
                    cptr = "11";
                }
                else if (cptr == "C")
                {
                    cptr = "12";
                }
                else if (cptr == "D")
                {
                    cptr = "13";
                }
                else if (cptr == "E")
                {
                    cptr = "14";
                }
                else if (cptr == "F")
                {
                    cptr = "15";
                }
                if (i == 0)
                {
                    k = 1;
                }
                else if (i == 1)
                {
                    k = 16;
                }
                else if (i == 2)
                {
                    k = 256;
                }
                else if (i == 3)
                {
                    k = 16 * 256;
                }
                else if (i == 4)
                {
                    k = 256 * 256;
                }
                else if (i == 5)
                {
                    k = 16 * 256 * 256;
                }
                else if (i == 6)
                {
                    k = 256 * 256 * 256;
                }
                else if (i == 7)
                {
                    k = 16 * 256 * 256 * 256;
                }
                nsum = nsum + Convert.ToInt32(cptr) * k;
            }
            return nsum;
        }
 
        ////得到十六进制
        //public static string fun_gethex(string s_data)
        //{
        //    string tohex = "";
        //    tohex = Convert.ToString(Convert.ToInt32(funi_htoi(s_data, 4)), 2);
        //    return tohex;
        //}
 
        ////得到位与运算结果,并判断是否相同
        //public static bool fun_ChkAndByte(string s_data, long t_data)
        //{
        //    long tohex1 = 0, tohex2 = 0, tohex3 = 0;
        //    tohex1 = Convert.ToInt64(Convert.ToString(Convert.ToInt64(funi_htoi(s_data, s_data.Length)), 2));
        //    tohex2 = t_data;// Convert.ToInt32(Convert.ToString(t_data, 2));
        //    tohex3 = tohex1 & tohex2;
        //    if (tohex3 == tohex2)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
 
        /// <summary>
        /// 得到位与运算结果,并判断是否相同
        /// </summary>
        /// <param name="i_data"></param>
        /// <param name="t_data"></param>
        /// <returns></returns>
        public static bool fun_ChkAndByte(long i_data, long t_data)
        {
            long tohex1 = 0, tohex2 = 0, tohex3 = 0;
            tohex1 = i_data;
            tohex2 = t_data;// Convert.ToInt32(Convert.ToString(t_data, 2));
            tohex3 = tohex1 & tohex2;
            if (tohex3 == tohex2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
        /// <summary>
        /// 生成工作号
        /// </summary>
        /// <param name="wrkmk"></param>
        /// <returns></returns>
        public static int GetWrkno(int wrkmk)
        {
            int wrkno = 0, li_s_no = 0, li_e_no = 0;
            SqlConnection sqlcn = new SqlConnection(sqlcon);
            sqlcn.Open();
            SqlDataAdapter sqlda = new SqlDataAdapter("select wrk_no,s_no,e_no from asr_wrk_lastno where wrk_mk=" + wrkmk + "", sqlcn);
            DataSet ds = new DataSet();
            sqlda.Fill(ds);
            DataView dv = new DataView(ds.Tables[0]);
            sqlcn.Close();
            foreach (System.Data.DataRowView drow in dv)
            {
                wrkno = Convert.ToInt32(drow[0].ToString().Trim());
                li_s_no = Convert.ToInt32(drow[1].ToString().Trim());
                li_e_no = Convert.ToInt32(drow[2].ToString().Trim());
            }
            if (wrkno >= li_e_no)
            {
                wrkno = li_s_no;
            }
            else
            {
                wrkno++;
            }
 
            SqlConnection sqlcon1 = new SqlConnection(sqlcon);
            sqlcon1.Open();
            SqlTransaction sqlts = sqlcon1.BeginTransaction();
            string sql = "update asr_wrk_lastno set wrk_no=" + wrkno + " where wrk_mk=" + wrkmk + "";
            SqlCommand sqlcom1 = new SqlCommand(sql, sqlcon1);
            sqlcom1.Transaction = sqlts;
            try
            {
                sqlcom1.ExecuteNonQuery();
                sqlts.Commit();
            }
            catch (SqlException r)
            {
                //MessageBox.Show("更新[asr_wrk_lastno]错误!", "错误");
                sqlts.Rollback();
                wrkno = 0;
            }
            finally
            {
                sqlcom1.Dispose();
                sqlcon1.Dispose();
                sqlcon1.Close();
            }
            return wrkno;
        }
 
        /// <summary>
        /// 生成库位号
        /// </summary>
        /// <param name="type">入库类型</param>
        /// <param name="loc_type">高低库位</param>
        /// <param name="crn_no">堆垛机号</param>
        /// <param name="stano">入库站号</param>
        /// <param name="stnType">入库方向,1为东侧1列起数,2为西侧最大列起数</param>
        /// <returns></returns>
        public static string GetLocNo(int type, int loc_type, int crn_no, int stano, int stnType)
        {
            int e_staNo = 0;
            string locno = "";
            int li_crnrow = 0, li_crn = 0, li_cnt = 0, li_max_cnt = 0, i = 0, n = 0, li_min = 0, li_max = 0, li_max_1 = 0, li_crn_qty = 0, crnsts = 0;
            string orderBy = "lev1,bay1 asc";
            if (stnType == 1)    //东侧
            {
                orderBy = "lev1,bay1 asc";
            }
            else if (stnType == 2)  //西侧
            {
                orderBy = "lev1 asc,bay1 desc";
            }
            //DataView dv = ExecAsrsSelect("select current_row,s_row,e_row,crn_qty from asr_row_lastno where whs_type=" + whs_type);
            DataView dv = ExecAsrsSelect("select current_row,s_row,e_row,crn_qty from asr_row_lastno ");
            foreach (DataRowView drv in dv)
            {
                li_crnrow = Convert.ToInt32(drv[0].ToString());
                li_min = Convert.ToInt32(drv[1].ToString());
                li_max = Convert.ToInt32(drv[2].ToString());
                li_crn_qty = Convert.ToInt32(drv[3].ToString());
            }
            li_max_1 = li_max - 1;
            i = 1;
            do
            {
                if (li_crnrow == li_max)
                {
                    li_crnrow = li_min;
                }
                else if (li_crnrow == li_max_1)
                {
                    li_crnrow = li_min + 1;
                }
                else
                {
                    li_crnrow = li_crnrow + 2;
                }
                li_crn = (li_crnrow + 1) / 2;
 
                if (ChkCrnEnable(li_crn, "I") == "Y")
                {
                    e_staNo = getIoStaNo(type, li_crn, stano);
                    if (e_staNo == 0)
                    {
                        continue;
                    }
                    //if (type == 10)
                    //{
                    //    locno = getEmptyLocation(li_crnrow, loc_type, orderBy);
                    //}
 
                    if (locno == "")
                    {
                        string sql = "";
                        //if (type == 10)
                        //{
                        sql = "select top 1 loc_no from asr_loc_mast where row1=" + li_crnrow + " and loc_sts='O' order by " + orderBy;
                        //}
                        //else
                        //{
                        //    sql = "select top 1 loc_no from asr_loc_mast where row1=" + li_crnrow + " and loc_sts='O' order by " + orderBy;
                        //}
                        SqlConnection sqlconn = new SqlConnection(sqlcon);
                        sqlconn.Open();
                        SqlDataAdapter sqlap = new SqlDataAdapter(sql, sqlconn);
                        DataSet ds = new DataSet();
                        sqlap.Fill(ds);
                        DataView dv1 = new DataView(ds.Tables[0]);
                        sqlap.Dispose();
                        sqlconn.Dispose();
                        //sqlconn.Close();
                        foreach (DataRowView drv in dv1)
                        {
                            locno = drv[0].ToString();
                            break;
                        }
                    }
                }
 
                //if (locno != "" && int.Parse(locno.Substring(0, 2)) < 3 && (stano == 1304 || stano == 1205))
                //{//1204站无法入库1号堆垛机
                //    locno = "";
                //}
                //if (crn_no > 0 && crn_no != li_crn)
                //{//先入品分配新库位,必须同一台堆垛机
                //    locno = "";
                //}
                if (Common.AlarmCode[li_crn - 1] > 0 || Common.Mode[li_crn - 1] != 3)
                { //堆垛机异常或者非自动,寻找下一个库位
                    locno = "";
                }
 
                //int seqno = Common.GetStnSeq(e_staNo);
                //int plcno = stnType - 1;
                //string s_loading = Common.plc_s_loading[plcno, seqno];
                //if (s_loading == "Y")
                //{//堆垛机入库站点有物,寻找下一个
                //    locno = "";
                //}
 
                i++;
                if (i > li_crn_qty * 2)
                {
                    break;
                }
            } while (locno == "");
 
            if (locno != "")
            {
                SqlConnection sqlconn = new SqlConnection(sqlcon);
                sqlconn.Open();
                SqlTransaction sqltrans = sqlconn.BeginTransaction();
                string sql = "update dbo.asr_row_lastno set current_row='" + li_crnrow + "',modi_time='" + DateTime.Now.ToString() + "' ";
                SqlCommand sqlcmd = new SqlCommand(sql, sqlconn);
                sqlcmd.Transaction = sqltrans;
                try
                {
                    sqlcmd.ExecuteNonQuery();
                    sqltrans.Commit();
                }
                catch (SqlException r)
                {
                    //MessageBox.Show("更新[asr_row_lastno]错误!", "错误");
                    sqltrans.Rollback();
                    sqlcmd.Dispose();
                    sqlconn.Dispose();
                    locno = "";
                }
            }
            return locno;
        }
 
        /// <summary>
        /// 根据作业类型得到站点编号
        /// </summary>
        /// <param name="type">入库类型</param>
        /// <param name="crnno">堆垛机号</param>
        /// <param name="stnno">站点号</param>
        /// <returns></returns>
        public static int getIoStaNo(int type, int crnno, int stnno)
        {
            int e_staNo = 0;
            try
            {
                string sql = "select crn_stn from asr_sta_desc ";
                sql += " where type_no=" + type + " and stn_no=" + stnno + " and crn_no=" + crnno;
                DataView dv_crn_stn = Common.ExecAsrsSelect(sql);
                if (dv_crn_stn != null || dv_crn_stn.Count > 0)
                {
                    foreach (DataRowView drow in dv_crn_stn)
                    {
                        e_staNo = int.Parse(drow[0].ToString());
                    }
                }
            }
            catch (Exception)
            {
            }
            return e_staNo;
        }
 
        /// <summary>
        /// 判断堆垛机是否可用
        /// </summary>
        /// <param name="crn"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string ChkCrnEnable(int crnno, string type)
        {
            DataView dv = null;
            string ls_in = "N", ls_ou = "N";
            dv = ExecAsrsSelect("select in_enable,out_enable from asr_bas_crnp where crn_no=" + crnno);
            foreach (DataRowView drv in dv)
            {
                ls_in = drv[0].ToString();
                ls_ou = drv[1].ToString();
            }
            if (type == "I")
            {
                return ls_in;
            }
            else if (type == "O")
            {
                return ls_ou;
            }
            else
            {
                return "N";
            }
        }
 
        //public static string GetRow(string row)
        //{
        //    if (row == "01")
        //    {
        //        return "01";
        //    }
        //    else if (row == "02")
        //    {
        //        return "02";
        //    }
        //    //else if (row == "03")
        //    //{
        //    //    return "01";
        //    //}
        //    //else if (row == "04")
        //    //{
        //    //    return "02";
        //    //}
        //    //else if (row == "05")
        //    //{
        //    //    return "01";
        //    //}
        //    //else if (row == "06")
        //    //{
        //    //    return "02";
        //    //}
        //    else
        //    {
        //        return "";
        //    }
        //}
 
        /// <summary>
        /// 根据堆垛机异常码得到异常描述
        /// </summary>
        /// <param name="error_code"></param>
        /// <returns></returns>
        public static string GetErr(int error_code)
        {
            string result = "";
            switch (error_code)
            {
                case 1:
                    result = "左超限";
                    break;
                case 2:
                    result = "右超限";
                    break;
                case 3:
                    result = "前超限";
                    break;
                case 4:
                    result = "后超限";
                    break;
                case 5:
                    result = "高超限";
                    break;
                case 6:
                    result = "取货载货台有货";
                    break;
                case 7:
                    result = "放货载货台无货";
                    break;
                case 8:
                    result = "取货左货格无货";
                    break;
                case 9:
                    result = "取货右货格无货";
                    break;
                case 10:
                    result = "放货左一有货";
                    break;
                case 11:
                    result = "放货右一有货";
                    break;
                case 12:
                    result = "取左二货格无货";
                    break;
                case 13:
                    result = "取右二货格无货";
                    break;
                case 14:
                    result = "放货左二货格有货";
                    break;
                case 15:
                    result = "放货右二货格有货";
                    break;
                case 16:
                    result = "左二取货左一有货";
                    break;
                case 17:
                    result = "右二取货右一有货";
                    break;
                case 18:
                    result = "左取货失败";
                    break;
                case 19:
                    result = "右取货失败";
                    break;
                case 20:
                    result = "左放货失败";
                    break;
                case 21:
                    result = "右放货失败";
                    break;
                case 22:
                    result = "货叉运行超时";
                    break;
                case 23:
                    result = "货叉断路器跳闸";
                    break;
                case 24:
                    result = "货叉变频器报警";
                    break;
                case 25:
                    result = "货叉编码器故障";
                    break;
                case 26:
                    result = "货叉伸叉故障";
                    break;
                case 27:
                    result = "层运行货叉不在中位";
                    break;
                case 28:
                    result = "列运行货叉不在中位";
                    break;
                case 29:
                    result = "货叉中位开关故障";
                    break;
                case 30:
                    result = "货叉变频器通讯故障";
                    break;
                case 31:
                    result = "货叉编码器通讯故障";
                    break;
                case 32:
                    result = "伸叉超出左极限";
                    break;
                case 33:
                    result = "伸叉超出右极限";
                    break;
                case 34:
                    result = "入左二货格货时左一货格有货";
                    break;
                case 35:
                    result = "入右二货格货时右一货格有货";
                    break;
                case 36:
                    result = "货叉右侧回中停止位置错误";
                    break;
                case 37:
                    result = "货叉左侧回中停止位置错误";
                    break;
                case 38:
                    result = "货叉左侧极限停止位置错误";
                    break;
                case 39:
                    result = "货叉右侧极限停止位置错误";
                    break;
                case 40:
                    result = "面板急停";
                    break;
                case 41:
                    result = "远程急停";
                    break;
                case 42:
                    result = "主接触器控制回路故障";
                    break;
                case 43:
                    result = "超重保护";
                    break;
                case 44:
                    result = "松绳保护";
                    break;
                case 45:
                    result = "限速保护";
                    break;
                case 46:
                    result = "层停止位置错误";
                    break;
                case 47:
                    result = "列停止位置错误";
                    break;
                case 48:
                    result = "列停止位置错误";
                    break;
                case 49:
                    result = "接收列超限";
                    break;
                case 50:
                    result = "接收层超限";
                    break;
                case 51:
                    result = "接收层超限";
                    break;
                case 52:
                    result = "行走后退极限";
                    break;
                case 53:
                    result = "提升上极限";
                    break;
                case 54:
                    result = "提升下极限";
                    break;
                case 55:
                    result = "行走运行超时";
                    break;
                case 56:
                    result = "提升运行超时";
                     break;
                      case 57:
                     result = "行走断路器跳闸";
                     break;
                      case 58:
                     result = "提升断路器跳闸";
                     break;
                      case 59:
                     result = "行走变频器故障";
                     break;
                      case 60:
                     result = "提升变频器故障";
                     break;
                      case 61:
                     result = "行走测距/条码故障";
                     break;
                      case 62:
                     result = "提升测距/条码故障";
                     break;
                      case 63:
                     result = "行走测距/条码被挡";
                     break;
                      case 64:
                     result = "提升测距/条码被挡";
                     break;
                      case 65:
                     result = "上升减速光电故障";
                     break;
                      case 66:
                     result = "下降减速光电故障";
                     break;
                      case 67:
                     result = "提升原点光电故障";
                     break;
                      case 68:
                     result = "行走前减速光电故障";
                     break;
                      case 69:
                     result = "行走后减速光电故障";
                     break;
                      case 70:
                     result = "行走原点光电故障";
                     break;
                      case 71:
                     result = "与输送机通讯故障";
                     break;
                      case 72:
                     result = "升降超出最小层";
                     break;
                      case 73:
                     result = "升降超出最大层";
                     break;
                      case 74:
                     result = "行走超出最小列";
                     break;
                      case 75:
                     result = "行走超出最大列";
                     break;
                      case 76:
                     result = "接收排错误";
                     break;
                      case 77:
                     result = "起始站货格被禁用";
                     break;
                      case 78:
                     result = "目的站货格被禁用";
                     break;
                      case 79:
                     result = "行走抱闸故障";
                     break;
                      case 80:
                     result = "提升抱闸故障";
                     break;
                      case 81:
                     result = "安全门打开故障";
                     break;
                default:
                    result = "";
                    break;
            }
            return result;
        }
 
        ////判断数字是否合法
        //public static bool ChkFloat(string str)
        //{
        //    try
        //    {
        //        float f = (float)Convert.ToDouble(str);
        //        return true;
        //    }
        //    catch (Exception e)
        //    {
        //        return false;
        //    }
        //}
        ////判断整数是否合法
        //public static bool ChkInt(string str)
        //{
        //    try
        //    {
        //        int f = Convert.ToInt32(str);
        //        return true;
        //    }
        //    catch (Exception e)
        //    {
        //        return false;
        //    }
        //}
        ////得到地址
        //public static string GetAddr(int li)
        //{
        //    string addr = "";
        //    try
        //    {
        //        switch (li)
        //        {
        //            case 0:
        //                return addr = "1030";
        //            case 1:
        //                return addr = "1032";
        //            case 2:
        //                return addr = "1034";
        //            case 3:
        //                return addr = "1036";
        //            case 4:
        //                return addr = "1038";
        //            case 5:
        //                return addr = "1040";
        //            case 6:
        //                return addr = "1042";
        //            default:
        //                return addr = "";
 
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        return addr = "";
        //    }
        //}
 
        /// <summary>
        /// 查询erp数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataView ExecErpSelect(string sql)
        {
            try
            {
                OracleConnection sqlerp = new OracleConnection(erpcon);
                sqlerp.Open();
                OracleDataAdapter odasrs = new OracleDataAdapter(sql, sqlerp);
                DataSet dserp = new DataSet();
                odasrs.Fill(dserp);
                DataView dverp = new DataView(dserp.Tables[0]);
                odasrs.Dispose();
                sqlerp.Dispose();
                sqlerp.Close();
                return dverp;
            }
            catch (SqlException em)
            {
                return null;
            }
        }
 
        /// <summary>
        /// 执行ERP数据更新sql语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static bool ExecERPModify(string sql)
        {
            bool result = false;
            try
            {
                OracleConnection sqlconn = new OracleConnection(erpcon);
                sqlconn.Open();
                OracleTransaction sqltrans = sqlconn.BeginTransaction();
                OracleCommand sqlcmd = new OracleCommand();
                //SqlCommand sqlcmd = new SqlCommand(sql, sqlconn);
                //sqlcmd.Transaction = sqltrans;
                string[] arraySql = sql.Split(';');
                try
                {
                    for (int i = 0; i < arraySql.Length; i++)
                    {
                        if (arraySql[i] != "")
                        {
                            sqlcmd.CommandText = arraySql[i];
                            sqlcmd.Connection = sqlconn;
                            sqlcmd.Transaction = sqltrans;
                            sqlcmd.ExecuteNonQuery();
                        }
                    }
                    sqltrans.Commit();
                    result = true;
                }
                catch (SqlException t)
                {
                    sqltrans.Rollback();
                    result = false;
 
                }
                finally
                {
                    sqlcmd.Dispose();
                    sqltrans.Dispose();
                    sqlconn.Dispose();
                    //sqlconn.Close();
                }
            }
            catch (Exception r)
            {
                return false;
            }
            return result;
        }
 
        /////-------------------------------从asrs数据库中执行查询功能返回数据集----------------
        public static DataView ExecAsrsSelect(string sql)
        {
            try
            {
                SqlConnection sqlasrs = new SqlConnection(sqlcon);
                sqlasrs.Open();
                SqlDataAdapter odasrs = new SqlDataAdapter(sql, sqlasrs);
                DataSet dsasrs = new DataSet();
                odasrs.Fill(dsasrs);
                DataView dvasrs = new DataView(dsasrs.Tables[0]);
                odasrs.Dispose();
                sqlasrs.Dispose();
                sqlasrs.Close();
                return dvasrs;
            }
            catch (SqlException em)
            {
                return null;
            }
        }
 
        public static DataView ExecAsrsSelect(string sql, out string err)
        {
            err = null;
            try
            {
                SqlConnection sqlasrs = new SqlConnection(sqlcon);
                sqlasrs.Open();
                SqlDataAdapter odasrs = new SqlDataAdapter(sql, sqlasrs);
                DataSet dsasrs = new DataSet();
                odasrs.Fill(dsasrs);
                DataView dvasrs = new DataView(dsasrs.Tables[0]);
                odasrs.Dispose();
                sqlasrs.Dispose();
                sqlasrs.Close();
                return dvasrs;
            }
            catch (SqlException em)
            {
                err = "查询sql语句失败:" + em.Message;
                //MessageBox.Show("查询sql语句失败:" + em.Message + "\r\n" + sql);
                return null;
            }
        }
        /////-------------------------------从asrs数据库中执行查询功能返回数据量----------------
        public static int ExecAsrsSelect1(string sql)
        {
            int li_count1 = 0;
            SqlConnection sqlasrs0 = new SqlConnection(sqlcon);
            sqlasrs0.Open();
            SqlCommand ocasrs = new SqlCommand(sql, sqlasrs0);
            li_count1 = Convert.ToInt32(ocasrs.ExecuteScalar());
            sqlasrs0.Dispose();
            ocasrs.Dispose();
            sqlasrs0.Close();
 
            return li_count1;
        }
        /////-------------------------------从asrs数据库中执行异动功能(提交)----------------
        /// <summary>
        /// 执行sql更新语句(insert、delete、update)
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static bool ExecAsrsModify(string sql)
        {
            bool result = false;
            try
            {
                SqlConnection sqlconn = new SqlConnection(sqlcon);
                sqlconn.Open();
                SqlTransaction sqltrans = sqlconn.BeginTransaction();
                SqlCommand sqlcmd = new SqlCommand();
                //SqlCommand sqlcmd = new SqlCommand(sql, sqlconn);
                //sqlcmd.Transaction = sqltrans;
                string[] arraySql = sql.Split(';');
                try
                {
                    for (int i = 0; i < arraySql.Length; i++)
                    {
                        if (arraySql[i] != "")
                        {
                            sqlcmd.CommandText = arraySql[i];
                            sqlcmd.Connection = sqlconn;
                            sqlcmd.Transaction = sqltrans;
                            sqlcmd.ExecuteNonQuery();
                        }
                    }
                    sqltrans.Commit();
                    result = true;
                }
                catch (SqlException em)
                {
                    WriteLogFile("WcsError", "Common/ExecAsrsModify--执行SQL语句发生异常:" + em.Message + "\r\n" + sql);
                    sqltrans.Rollback();
                    result = false;
 
                }
                finally
                {
                    sqlcmd.Dispose();
                    sqltrans.Dispose();
                    sqlconn.Dispose();
                    //sqlconn.Close();
                }
            }
            catch (Exception r)
            {
                return false;
            }
            return result;
        }
        ///////-------------------------------从asrs数据库中执行异动功能(未提交)----------------
        //public static bool ExecAsrsModify1(string sql)
        //{
        //    bool result = false;
        //    SqlConnection sqlasrs1 = new SqlConnection(sqlcon);
        //    sqlasrs1.Open();
        //    SqlTransaction otasrs = sqlasrs1.BeginTransaction();
        //    SqlCommand ocom = new SqlCommand(sql, sqlasrs1);
        //    ocom.Transaction = otasrs;
        //    try
        //    {
        //        ocom.ExecuteNonQuery();
        //        //otasrs.Commit();
        //        result = true;
        //    }
        //    catch (SqlException t)
        //    {
        //        otasrs.Rollback();
        //        result = false;
 
        //    }
        //    finally
        //    {
        //        ocom.Dispose();
        //        otasrs.Dispose();
        //        sqlasrs1.Dispose();
        //        sqlasrs1.Close();
        //    }
        //    return result;
        //}
        ///////-------------------------------从asrs数据库中执行异动功能(两个表),同步执行----------------
        //public static bool ExecAsrsModifyByMD(string sql, string sql1)
        //{
        //    bool result = false;
        //    SqlConnection sqlasrs1 = new SqlConnection(sqlcon);
        //    sqlasrs1.Open();
        //    SqlTransaction otasrs = sqlasrs1.BeginTransaction();
        //    SqlCommand ocom = new SqlCommand(sql, sqlasrs1);
        //    SqlCommand ocom1 = new SqlCommand(sql1, sqlasrs1);
        //    ocom.Transaction = otasrs;
        //    ocom1.Transaction = otasrs;
        //    try
        //    {
        //        ocom.ExecuteNonQuery();
        //        ocom1.ExecuteNonQuery();
        //        otasrs.Commit();
        //        result = true;
        //    }
        //    catch (SqlException t)
        //    {
        //        otasrs.Rollback();
        //        result = false;
 
        //    }
        //    finally
        //    {
        //        ocom.Dispose();
        //        otasrs.Dispose();
        //        sqlasrs1.Dispose();
        //        sqlasrs1.Close();
        //    }
        //    return result;
        //}
        ///////-------------------------------从asrs数据库中执行异动功能(4个表),同步执行----------------
        //public static bool ExecAsrsModifyByMD(string sql, string sql1, string sql2, string sql3)
        //{
        //    bool result = false;
        //    SqlConnection sqlasrs1 = new SqlConnection(sqlcon);
        //    sqlasrs1.Open();
        //    SqlTransaction otasrs = sqlasrs1.BeginTransaction();
        //    SqlCommand ocom = new SqlCommand(sql, sqlasrs1);
        //    SqlCommand ocom1 = new SqlCommand(sql1, sqlasrs1);
        //    SqlCommand ocom2 = new SqlCommand(sql2, sqlasrs1);
        //    SqlCommand ocom3 = new SqlCommand(sql3, sqlasrs1);
        //    ocom.Transaction = otasrs;
        //    ocom1.Transaction = otasrs;
        //    ocom2.Transaction = otasrs;
        //    ocom3.Transaction = otasrs;
        //    try
        //    {
        //        ocom.ExecuteNonQuery();
        //        ocom1.ExecuteNonQuery();
        //        ocom2.ExecuteNonQuery();
        //        ocom3.ExecuteNonQuery();
        //        otasrs.Commit();
        //        result = true;
        //    }
        //    catch (SqlException t)
        //    {
        //        otasrs.Rollback();
        //        result = false;
 
        //    }
        //    finally
        //    {
        //        ocom.Dispose();
        //        otasrs.Dispose();
        //        sqlasrs1.Dispose();
        //        sqlasrs1.Close();
        //    }
        //    return result;
        //}
        /////-------------------------------从asrs数据库中执行异动功能(5个表),同步执行----------------
        public static bool ExecAsrsModifyByMD(string sql, string sql1, string sql2, string sql3, string sql4)
        {
            bool result = false;
            SqlConnection sqlasrs1 = new SqlConnection(sqlcon);
            sqlasrs1.Open();
            SqlTransaction otasrs = sqlasrs1.BeginTransaction();
            SqlCommand ocom = new SqlCommand(sql, sqlasrs1);
            SqlCommand ocom1 = new SqlCommand(sql1, sqlasrs1);
            SqlCommand ocom2 = new SqlCommand(sql2, sqlasrs1);
            SqlCommand ocom3 = new SqlCommand(sql3, sqlasrs1);
            SqlCommand ocom4 = new SqlCommand(sql4, sqlasrs1);
            ocom.Transaction = otasrs;
            ocom1.Transaction = otasrs;
            ocom2.Transaction = otasrs;
            ocom3.Transaction = otasrs;
            ocom4.Transaction = otasrs;
            try
            {
                ocom.ExecuteNonQuery();
                ocom1.ExecuteNonQuery();
                ocom2.ExecuteNonQuery();
                ocom3.ExecuteNonQuery();
                ocom4.ExecuteNonQuery();
                otasrs.Commit();
                result = true;
            }
            catch (SqlException t)
            {
                otasrs.Rollback();
                result = false;
 
            }
            finally
            {
                ocom.Dispose();
                otasrs.Dispose();
                sqlasrs1.Dispose();
                sqlasrs1.Close();
            }
            return result;
        }
        ///////-------------------------------从ASRS数据库中执行查询功能返回数据量----------------
        //public static int ExecASRSSelect1(string sql)
        //{
        //    int li_count1 = 0;
        //    SqlConnection sqlasrs = new SqlConnection(sqlcon);
        //    sqlasrs.Open();
        //    SqlCommand ocerp = new SqlCommand(sql, sqlasrs);
        //    li_count1 = Convert.ToInt32(ocerp.ExecuteScalar());
        //    ocerp.Dispose();
        //    sqlasrs.Dispose();
        //    sqlasrs.Close();
        //    return li_count1;
        //}
 
        /// <summary>
        /// 根据库位状态代号返回库位状态名称
        /// </summary>
        /// <param name="locsts"></param>
        /// <returns></returns>
        public static string getlocsts(string locsts)
        {
            string locstsname = "";
            switch (locsts)
            {
                case "O":
                    locstsname = "O-空库位";
                    break;
                case "F":
                    locstsname = "F-在库";
                    break;
                case "S":
                    locstsname = "S-入库预约中";
                    break;
                case "R":
                    locstsname = "R-出库预约中";
                    break;
                case "P":
                    locstsname = "P-拣料/并板/盘点出库预约中";
                    break;
                case "L":
                    locstsname = "L-拣料库位空载中";
                    break;
                case "M":
                    locstsname = "M-拣料库位满载中";
                    break;
                case "Q":
                    locstsname = "Q-拣料/并板/盘点再入库预约中";
                    break;
                case "X":
                    locstsname = "X-禁用";
                    break;
                case "D":
                    locstsname = "D-空栈板";
                    break;
                default:
                    locstsname = "O-空库位";
                    break;
            }
            return locstsname;
        }
 
        /// <summary>
        /// 根据工作状态代号得到工作状态名称
        /// </summary>
        /// <param name="sts"></param>
        /// <returns></returns>
        public static string Getwrksts(string sts)
        {
            string wrkstsname = "";
            switch (sts)
            {
                case "1":
                    wrkstsname = "1.生成入库ID";
                    break;
                case "2":
                    wrkstsname = "2.设备上移动";
                    break;
                case "3":
                    wrkstsname = "3.堆垛机入库中";
                    break;
                case "4":
                    wrkstsname = "4.堆垛机入库完成";
                    break;
                case "5":
                    wrkstsname = "5.入库回报完成";
                    break;
                //case "6":
                //    wrkstsname = "6.2号堆垛机站到站中";
                //    break;
                //case "7":
                //    return "7.5站到6站移动中";
                //    break;
                //case "8":
                //    return "8.7站到8站移动中";
                //    break;
                //case "9":
                //    return "9.2号堆垛机站到站完成";
                //    break;
                case "11":
                    wrkstsname = "11.生成出库ID";
                    break;
                case "12":
                    wrkstsname = "12.堆垛机出库中";
                    break;
                case "13":
                    wrkstsname = "13.空出库";
                    break;
                case "14":
                    wrkstsname = "14.堆垛机出库完成";
                    break;
                case "15":
                    wrkstsname = "15.出库回报完成";
                    break;
                case "16":
                    wrkstsname = "16.LED指令完成";
                    break;
            }
            return wrkstsname;
        }
 
        /// <summary>
        /// 根据IO类型代号得到IO名称
        /// </summary>
        /// <param name="sts"></param>
        /// <returns></returns>
        public static string Getiotype(string sts)
        {
            string iotypename = "";
            switch (sts)
            {
                case "1":
                    iotypename = "1.入库";
                    break;
                case "6":
                    iotypename = "6.退库";
                    break;
                case "10":
                    iotypename = "10.空桶入库";
                    break;
                case "110":
                    iotypename = "110.空桶出库";
                    break;
                case "101":
                    iotypename = "101.全板出库";
                    break;
                case "103":
                    iotypename = "103.拣料出库";
                    break;
                case "104":
                    iotypename = "104.并板出库";
                    break;
                case "107":
                    iotypename = "107.盘点出库";
                    break;
                case "53":
                    iotypename = "53.拣料再入库";
                    break;
                case "57":
                    iotypename = "57.盘点再入库";
                    break;
                case "54":
                    iotypename = "54.并板再入库";
                    break;
            }
            return iotypename;
        }
 
        /// <summary>
        /// 根据拣料站得到再入库堆垛机站点
        /// </summary>
        /// <param name="crn"></param>
        /// <param name="stn"></param>
        /// <returns></returns>
        public static int GetRestoreStnByPick(int crn, int stn)
        {
            int stnno = 0;
            switch (crn)
            {
                case 1:
                    stnno = 106;
                    break;
                case 2:
                    stnno = 120;
                    break;
 
                case 3:
                    stnno = 133;
                    break;
            
 
 
 
 
            }
            return stnno;
        }
 
        /// <summary>
        /// 根据站号得到对应吊车站序号
        /// </summary>
        /// <param name="stn"></param>
        /// <returns></returns>
        public static int GetCrnStnSeq(int stn)
        {
            int crnstn = 0;
            switch (stn)
            {
                case 100:
                    crnstn = 1;
                    break;
                case 200:
                    crnstn = 2;
                    break;
                case 104:
                    crnstn = 1;
                    break;
                case 204:
                    crnstn = 2;
                    break;
                default:
                    crnstn = 0;
                    break;
            }
            return crnstn;
        }
 
        /// <summary>
        /// 根据堆垛机入库站号得到站点编号
        /// </summary>
        /// <param name="crn">堆垛机号</param>
        /// <param name="seq">堆垛机站点编号</param>
        /// <returns>输送机站点编号</returns>
        public static int GetStnSeqNo(int crn, int seq)
        {
            int stnno = 0;
            switch (crn)
            {
                case 1:
                    switch (seq)
                    {
                        case 1:
                            stnno = 104;
                            break;
                        //case 2:
                        //    stnno = 104;
                        //    break;
                    }
                    break;
                case 2:
                    switch (seq)
                    {
                        case 1:
                            stnno = 204;
                            break;
                    }
                    break;
                default:
                    stnno = seq;
                    break;
            }
            return stnno;
        }
 
        /// <summary>
        /// 判断字符串是否数字
        /// </summary>
        /// <param name="ls_string"></param>
        /// <returns></returns>
        public static bool ChkStrtoInt(string ls_string)
        {
            bool result = false;
            int i = 0, i_len = 0;
            i_len = ls_string.Length;
            for (i = 0; i < i_len; i++)
            {
                if (ls_string[i] >= '0' && ls_string[i] <= '9')
                // if (Convert.ToInt32(ls_string[i].ToString()) >= 0 && Convert.ToInt32(ls_string[i].ToString()) <= 9)
                {
                    result = true;
                }
                else
                {
                    result = false;
                    break;
                }
            }
            return result;
 
        }
 
        /// <summary>
        /// 写日志文件
        /// </summary>
        /// <param name="Memo">写入内容</param>
        public static void WriteLogFile(string fileName, string Memo)
        {
            DateTime dt = DateTime.Now;
            string FileName = Application.StartupPath + "\\log\\" + fileName + string.Format("{0:yyyyMMdd}", dt) + ".log";
            try
            {
                if (!Directory.Exists(Application.StartupPath + "\\log"))
                {
                    Directory.CreateDirectory(Application.StartupPath + "\\log");
                }
 
                StreamWriter fs1 = new StreamWriter(FileName, true);//创建写入文件    
                //StreamWriter sw = new StreamWriter(fs1);
                fs1.WriteLine("【" + DateTime.Now.ToString() + "】" + Memo);//开始写入值                   
 
                //sw.Close();
                fs1.Close();
            }
            catch (Exception)
            {
            }
        }
 
        /// <summary>
        /// DateTime时间格式转换为Unix时间戳格式
        /// </summary>
        /// <param name=”time”></param>
        /// <returns></returns>
        public static int ConvertDateTimeInt(System.DateTime time)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
            return (int)(time - startTime).TotalSeconds;
 
        }
 
        ///// <summary>
        ///// 判断工作档中入库资料数量
        ///// </summary>
        ///// <returns></returns>
        //public static int GetWrkInCount()
        //{
        //    int result = 1000;
        //    try
        //    {
        //        string sql = "select * from asr_wrk_mast where wrk_sts>0 and wrk_sts<5";
        //        result = Common.ExecAsrsSelect1(sql);                
        //    }
        //    catch (Exception)
        //    {
        //    }
        //    return result;
        //}
 
        ///// <summary>
        ///// 判断工作档中出库资料数量
        ///// </summary>
        ///// <returns></returns>
        //public static int GetWrkOutCount()
        //{
        //    int result = 1000;
        //    try
        //    {
        //        string sql = "select * from asr_wrk_mast where wrk_sts>11 and wrk_sts<15";
        //        result = Common.ExecAsrsSelect1(sql);
        //    }
        //    catch (Exception)
        //    {
        //    }
        //    return result;
        //}
 
        ///// <summary>
        ///// 判断工作档中资料数量
        ///// </summary>
        ///// <returns></returns>
        //public static int GetWrkCount()
        //{
        //    int result = 1000;
        //    try
        //    {
        //        string sql = "select * from asr_wrk_mast where wrk_sts<15";
        //        result = Common.ExecAsrsSelect1(sql);
        //    }
        //    catch (Exception)
        //    {
        //    }
        //    return result;
        //}
 
        ///// <summary>
        ///// 判断库存档中库存资料是否存在
        ///// </summary>
        ///// <returns></returns>
        //public static int GetStkCount(string boxId)
        //{
        //    int result = 1000;
        //    try
        //    {
        //        string sql = "select * from asr_loc_mast where boxId='" + boxId + "'";
        //        result = Common.ExecAsrsSelect1(sql);
        //    }
        //    catch (Exception)
        //    {
        //    }
        //    return result;
        //}
 
        /// <summary>
        /// 检查数据库连接是否正常
        /// </summary>
        /// <returns></returns>
        public static bool CheckDbConnect()
        {
            bool result = false;
            SqlConnection conn = new SqlConnection(Common.sqlcon);
            try
            {
                if (conn.State == ConnectionState.Closed)
                    conn.Open();
                else if (conn.State == ConnectionState.Broken)
                {
                    conn.Close();
                    conn.Open();
                }
                result = true;
            }
            catch (Exception em)
            {
                //MessageBox.Show("数据库连接失败。" + em.Message, "错误");
            }
            finally
            {
                conn.Close();
            }
            return result;
        }
 
        /// <summary>
        /// 检测端口是否占用
        /// </summary>
        /// <param name="port"></param>
        /// <returns></returns>
        public static bool PortInUse(int port)
        {
            bool inUse = false;
 
            IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
            IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
 
            foreach (IPEndPoint endPoint in ipEndPoints)
            {
                if (endPoint.Port == port)
                {
                    inUse = true;
                    break;
                }
            }
            return inUse;
        }
 
        /// <summary>
        /// 根据输送机站点获取对应库位号
        /// </summary>
        /// <param name="i_stn">堆垛机状态值</param>
        /// <returns>库位号</returns>
        public static string GetLocByStn(int i_stn)
        {
            string loc_no = "0000000";
            switch (i_stn)
            {
                case 100:
                    loc_no = "0200101";
                    break;
                case 104:
                    loc_no = "0300101";
                    break;
                case 200:
                    loc_no = "0400101";
                    break;
                case 204:
                    loc_no = "0500101";
                    break;
                default:
                    loc_no = "0000000";
                    break;
            }
            return loc_no;
        }
 
        /// <summary>
        /// 根据库位号获取对应输送机站点编号
        /// </summary>
        /// <param name="i_stn">堆垛机状态值</param>
        /// <returns>库位号</returns>
        public static int GetStnByLoc(string loc_no)
        {
            int i_stn = 0;
            switch (loc_no)
            {
                case "0200101":
                    i_stn = 100;
                    break;
                case "0300101":
                    i_stn = 104;
                    break;
                case "0400101":
                    i_stn = 200;
                    break;
                case "0500101":
                    i_stn = 204;
                    break;
                default:
                    i_stn = 0;
                    break;
            }
            return i_stn;
        }
 
        #region 堆垛机异常列表
        /// <summary>
        /// 根据堆垛机异常码得到异常名称
        /// </summary>
        /// <param name="AlarmCode">堆垛机异常码</param>
        /// <returns>堆垛机异常名称</returns>
        public static string GetCrnErrorName(int AlarmCode)
        {
            string errorName = "";
            switch (AlarmCode)
            {
                case 0:
                    errorName = "";
                    break;
                case 1:
                    errorName = "主电源断路器断开";
                    break;
                case 2:
                    errorName = "相位变化或缺相";
                    break;
                case 3:
                    errorName = "内部 24V 供电异常";
                    break;
                case 4:
                    errorName = "外部 24V 供电异常";
                    break;
                case 5:
                    errorName = "24V总断路器异常";
                    break;
                case 6:
                    errorName = "总交流接触器异常";
                    break;
                case 7:
                    errorName = "行走抱闸接触器异常";
                    break;
                case 8:
                    errorName = "起升抱闸接触器异常";
                    break;
                case 9:
                    errorName = "货叉抱闸接触器异常";
                    break;
                case 11:
                    errorName = "行走变频器报警";
                    break;
                case 12:
                    errorName = "起升变频器报警";
                    break;
                case 13:
                    errorName = "货叉变频器报警";
                    break;
                case 14:
                    errorName = "行走马达保护器异常";
                    break;
                case 15:
                    errorName = "起升马达保护器异常";
                    break;
                case 16:
                    errorName = "货叉马达保护器异常";
                    break;
                case 18:
                    errorName = "货叉位置错误";
                    break;
                case 19:
                    errorName = "货叉触发左极限";
                    break;
                case 20:
                    errorName = "货叉触发右极限";
                    break;
                case 21:
                    errorName = "载货台货物左后超限";
                    break;
                case 22:
                    errorName = "载货台货物左前超限";
                    break;
                case 23:
                    errorName = "载货台货物右后超限";
                    break;
                case 24:
                    errorName = "载货台货物右前超限";
                    break;
                case 25:
                    errorName = "载货台货物左坍塌";
                    break;
                case 26:
                    errorName = "载货台货物左超高";
                    break;
                case 27:
                    errorName = "行走电机位置值未变动";
                    break;
                case 28:
                    errorName = "起升电机位置值未变动";
                    break;
                case 29:
                    errorName = "载货台货物右超高";
                    break;
                case 30:
                    errorName = "货叉电机位置值未变动";
                    break;
                case 32:
                    errorName = "载货台货物右坍塌";
                    break;
                case 33:
                    errorName = "行走激光丢失";
                    break;
                case 34:
                    errorName = "行走停准失败";
                    break;
                case 35:
                    errorName = "起升激光丢失";
                    break;
                case 36:
                    errorName = "起升停准失败";
                    break;
                case 37:
                    errorName = "货叉测距异常";
                    break;
                case 38:
                    errorName = "货叉停准失败";
                    break;
                case 39:
                    errorName = "变频器总线IO通讯断开";
                    break;
                case 42:
                    errorName = "行走电机运行超时";
                    break;
                case 43:
                    errorName = "起升电机运行超时";
                    break;
                case 44:
                    errorName = "货叉电机运行超时";
                    break;
                case 45:
                    errorName = "载货台安全回路断开";
                    break;
                case 47:
                    errorName = "柜门急停";
                    break;
                case 49:
                    errorName = "松绳保护开关触发";
                    break;
                case 51:
                    errorName = "外部急停或安全门打开";
                    break;
                case 53:
                    errorName = "相序保护器异常";
                    break;
                case 54:
                    errorName = "安全继电器异常";
                    break;
                case 55:
                    errorName = "水平极限开关被触发";
                    break;
                case 56:
                    errorName = "起升下极限开关触发";
                    break;
                case 57:
                    errorName = "起升超速保护开关触发";
                    break;
                case 58:
                    errorName = "起升上极限开关触发";
                    break;
                case 61:
                    errorName = "放货时货架有货";
                    break;
                case 62:
                    errorName = "自动模式无任务载货台有货";
                    break;
                case 63:
                    errorName = "放货后载货台有货";
                    break;
                case 64:
                    errorName = "取货后载货台无货";
                    break;
                case 66:
                    errorName = "目标位置未找到";
                    break;
                case 67:
                    errorName = "输送机不允许取货/放货";
                    break;
                case 69:
                    errorName = "任务地址错误";
                    break;
                case 71:
                    errorName = "上一任务未完成警告";
                    break;
                case 75:
                    errorName = "上位机下发急停";
                    break;
                case 76:
                    errorName = "电控柜门打开";
                    break;
                case 85:
                    errorName = "载货台远程IO断开";
                    break;
                case 87:
                    errorName = "触摸屏急停";
                    break;
                case 101:
                    errorName = "货叉在中位没有中位开关信号";
                    break;
                case 102:
                    errorName = "货叉在非中位有中位信号";
                    break;
                default:
                    errorName = "未知";
                    break;
            }
            return errorName;
        }
        #endregion
 
    }
}