二维码模组扫码器C#实现串口自动监听功能

news2024/9/20 10:49:15

C# Demo,调用二维码模块的tx_windows_hidpos.dll扫码库,支持QR-M20 、QR-M10、QR-M30等二维码型号。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text;
using System.IO;
using System.IO.Ports;
using System.Threading;
using System.Management;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using AssemblyInfo;

namespace demo
{
    class Program
    {
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		/**解码数据回调函数**/
        public delegate int tx_scanner_decode_data_cb_fun(byte ucCodeType, [MarshalAs(UnmanagedType.LPArray, SizeConst = 8192)]byte[] pBuf, int uiBufLen);
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		/**通信接口连接状态0:断开,1:连接**/
        public delegate void tx_scanner_comm_state_cb_fun(byte ucState);

		[DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
		private extern static int tx_scanner_init();

		[DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
		private extern static int tx_scanner_deinit();

		[DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
		private extern static int tx_scanner_get_version(byte[] pVer, byte ucVerLen);

		[DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
		private extern static int tx_scanner_decode_data_fun_register(tx_scanner_decode_data_cb_fun fDataFun);

		[DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
		private extern static int tx_scanner_comm_state_fun_register(tx_scanner_comm_state_cb_fun fStateFun);

		[DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
		private extern static int tx_scanner_get_version_info(byte[] pVerInfo, int iVerInfoLen);

		[DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
		private extern static int tx_scanner_get_all_product_info(byte[] pProInfo, int iProInfoLen);

		[DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
		private extern static int tx_scanner_decode_start();

		[DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
		private extern static int tx_scanner_decode_stop();

		[DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
		private extern static int tx_scanner_no_time_decode_start();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_trigger_mode(DB_TRIGGER_MODE_E eMode, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_trigger_mode();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_light_state(DB_LED_STATE_E eLedState, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_light_state();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_en_prefix(byte ucEnable, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_en_prefix();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_prefix(byte[] pData, byte ucDataLen, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_prefix(byte[] pData, byte ucDataLen);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_en_suffix(byte ucEnable, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_en_suffix();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_suffix(byte[] pData, byte ucDataLen, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_suffix(byte[] pData, byte ucDataLen);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_focus_state(DB_LED_STATE_E eLedState, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_focus_state();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_once_scan_time(int usTimeMs, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_once_scan_time();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_beep_volume(byte ucVol, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_beep_volume();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_heartbeat_type(DB_HEARTBEAT_TYPE_E eType, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_heartbeat_type();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_reset();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_scan_sw(byte ucEnable);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_cmd_setcode_sw(byte ucEnable, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_heartbeat_gap_time(uint uiTimeMs, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_heartbeat_gap_time();

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_set_heartbeat_wait_ack_time(uint uiTimeMs, byte isSaveParam);

        [DllImport("..\\..\\..\\..\\..\\lib\\tx_windows_hidpos.dll", CallingConvention = CallingConvention.Cdecl)]
        private extern static int tx_scanner_get_heartbeat_wait_ack_time();


		static tx_scanner_decode_data_cb_fun s_fDecodeDataCb;
        static tx_scanner_comm_state_cb_fun s_fCommStateCb;

		static int s_uiDecodeCnt = 0;
		static int tx_scanner_sdk_decode_data_cb(byte ucCodeType, byte[] pBuf, int uiBufLen)
		{
			byte[] ucData = new byte[uiBufLen];
			string strData;
			int i;

			for(i=0; i<uiBufLen; i++)
            {
                ucData[i] = pBuf[i];
            }

			strData = System.Text.Encoding.Default.GetString(ucData, 0, uiBufLen);
			Console.WriteLine("[{0}[{1}]len:{2},data:{3}", ++s_uiDecodeCnt, ucCodeType, uiBufLen, strData);
			return 0;
		}
		
		static void tx_scanner_sdk_comm_state_cb_fun(byte ucState)
		{
			/**0:断开连接,1:连接**/
			Console.WriteLine("scanner usb hidpos state:{0}", ucState);
		}

        static void tx_scanner_sdk_show_menu()
        {
            Console.Write("***************************MENU***************************\r\n");
            Console.Write("a:start decode\r\n");
            Console.Write("b:stop decode\r\n");
            Console.Write("c:no time decode start\r\n");
            Console.Write("d:get version info\r\n");
            Console.Write("e:get product info\r\n");
            Console.Write("f:set trigger mode; 0:LEVEL,1:PULSE,2:CONTINUOUS,3:AUTOSENS; save:0:no,1:yes.(eg:f01)\r\n");
            Console.Write("g:get trigger mode\r\n");
            Console.Write("h:set light LED; 0:working light,1:always off,2:always on; save:0:no,1:yes.(eg:h01)\r\n");
            Console.Write("i:get light LED\r\n");
            Console.Write("j:set focus state; 0:working light,1:always off,2:always on; save:0:no,1:yes.(eg:j01)\r\n");
            Console.Write("k:get fucus state\r\n");
            Console.Write("l:set en prefix; 0:OFF,1:ON; save:0:no,1:yes.(eg:l01)\r\n");
            Console.Write("n:get en prefix\r\n");
            Console.Write("o:set prefix; save:0:no,1:yes.(eg:o0)\r\n");
            Console.Write("p:get prefix length\r\n");
            Console.Write("r:set en suffix; 0:OFF,1:ON; save:0:no,1:yes.(eg:r01)\r\n");
            Console.Write("s:get en suffix\r\n");
            Console.Write("t:set suffix; save:0:no,1:yes.(eg:t0)\r\n");
            Console.Write("u:get suffix length\r\n");
            Console.Write("v:set once scan time(0-65536); save:0:no,1:yes.(eg:v01)\r\n");
            Console.Write("w:get once scan time\r\n");
            Console.Write("x:set beep volume(0-100); save:0:no,1:yes.(eg:x01)\r\n");
            Console.Write("y:get beep volume\r\n");
            Console.Write("z:set heartbeat type; 0:BAN,1:NO ACK,2:ACK; save:0:no,1:yes.(eg:z01)\r\n");
            Console.Write("0:get heartbeat type\r\n");
            Console.Write("1:set heartbeat gap time(0-2147483648); save:0:no,1:yes.(eg:101)\r\n");
            Console.Write("2:get heartbeat gap time\r\n");
            Console.Write("3:set heartbeat wait ack time(0-2147483648); save:0:no,1:yes.(eg:301)\r\n");
            Console.Write("4:get heartbeat wait ack time\r\n");
            Console.Write("5:reset\r\n");
            Console.Write("6:set scan sw; 0:unable,1:able\r\n");
            Console.Write("7:set setcode sw; 0:unable,1:able; save:0:no,1:yes.(eg:71)\r\n");
            Console.Write("?/m:more menu\r\n");
            Console.Write("q:quit\r\n");
            Console.Write("******************************************************\r\n");
        }
		
        static void Main(string[] args)
        {
            int iRet;
            byte[] ucVer = new byte[128];
			byte[] ucVerInfo = new byte[128];
			byte[] ucProInfo = new byte[512];
            byte[] cTemp = new byte[128];
            string strTemp = null;
            byte ucTemp1;
            byte ucTemp2;
            uint uiTemp3;
            char cFristChar;
            char cSecondChar;
            string cInput;
            byte uiLen = 0;

            iRet = tx_scanner_get_version(ucVer, (byte)ucVer.Length);
            if(iRet > 0)
                strTemp = System.Text.Encoding.Default.GetString(ucVer, 0, iRet);
            Console.WriteLine("windows c# usb hidpos demo ver:{0}", strTemp);

			/**注册解码数据回调函数**/
			s_fDecodeDataCb = tx_scanner_sdk_decode_data_cb;
			tx_scanner_decode_data_fun_register(s_fDecodeDataCb);

            /**注册设备连接状态回调函数**/
            s_fCommStateCb = tx_scanner_sdk_comm_state_cb_fun;
			tx_scanner_comm_state_fun_register(s_fCommStateCb);

			/**初始化**/
			tx_scanner_init();

			Console.Write("******************************************************\r\n");
			Console.Write("a:start decode\r\n");
	        Console.Write("b:stop decode\r\n");
	        Console.Write("c:no time decode start\r\n");
	        Console.Write("d:get version info\r\n");
	        Console.Write("e:get product info\r\n");
	        Console.Write("f:set trigger mode; 0:LEVEL,1:PULSE,2:CONTINUOUS,3:AUTOSENS; save:0:no,1:yes.(eg:f01)\r\n");
	        Console.Write("g:get trigger mode\r\n");
	        Console.Write("h:set light LED; 0:working light,1:always off,2:always on; save:0:no,1:yes.(eg:h01)\r\n");
	        Console.Write("i:get light LED\r\n");
	        Console.Write("?/m:more menu\r\n");
	        Console.Write("q:quit\r\n");
			Console.Write("******************************************************\r\n");
            while(true)
            {
                /**switch(Console.ReadLine())这种方式需要点击回车,有的功能操作方式和C++的不一样,如C++下h01+回车,C#下h+回车+01**/
                switch(Console.ReadKey().KeyChar)
                {
                	case 'A':
                    case 'a':
                        Console.ReadLine();/**吸收回车符**/
						iRet = tx_scanner_decode_start();
						if (iRet < 0)
							Console.Write("tx_scanner_decode_start fail!!!\r\n");
						else
							Console.Write("start\r\n");
                        break;

					case 'B':
                    case 'b':
                        Console.ReadLine();
						iRet = tx_scanner_decode_stop();
						if (iRet < 0)
							Console.Write("tx_scanner_decode_stop fail!!!\r\n");
						else
							Console.Write("stop\r\n");
                        break;

					case 'C':
                    case 'c':
                        Console.ReadLine();
						iRet = tx_scanner_no_time_decode_start();
						if (iRet < 0)
							Console.Write("tx_scanner_no_time_decode_start fail!!!\r\n");
						else
							Console.Write("no time start\r\n");
                        break;

					case 'D':
                    case 'd':
                        Console.ReadLine();
						iRet = tx_scanner_get_version_info(ucVerInfo, ucVerInfo.Length);
						if (iRet < 0)
						{
							Console.Write("tx_scanner_get_version_info fail!!!\r\n");
						}
						else
						{
			                strTemp = System.Text.Encoding.Default.GetString(ucVerInfo, 0, iRet);
			           		Console.Write("{0}\r\n", strTemp);
						}
                        break;

					case 'E':
                    case 'e':
                        Console.ReadLine();
						iRet = tx_scanner_get_all_product_info(ucProInfo, ucProInfo.Length);
						if (iRet < 0)
						{
							Console.Write("tx_scanner_get_all_product_info fail!!!\r\n");
						}
						else
						{
			                strTemp = System.Text.Encoding.Default.GetString(ucProInfo, 0, iRet);
			           		Console.Write("{0}\r\n", strTemp);
						}
                        break;

                    case 'f':
		            case 'F':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 2)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 2 characters.");
                        }
                        else
                        {
                            cFristChar = cInput[0];
                            cSecondChar = cInput[1];
                            ucTemp1 = byte.Parse(cFristChar.ToString());
                            ucTemp2 = byte.Parse(cSecondChar.ToString());

                            Console.Write("{0},{1}\r\n", ucTemp1, ucTemp2);
                            iRet = tx_scanner_set_trigger_mode((DB_TRIGGER_MODE_E)ucTemp1, ucTemp2);
                            if (iRet < 0)
                                Console.Write("tx_scanner_set_trigger_mode fail!!!\r\n");
                        }
				        break;

		            case 'g':
		            case 'G':
			            Console.ReadLine();
				        iRet = tx_scanner_get_trigger_mode();
				        Console.Write("tx_scanner_get_trigger_mode:{0}\r\n", iRet);
				        break;

		            case 'h':
		            case 'H':
                        cInput = Console.ReadLine();
                        if (cInput.Length < 2)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 2 characters.");
                        }
                        else
                        {
                            cFristChar = cInput[0];
                            cSecondChar = cInput[1];
                            ucTemp1 = byte.Parse(cFristChar.ToString());
                            ucTemp2 = byte.Parse(cSecondChar.ToString());

                            Console.Write("{0},{1}\r\n", ucTemp1, ucTemp2);
                            iRet = tx_scanner_set_light_state((DB_LED_STATE_E)ucTemp1, ucTemp2);
                            if (iRet < 0)
                                Console.Write("ts_scanner_set_light_state fail!!!\r\n");
                        }
				        break;

		            case 'i':
		            case 'I':
			            Console.ReadLine();
				        iRet = tx_scanner_get_light_state();
				        Console.Write("ts_scanner_get_light_state:{0}\r\n", iRet);
				        break;	

		            case 'j':
		            case 'J':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 2)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 2 characters.");
                        }
                        else
                        {
                            cFristChar = cInput[0];
                            cSecondChar = cInput[1];
                            ucTemp1 = byte.Parse(cFristChar.ToString());
                            ucTemp2 = byte.Parse(cSecondChar.ToString());

                            Console.Write("{0},{1}\r\n", ucTemp1, ucTemp2);
                            iRet = tx_scanner_set_focus_state((DB_LED_STATE_E)ucTemp1, ucTemp2);
                            if (iRet < 0)
                                Console.Write("tx_scanner_set_focus_state fail!!!\r\n");
                        }
			            break;

		            case 'k':
		            case 'K':
                        cInput = Console.ReadLine();
			            iRet = tx_scanner_get_focus_state();
			            Console.Write("tx_scanner_set_focus_state:{0}\r\n", iRet);
			            break;
		
		            case 'l':
		            case 'L':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 2)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 2 characters.");
                        }
                        else
                        {
                            cFristChar = cInput[0];
                            cSecondChar = cInput[1];
                            ucTemp1 = byte.Parse(cFristChar.ToString());
                            ucTemp2 = byte.Parse(cSecondChar.ToString());

                            Console.Write("{0},{1}\r\n", ucTemp1, ucTemp2);
                            iRet = tx_scanner_set_en_prefix(ucTemp1, ucTemp2);
                            if (iRet < 0)
                                Console.Write("tx_scanner_set_prefix_state fail!!!\r\n");
                        }
				        break;

		            case 'n':
		            case 'N':
			            Console.ReadLine();
				        iRet = tx_scanner_get_en_prefix();
				        Console.Write("tx_scanner_get_en_prefix:{0}\r\n", iRet);
				        break;

		            case 'o':
		            case 'O':
		                {
					        cInput = Console.ReadLine();
                            if (cInput.Length < 1)
                            {
                                Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                            }
                            else
                            {
                                cFristChar = cInput[0];
                                ucTemp1 = byte.Parse(cFristChar.ToString());
                                Console.Write("{0}\r\n", ucTemp1);

                                string str = "ABC";
                                byte[] ucArr = Encoding.ASCII.GetBytes(str);
                                uiLen = (byte)str.Length;

                                iRet = tx_scanner_set_prefix(ucArr, uiLen, ucTemp1);
                                if (iRet < 0)
                                    Console.Write("tx_scanner_set_prefix fail!!!\r\n");
                            }
					        break;
				        }
		
		            case 'p':
		            case 'P':
			            Console.ReadLine();
				        Array.Clear(cTemp, 0, cTemp.Length);
				        iRet = tx_scanner_get_prefix(cTemp, uiLen);
				        Console.Write("tx_scanner_get_prefix:{0}\r\n", iRet);			
				        break;
		
		            case 'r':
		            case 'R':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 2)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 2 characters.");
                        }
                        else
                        {
                            cFristChar = cInput[0];
                            cSecondChar = cInput[1];
                            ucTemp1 = byte.Parse(cFristChar.ToString());
                            ucTemp2 = byte.Parse(cSecondChar.ToString());
                            Console.Write("{0},{1}\r\n", ucTemp1, ucTemp2);

                            iRet = tx_scanner_set_en_suffix(ucTemp1, ucTemp2);
                            if (iRet < 0)
                                Console.Write("tx_scanner_set_en_suffix fail!!!\r\n");
                        }
				        break;
			
		            case 's':
		            case 'S':
			            Console.ReadLine();
				        iRet = tx_scanner_get_en_suffix();
				        Console.Write("tx_scanner_get_en_suffix:{0}\r\n", iRet);
				        break;

		            case 't':
		            case 'T':
		                {
					        cInput = Console.ReadLine();
                            if (cInput.Length < 1)
                            {
                                Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                            }
                            else
                            {
                                cFristChar = cInput[0];
                                ucTemp1 = byte.Parse(cFristChar.ToString());
                                Console.Write("{0}\r\n", ucTemp1);

                                string str = "CBA";
                                byte[] ucArr = Encoding.ASCII.GetBytes(str);
                                uiLen = (byte)str.Length;

                                iRet = tx_scanner_set_suffix(ucArr, uiLen, ucTemp1);
                                if (iRet < 0)
                                    Console.Write("tx_scanner_set_suffix fail!!!\r\n");
                            }
					        break;
				        }

		            case 'u':
		            case 'U':
			            Console.ReadLine();
				        Array.Clear(cTemp, 0, cTemp.Length);
				        iRet = tx_scanner_get_suffix(cTemp, uiLen);
				        Console.Write("tx_scanner_get_suffix:{0}\r\n", iRet);
				        break;
		
		            case 'v':
		            case 'V':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 1)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                        }
                        else
                        {
                            uiTemp3 = uint.Parse(cInput);
                            cInput = Console.ReadLine();
                            if (cInput.Length < 1)
                            {
                                Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                            }
                            else
                            {
                                cFristChar = cInput[0];
                                ucTemp1 = byte.Parse(cFristChar.ToString());

                                Console.Write("{0},{1}\r\n", uiTemp3, ucTemp1);
                                iRet = tx_scanner_set_once_scan_time((ushort)uiTemp3, ucTemp1);
                                if (iRet < 0)
                                    Console.Write("tx_scanner_set_suffix_state fail!!!\r\n");
                            }
                        }
				        break;
			
		            case 'w':
		            case 'W':
			            Console.ReadLine();
				        iRet = tx_scanner_get_once_scan_time();
				        Console.Write("tx_scanner_get_once_scan_time:{0}\r\n", iRet);
				        break;

		            case 'x':
		            case 'X':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 1)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                        }
                        else
                        {
                            ucTemp1 = byte.Parse(cInput);
                            cInput = Console.ReadLine();
                            if (cInput.Length < 1)
                            {
                                Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                            }
                            else
                            {
                                cFristChar = cInput[0];
                                ucTemp2 = byte.Parse(cFristChar.ToString());

                                Console.Write("{0},{1}\r\n", ucTemp1, ucTemp2);
                                iRet = tx_scanner_set_beep_volume(ucTemp1, ucTemp2);
                                if (iRet < 0)
                                    Console.Write("tx_scanner_set_beep_volume fail!!!\r\n");
                            }
                        }
				        break;

		            case 'y':
		            case 'Y':
			            Console.ReadLine();
				        iRet = tx_scanner_get_beep_volume();
				        Console.Write("tx_scanner_get_beep_volume:{0}\r\n", iRet);
				        break;	
			
		            case 'z':
		            case 'Z':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 2)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 2 characters.");
                        }
                        else
                        {
                            cFristChar = cInput[0];
                            cSecondChar = cInput[1];
                            ucTemp1 = byte.Parse(cFristChar.ToString());
                            ucTemp2 = byte.Parse(cSecondChar.ToString());
                            Console.Write("{0},{1}\r\n", ucTemp1, ucTemp2);

                            iRet = tx_scanner_set_heartbeat_type((DB_HEARTBEAT_TYPE_E)ucTemp1, ucTemp2);
                            if (iRet < 0)
                                Console.Write("tx_scanner_set_heartbeat_type fail!!!\r\n");
                        }
				        break;
			
		            case '0':
			            Console.ReadLine();
				        iRet = tx_scanner_get_heartbeat_type();
				        Console.Write("tx_scanner_get_heartbeat_type:{0}\r\n", iRet);
				        break;

		            case '1':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 1)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                        }
                        else
                        {
                            uiTemp3 = uint.Parse(cInput);
                            cInput = Console.ReadLine();
                            if (cInput.Length < 1)
                            {
                                Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                            }
                            else
                            {
                                cFristChar = cInput[0];
                                ucTemp1 = byte.Parse(cFristChar.ToString());

                                iRet = tx_scanner_set_heartbeat_gap_time(uiTemp3, ucTemp1);
                                if (iRet < 0)
                                    Console.Write("tx_scanner_set_heartbeat_gap_time fail!!!\r\n");
                            }
                        }
				        break;
			
		            case '2':
			            Console.ReadLine();
				        iRet = tx_scanner_get_heartbeat_gap_time();
				        Console.Write("tx_scanner_get_heartbeat_gap_time:{0}\r\n", iRet);
				        break;

		            case '3':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 1)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                        }
                        else
                        {
                            uiTemp3 = uint.Parse(cInput);
                            cInput = Console.ReadLine();
                            if (cInput.Length < 1)
                            {
                                Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                            }
                            else
                            {
                                cFristChar = cInput[0];
                                ucTemp1 = byte.Parse(cFristChar.ToString());

                                iRet = tx_scanner_set_heartbeat_wait_ack_time(uiTemp3, ucTemp1);
                                if (iRet < 0)
                                    Console.Write("tx_scanner_set_heartbeat_wait_ack_time fail!!!\r\n");
                            }
                        }
				        break;

		            case '4':
			            Console.ReadLine();
				        iRet = tx_scanner_get_heartbeat_wait_ack_time();
				        Console.Write("tx_scanner_get_heartbeat_wait_ack_time:{0}\r\n", iRet);
				        break;
			
		            case '5':
			            Console.ReadLine();
				        iRet = tx_scanner_reset();
				        if(iRet < 0)
					        Console.Write("tx_scanner_reset fail!!!\r\n");
				        else
					        Console.Write("reset\r\n");				
				        break;

		            case '6':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 1)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 1 characters.");
                        }
                        else
                        {
                            cFristChar = cInput[0];
                            ucTemp1 = byte.Parse(cFristChar.ToString());
                            Console.Write("{0}\r\n", ucTemp1);
                            iRet = tx_scanner_scan_sw(ucTemp1);
                            if (iRet < 0)
                                Console.Write("tx_scanner_scan_sw fail!!!\r\n");
                        }
				        break;

		            case '7':
			            cInput = Console.ReadLine();
                        if (cInput.Length < 2)
                        {
                            Console.WriteLine("Invalid input! Input length must be at least 2 characters.");
                        }
                        else
                        {
                            cFristChar = cInput[0];
                            cSecondChar = cInput[1];
                            ucTemp1 = byte.Parse(cFristChar.ToString());
                            ucTemp2 = byte.Parse(cSecondChar.ToString());
                            Console.Write("{0},{1}\r\n", ucTemp1, ucTemp2);

                            iRet = tx_scanner_cmd_setcode_sw(ucTemp1, ucTemp2);
                            if (iRet < 0)
                                Console.Write("tx_scanner_cmd_setcode_sw fail!!!\r\n");
                        }
				        break;

		            case 'm':
		            case 'M':
		            case '?':
                        cInput = Console.ReadLine();
			            tx_scanner_sdk_show_menu();
			            break;
		
		            case 'q':
		            case 'Q':
                        cInput = Console.ReadLine();
			            Console.Write("quit\r\n");
			            return;

                    default:
                        break;
                }
            }
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2134806.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

超级好用的化妆神器,一键迁移妆容,觉得别人化妆真好看,看我一键迁移到自己的脸上!(附工作流)

这两天开源社区又出了一个比较有趣的ComfyUI 插件&#xff0c;功能很简单&#xff0c;可以实现妆容的一键迁移。 操作也很简单&#xff0c;只需要上传一张带有妆容的人物照片&#xff0c;再上传一张想要迁移妆容的照片&#xff0c;就可以把参考人物的妆容迁移到想要迁移的人物…

深入分析计算机网络性能指标

速率带宽吞吐量时延时延带宽积往返时间RTT利用率丢包率图书推荐内容简介作者简介 速率 连接在计算机网络上的主机在数字信道上传送比特的速率&#xff0c;也称为比特率或数据率。 基本单位&#xff1a;bit/s&#xff08;b/s、bps&#xff09; 常用单位&#xff1a;kb/s&#x…

大模型能否真正理解上下文?

人工智能咨询培训老师叶梓 转载标明出处 尽管对LLMs的评估涵盖了自然语言处理&#xff08;NLP&#xff09;的各个领域&#xff0c;但对它们理解上下文特征的语言能力的探讨却相对有限。为了填补这一空白&#xff0c;乔治城大学和苹果公司的研究者们共同提出了一种新的上下文理解…

HW行动指南,前辈教你如何真正靠护网赚到钱!

‍正文&#xff1a; HW行动&#xff0c;攻击方的专业性越来越高&#xff0c;ATT&CK攻击手段覆盖率也越来越高&#xff0c;这对于防守方提出了更高的要求&#xff0c;HW行动对甲方是一个双刃剑&#xff0c;既极大地推动了公司的信息安全重视度和投入力量&#xff0c;但同时…

【目标检测数据集】水泥搅拌车数据集2165张VOC+YOLO格式

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;2165 标注数量(xml文件个数)&#xff1a;2165 标注数量(txt文件个数)&#xff1a;2165 标注…

【LeetCode】每日一题 2024_9_14 从字符串中移除星号(模拟)

前言 每天和你一起刷 LeetCode 每日一题~ LeetCode 启动&#xff01; 今天的题目曾经的我做过了 . . . 又是复习的一天 题目&#xff1a;从字符串中移除星号 代码与解题思路 func removeStars(s string) string {// 本题的核心&#xff1a;生成的输入保证总是可以执行题面中…

ImportError: DLL load failed while importing _ssl: 找不到指定的模块的解决方法

ImportError: DLL load failed while importing _ssl: 找不到指定的模块的解决方法 现象解决办法 现象 在命令行中&#xff0c;可以正常导入_ssl模块&#xff0c;如下&#xff1a; Python 3.9.0 (default, Nov 15 2020, 08:30:55) [MSC v.1916 64 bit (AMD64)] :: Anaconda, …

【Qt | QLineEdit】Qt 中使 QLineEdit 响应 鼠标单击、双击事件 的两个方法

&#x1f601;博客主页&#x1f601;&#xff1a;&#x1f680;https://blog.csdn.net/wkd_007&#x1f680; &#x1f911;博客内容&#x1f911;&#xff1a;&#x1f36d;嵌入式开发、Linux、C语言、C、数据结构、音视频&#x1f36d; ⏰发布时间⏰&#xff1a; 2024-09-14 …

做外贸为什么要做谷歌seo?

跟国内不同&#xff0c;购物有多个大平台可供选择&#xff0c;在海外是有很多人会在谷歌搜索上寻找自己想要的产品或者服务的&#xff0c;海外谷歌那是真正的老大哥&#xff0c;你想要的都能搜到&#xff0c;而谷歌的流量以及准确性&#xff0c;都不是国内以及购物平台可以比拟…

Vue组合式API:setup()函数

1、什么是组合式API Vue 3.0 中新增了组合式 API 的功能&#xff0c;它是一组附加的、基于函数的 API&#xff0c;可以更加灵活地组织组件代码。通过组合式 API 可以使用函数而不是声明选项的方式来编写 Vue 组件。因此&#xff0c;使用组合式 API 可以将组件代码编写为多个函…

H3C CAS系列开篇之CAS初认识

一、前言 基于信创需要,某项目中的VMware软件存求替代方案,尤其在Virtual Desktop Infrastructure(VDI)方面,寻求使用紫光集团旗下H3C的CAS云计算管理平台,又称CAS虚拟化解决方案/管理系统,H3C CAS是H3C公司面向数据中心自主研发的企业级虚拟化软件。CAS提供了强大的虚拟…

nz-select 数据回显失败,大模型救了我一命。

文章目录 前言问题现象问题解决经过数据类型的问题&#xff1f;求助大模型问题解决 小小的疑问 前言 最近老苦逼了。原本计划推进的《软件开发人员从0到1实现物联网项目》项目因为种种原因停滞了将近一个月&#xff0c;进展缓慢。其中一个原因就和本文有关。 继《时隔5年重拾…

MySQL迁移达梦,部分数据写入失败,VARCHAR字段长度不足

迁移时&#xff0c;字符长度选择“4”即可。如果是GBK可选择“2”。

八道指针笔试题

文章目录 笔试题1笔试题2笔试题3笔试题4笔试题5笔试题6笔试题7笔试题8 笔试题1 int main() { int a[5] { 1, 2, 3, 4, 5 }; int *ptr (int *)(&a 1); printf( "%d,%d", *(a 1), *(ptr - 1)); return 0; } //程序的结果是什么&#xff1f;首先定义了一个数组…

数据结构————双链表

目录 一、单链表的定义及其特点 定义&#xff1a; 特点&#xff1a; 双链表的优缺点 双链表的关键特性 二、双链表的实现 准备工作&#xff1a; 自定义数据元素类型&#xff1a; 1.双链表的创建 1.1头插法介绍 1.2尾插法介绍 2.双链表的初始化 3.双链表的求表长 4.…

TDengine 与 SCADA 强强联合:提升工业数据管理的效率与精准

随着时序数据库&#xff08;Time Series Database&#xff09;的日益普及&#xff0c;越来越多的工业自动化控制&#xff08;工控&#xff09;人员开始认识到其强大能力。然而&#xff0c;时序数据库在传统实时数据库应用领域&#xff0c;特别是在过程监控层的推广仍面临挑战&a…

cmd命令

常用命令 查看电脑名称&#xff1a; hostname 查看网卡信息&#xff1a; ipconfig 快速打开网络设置界面&#xff1a; control.exe netconnections 或 rundll32.exe shell32.dll,Control_RunDLL ncpa.cpld 打开防火墙设置&#xff1a; wf.msc 指定网卡设置IP地址&#…

linux_L1_linux重启服务器

使用putty登录到linux服务器切换到管理员账号 sudo -s重启命令 reboot

Unity全面取消Runtime费用 安装游戏不再收版费

Unity宣布他们已经废除了争议性的Runtime费用&#xff0c;该费用于2023年9月引入&#xff0c;定于1月1日开始收取。Runtime费用起初是打算根据使用Unity引擎安装游戏的次数收取版权费。2023年9月晚些时候&#xff0c;该公司部分收回了计划&#xff0c;称Runtime费用只适用于订阅…

ROS1录包偶现一次崩溃问题定位

现象&#xff1a;崩到了mogo_reporter里面 堆栈&#xff1a;crash里面同时存在两个主线程的堆栈 代码 #include "boost/program_options.hpp" #include <signal.h> #include <string> #include <sstream> #include <iostream> #include <…