private void barcodeDisconnect() { if (IsDebugMode) { Trace.WriteLine("barcodeDisconnect()"); } if (PublicFunctionBarcode.type.Equals(4) || PublicFunctionBarcode.type.Equals(5)) { mBarcodePublicFunction.free(); } else if (mBarcodePublicFunction.isOpen()) { mBarcodePublicFunction.closePort(); // 非Intermec型號專用 } mBarcodePublicFunction = null; TimerBarcode = null; buttonBarcodeConnect.Enabled = true; buttonBarcodeDisconnect.Enabled = false; buttonScan.Enabled = false; }
protected override void WndProc(ref Message m) { if (m == null) { return; } #region Intermec 用來收 Comport 回傳 Data 的事件(Intermec自己將Comport操作的function直接包成DLL給User用) if (m.Msg == PublicFunctionBarcode.WM_ISCP_FRAME) { switch ((byte)m.WParam) { case PublicFunctionBarcode.BCD: PublicFunctionBarcode.GetBarcodeDataIsdcRs(); break; } } else if (m.Msg == PublicFunctionBarcode.WM_RAW_DATA) { PublicFunctionBarcode.GetRawDataIsdcRs(); } #endregion #region Moto 用來收 Comport 回傳 Data 的事件(Moto自己將Comport操作的function直接包成DLL給User用) if (m.Msg == 0x8001) { PublicFunctionBarcode.GetDecodeData(); SsiDllApi.SetDecodeBuffer(Convert.ToInt32(PortAddressBarcode.Remove(0, 3)), SsiDllApi.DecodeData, SsiDllApi.MAX_LEN); } else if (m.Msg == 0x8008) { PublicFunctionBarcode.GetVersionData(); SsiDllApi.SetDecodeBuffer(Convert.ToInt32(PortAddressBarcode.Remove(0, 3)), SsiDllApi.DecodeData, SsiDllApi.MAX_LEN); } #endregion base.WndProc(ref m); }
private void Barcode_Load(object sender, EventArgs e) { CloseWidget(); result["result"] = "FAIL"; var jsonconfig = GetFullPath("config.json"); if (!File.Exists(jsonconfig)) { MessageBox.Show("config.json not founded"); Exit(); } dynamic jobject = JObject.Parse(File.ReadAllText(jsonconfig)); ShowWindow = (bool)jobject.ShowWindow; IsHardwareTrigger = (bool)jobject.IsHardwareTrigger; BarcodeType = (int)jobject.BarcodeType; PortAddressBarcode = jobject.PortAddressBarcode.ToString(); BarcodeReadTime = (int)jobject.BarcodeReadTime; IsConfirmTagContextBarcode = (bool)jobject.IsConfirmTagContextBarcode; ConfirmTagContextBarcode = jobject.ConfirmTagContextBarcode.ToString(); if (ShowWindow) { this.Opacity = 100; this.ShowInTaskbar = true; } if (IsDebugMode) { Trace.WriteLine("Barcode_Load"); } Trace.WriteLine("Open all device power."); HotTabDLL.WinIO_SetDevice2State(Device2AllPowerOnOthers); // IB80 Bit6(Battery_Max_Charge) 只會讓電池充到50% if (TimerBarcode == null) { TimerBarcode = new System.Windows.Forms.Timer(); } TimerBarcode.Tick += new EventHandler(TimerBarcode_Tick); // 給予使用者指定秒數讓Barcode進行掃描, 時間到就啟動Timer關閉Barcode TimerBarcode.Interval = BarcodeReadTime; if (IsHardwareTrigger) { buttonFAIL.Enabled = true; TimerBarcode.Start(); } else { PublicFunctionBarcode.BarcodeType = Convert.ToUInt16(BarcodeType); if (IsDebugMode) { Trace.WriteLine("Barcod Port : " + PortAddressBarcode + " , Type : " + PublicFunctionBarcode.BarcodeType); } PublicFunctionBarcode.IsdcRsApiInit(); try { barcodeConnect(); } catch (Exception ex) { checkTestStatus(ex.Message); } } }
private void barcodeConnect() { if (IsDebugMode) { Trace.WriteLine("barcodeConnect - Port : " + PortAddressBarcode + " , Type : " + PublicFunctionBarcode.BarcodeType); } try { if (!HotTabDLL.CheckComExist(PortAddressBarcode)) // 檢查指定的Comport是否存在(掃描Barcode Comport,先開啟Comport一次後關閉) { DialogResult dr = ShowDialogMessageBox(PortAddressBarcode + " can't use or not find.", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error); if (dr == DialogResult.OK) { checkTestStatus(PortAddressBarcode + " can't use or not find."); } return; } if (mBarcodePublicFunction != null) { mBarcodePublicFunction.free(); // Release Barcode佔用的資源 mBarcodePublicFunction = null; } if (mBarcodePublicFunction == null) { mBarcodePublicFunction = new PublicFunctionBarcode(PortAddressBarcode, Handle); // 開啟新的COM mBarcodePublicFunction.initinalBarCode(); } if (PublicFunctionBarcode.BarcodeVisible == 0) { if (PublicFunctionBarcode.BarcodeType == 2) { Visible = true; // for ISDC_RS use fixed WM_ISCP_FRAME and WM_RAW_DATA can't receive Thread.Sleep(BarcodeReadTime); } Visible = false; } else { Visible = true; } lblVersionString.Text = mBarcodePublicFunction.GetBarcodeName2(); buttonFAIL.Enabled = true; // 如果沒有Barcode初始化完就可以直接按FAIL buttonScan.Enabled = true; if (mBarcodePublicFunction.IsComportReady() && mBarcodePublicFunction.IsSupportBarCode()) // driver usb-comport ready { textBoxReceiveTag.Focus(); } else if (mBarcodePublicFunction.IsComportReady()) { mBarcodePublicFunction.IsForceOpticonMDI3100(); textBoxReceiveTag.Focus(); } else { ShowDialogMessageBox("Module is instable, please check Device power or relogin Windows", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); checkTestStatus("Module is instable, please check Device power or relogin Windows"); return; } ReadyToScanTag(); } catch (Exception ex) { checkTestStatus("barcodeConnect() Exception : " + ex.Message); ShowDialogMessageBox("barcodeConnect() Exception : " + ex.Message, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }