C3032
2025-12-20 38c333f8091e5062be0bbdd81960315ebce69008
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
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using static IDViewerDemo.IDViewerDefines;
using static IDViewerDemo.IDViewerSDK;
 
namespace IDViewerDemo
{
    delegate void IDViewerCallBack(IntPtr device, IntPtr image, IntPtr decodeInfoHandel);
    class Program
    {
        static string filepath = "D:\\text.bmp";
 
        static void Main(string[] args)
        {
            int option = 0;
            long result = IDViewerSDK.IDVIEWER_Init_();
            while (0 == result)
            {
                ClearScreen();
                Console.WriteLine("0) 退出程序");
                Console.WriteLine("1) 读码器操作");
                if (GetInputOption(ref option) == false) continue;
                switch (option)
                {
                    case 0:
                        return;
                    case 1:
                        MenuIDViewer();
                        break;
                    default:
                        break;
                }
 
            }
        }
 
        static void MenuIDViewer()
        {
            int option = 0;
            while (true)
            {
                ClearScreen();
                Console.WriteLine("0) 返回上一级");
                Console.WriteLine("1) 扫描所有读码器");
                Console.WriteLine("2) 通过SN号连接读码器");
                if (GetInputOption(ref option) == false) continue;
                switch (option)
                {
                    case 0:
                        return;
                    case 1:
                        DiscoveryIDViewer();
                        system("pause");
                        break;
                    case 2:
                        DiscoveryIDViewer_SN();
                        system("pause");
                        break;
                    default:
                        break;
                }
            }
        }
 
  
 
        static void DiscoveryIDViewer()
        {
            IntPtr deviceList = IDVIEWER_DiscoveryDevices_();
            long length = IDVIEWER_GetDevicesLength_(deviceList);
            Console.WriteLine("获取到读码器个数为:" + length);
            IDDeviceInfo info = new IDDeviceInfo();
            for (uint i = 0; i < length; i++)
            {
                long Inforesult = IDVIEWER_SelectIDDeviceInfo_(deviceList, ref info, i);
                //Console.WriteLine(Inforesult);
                Console.WriteLine("*******************************************");
                if (i >= 0) Console.WriteLine("index:" + i);
                Console.WriteLine("networkIP:" + new string(info.networkIP));
                Console.WriteLine("networkMask:" + new string(info.networkMask));
                Console.WriteLine("networkGateway:" + new string(info.networkGateway));
                Console.WriteLine("cameraIP:" + new string(info.cameraIP));
                Console.WriteLine("cameraSN:" + new string(info.cameraSN));
                Console.WriteLine("cameraType:" + new string(info.cameraType));
            }
        }
 
 
        static void DiscoveryIDViewer_SN()
        {
            IntPtr device = IntPtr.Zero;
            IDDeviceInfo info = new IDDeviceInfo();
            Console.WriteLine("请输入SN号");
           String serialNum = Console.ReadLine();
            long result =  IDVIEWER_CreateDeviceBySN_(serialNum, ref device);
 
            if (device != IntPtr.Zero)
            {
                int option = 0;
 
                while (true)
                {
                    ClearScreen();
                    Console.WriteLine("0) 返回上一级");
                    Console.WriteLine("1) 打开");
                    Console.WriteLine("2) 运行");
                    Console.WriteLine("3) 连接状态");
                    Console.WriteLine("4) 关闭");
                    if (GetInputOption(ref option) == false) continue;
 
                    if (option == 0)
                    {
                        return;
                    }
 
                    if (option < 1 || option > 10)
                    {
                        continue;
                    }
 
                    switch (option)
                    {
                        case 1:
                            IDDevice_Open(device);
                            break;
                        case 2:
                            Device_StartRunning(device);
                            break;
                        case 3:
                            Device_IsOpen(device);
                            break;
                        case 4:
                            IDDevice_Close(device);
                            break;
                        default:
                            break;
                    }
                    system("pause");
                }
            }
        }
 
 
        static IDViewerCallBack callbackDelegate;
        static IDDecodeInfo decodeInfo;
        
        public static void CallBack(IntPtr device, IntPtr image, IntPtr decodeInfoHandel)
        {
            IDDecodeInfo info = new IDDecodeInfo();                         
            IDCallback_GetIDDecodeInfo_A(decodeInfoHandel, ref info);       //ROI解码信息数组的长度 获取到ROI的解码数量
 
            if (info.decodeStatus)                                         
            {
                for (uint roi = 0; roi < info.IDDecodeROIInfoLength; roi++)
                {
                    IDDecodeROIInfo IDpecodeROIInfo = IDCallback_GetIDDecodeROIInfo(decodeInfoHandel, 0);    
                    if (IDpecodeROIInfo.decodeReusltLength > 0)
                    {
                        IDDecodeResult IDpecodeResult = IDCallback_GetIDDecodeResult(decodeInfoHandel, roi, 0);
 
                        if (IDpecodeResult.dmResultsLength != 0)
                        {
                            for (uint dmSuccessNumber = 0; dmSuccessNumber < IDpecodeResult.dmResultsLength; dmSuccessNumber++)
                            {
                                IDDMCodeResult DMBarCodeResultData = new IDDMCodeResult();
                                long a = IDCallback_GetIDDMCodeResult(decodeInfoHandel, roi, 0, dmSuccessNumber, ref DMBarCodeResultData);
                                Console.WriteLine("ROI:" + (roi + 1));
                                Console.WriteLine("SuccessNumber:" + (dmSuccessNumber + 1));
                                Console.WriteLine("subType:" + new string(DMBarCodeResultData.subType));
                                Console.WriteLine("codeString: " + new string(DMBarCodeResultData.codeString));
                            }
                        }
                        else if (IDpecodeResult.qrResultsLength != 0)
                        {
                            for (uint qrSuccessNumber = 0; qrSuccessNumber < IDpecodeResult.qrResultsLength; qrSuccessNumber++)
                            {
                                IDQRCodeResult QRBarCodeResultData = new IDQRCodeResult();
                                long a = IDCallback_GetID_QR_CODE_Result(decodeInfoHandel, roi, 0, qrSuccessNumber, ref QRBarCodeResultData);
                                Console.WriteLine("ROI:" + (roi + 1));
                                Console.WriteLine("SuccessNumber:" + (qrSuccessNumber + 1));
                                Console.WriteLine("subType:" + new string(QRBarCodeResultData.subType));
                                Console.WriteLine("codeString: " + new string(QRBarCodeResultData.codeString));
                            }
                        }
                        else if (IDpecodeResult.pdf417ResultsLength != 0)
                        {
                            for (uint pdf417SuccessNumber = 0; pdf417SuccessNumber < IDpecodeResult.qrResultsLength; pdf417SuccessNumber++)
                            {
                                IDPDF417CodeResult PDF417BarCodeResultData = new IDPDF417CodeResult();
                                long a = IDCallback_GetIDPDF417CodeResult(decodeInfoHandel, roi, 0, pdf417SuccessNumber, ref PDF417BarCodeResultData);
                                Console.WriteLine("ROI:" + (roi + 1));
                                Console.WriteLine("SuccessNumber:" + (pdf417SuccessNumber + 1));
                                Console.WriteLine("subType:" + new string(PDF417BarCodeResultData.subType));
                                Console.WriteLine("codeString: " + new string(PDF417BarCodeResultData.codeString));
                            }
                        }
                        else if (IDpecodeResult.barcodeResultsLength != 0)
                        {
                            for (uint barcodeSuccessNumber = 0; barcodeSuccessNumber < IDpecodeResult.qrResultsLength; barcodeSuccessNumber++)
                            {
                                IDBarCodeResult IDBarCodeResultData = new IDBarCodeResult();
                                long a = IDCallback_GetIDBarCodeResult(decodeInfoHandel, roi, 0, barcodeSuccessNumber, ref IDBarCodeResultData);
                                Console.WriteLine("ROI:" + (roi + 1));
                                Console.WriteLine("SuccessNumber:" + (barcodeSuccessNumber + 1));
                                Console.WriteLine("codeString: " + new string(IDBarCodeResultData.codeString));
                            }
                        }
                    }
                }
            }
        }
 
        static void Device_StartRunning(IntPtr device)
        {
 
            IDDevice_StartRunning(device,1);
            callbackDelegate = new IDViewerCallBack(CallBack);
            IntPtr functionPointer = Marshal.GetFunctionPointerForDelegate(callbackDelegate);
            IDCallback_ResultNotify_(device, functionPointer);
            GC.KeepAlive(callbackDelegate);
        }
        static void Device_IsOpen(IntPtr device)
        { 
            long rel = IDDevice_IsOpen(device);
            if (rel == 0)
            {
                Console.WriteLine("读码器未打开");
            }
            else
            {
                Console.WriteLine("读码器已打开");
            }
        }
 
        static bool GetInputOption(ref int option)
        {
            int op;
            try
            {
                op = int.Parse(Console.ReadLine());
            }
            catch
            {
                return false;
            }
            option = op;
            return true;
        }
        static void ClearScreen()
        {
            system("cls");
            Console.WriteLine("*******************************************");
            Console.WriteLine("*              IDViewer Demo              *");
            Console.WriteLine("*******************************************");
        }
 
        [DllImport("msvcrt.dll", SetLastError = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        private extern static void system(string command);
    }
}