public static bool Mid_API_Serial_Open(uint ComPort) { //Mod by FJ for fix linking to incorrect Dll API issue, 2016-12-23 bool result = false; //bool result = true; rfid.Linkage lk = new rfid.Linkage(); uint[] DetectBaudRate = new uint[] { (uint)ENUM_BAUD_RATE.CBR_115200, (uint)ENUM_BAUD_RATE.CBR_230400, (uint)ENUM_BAUD_RATE.CBR_460800, (uint)ENUM_BAUD_RATE.CBR_921600 }; uint errcount = 0; for (int i = 0; i < DetectBaudRate.Length; i++) { if (FTDI_API_Serial_Open(DetectBaudRate[i], ref ftHandle) == FTDI.FT_STATUS.FT_OK) { Use_FTDI_Dll = true; if (lk.API_MacgGetDebug(ref errcount) != Result.OK) { result = false; continue; } else { result = true; return(result); } } else { result = false; } } if (result == false) { Use_FTDI_Dll = false; rfid.DCB pDcb = new rfid.DCB(); pDcb.ByteSize = 8; pDcb.Parity = 0; pDcb.StopBits = (byte)ENUM_STOP_BIT.ONESTOPBIT; pDcb.BaudRate = (uint)ENUM_BAUD_RATE.CBR_115200; if (clsPacket.TRANS_API_Serial_Open(ComPort, ref pDcb) != TRANS_RESULT.OK) { result = false; } else { result = true; } } ////Open COM port by WDK DLL ////Try to open real COM port by baudrate 115200 //Use_FTDI_Dll = false; //rfid.DCB pDcb = new rfid.DCB(); //pDcb.ByteSize = 8; //pDcb.Parity = 0; //pDcb.StopBits = (byte)ENUM_STOP_BIT.ONESTOPBIT; //pDcb.BaudRate = (uint)ENUM_BAUD_RATE.CBR_115200; //if (clsPacket.TRANS_API_Serial_Open(ComPort, ref pDcb) != TRANS_RESULT.OK) //{ // result = false; //} ////Open COM port by FTDI DLL //if (result == false) //Try to open virtual COM port by high speed baudrate //{ // uint[] DetectBaudRate = new uint[] { (uint)ENUM_BAUD_RATE.CBR_115200, (uint)ENUM_BAUD_RATE.CBR_230400, (uint)ENUM_BAUD_RATE.CBR_460800, (uint)ENUM_BAUD_RATE.CBR_921600 }; // uint errcount = 0; // //Use_FTDI_Dll = true; //Del by FJ for the FWUpdate failure in USB connection, 2016-09-08 // for (int i = 0; i < DetectBaudRate.Length; i++) // { // if (FTDI_API_Serial_Open(DetectBaudRate[i], ref ftHandle) == FTDI.FT_STATUS.FT_OK) // { // if (lk.API_MacgGetDebug(ref errcount) != Result.OK) // { // result = false; // continue; // } // else // { // Use_FTDI_Dll = true; //Add by FJ for the FWUpdate failure in USB connection, 2016-09-08 // result = true; // break; // } // } // else // { // result = false; // } // } //} //End by FJ for fix linking to incorrect Dll API issue, 2016-12-23 return(result); }
public bool LinkDevice( ) { #if _TRACE_OUT_PUT PrintMagToTxt("LinkDevice"); #endif bool bGetUSB = false; do { //open USB foreach (ENUM_DEVICE_INFO device in Enum.GetValues(typeof(ENUM_DEVICE_INFO))) { if ( clsPacket.TRANS_API_USB_Open((uint)device, (uint)ENUM_DEVICE_INFO.MTI_VID) == TRANS_RESULT.OK ) { bGetUSB = true; break; } } if (bGetUSB) { #if _TRACE_OUT_PUT PrintMagToTxt("--Open USB successfully---"); #endif break; } else { #if _TRACE_OUT_PUT PrintMagToTxt("--Open USB fail---"); #endif } //open Serial rfid.DCB pDcb = new rfid.DCB(); pDcb.BaudRate = (uint)ENUM_BAUD_RATE.CBR_115200; pDcb.ByteSize = 8; pDcb.Parity = 0; pDcb.StopBits = (byte)ENUM_STOP_BIT.ONESTOPBIT; if (clsPacket.TRANS_API_Serial_Open(uiLibSettingComPort, ref pDcb) != TRANS_RESULT.OK) { #if _TRACE_OUT_PUT PrintMagToTxt("--Open Serial fail---"); #endif return false; } else { #if _TRACE_OUT_PUT PrintMagToTxt("--Open Serial successfully---"); #endif break; } }while( false ); //Set USB/RS232 Overlap time clsPacket.TRANS_API_SetOverlapTime( 400, 400 ); // clark 2011.6.8 //If the device is in inventory status, abort it. //Maybe receive many inventory's infomation. /*Mod by Rick for change abort to stop, 2013-1-29*/ //if( ControlAbort() != Result.OK ) //return false; //??modified for abort??// if (ControlCancel() != Result.OK)/*Mod by Rick for change abort to stop, 2013-1-29*/ return false; System.Threading.Thread.Sleep(500); //Clear inventory's infomation buffer clsPacket.TRANS_API_ClearBuffer(); return true; }