private void ReadBarcode() { byte[] ReceiveBuf; byte[] CountBuf; ReceiveBuf = new byte[128]; CountBuf = new byte[1]; while (true) { if (paused) { resumeEvent.WaitOne(); paused = false; } int uiState = Se955.Se955GetDecodeData(ReceiveBuf, CountBuf); if (uiState == 52 /*RECEIVE_SUCCESS*/) { strDisp = ""; Buzzer.BeepOK(); int count = CountBuf[0]; for (int i = 0; i < count; i++) { strDisp += (char)ReceiveBuf[i]; } Pause(); } Thread.Sleep(2); } }
private void Scan_Closed(object sender, EventArgs e) { Se955.Se955SerialTerminate(); if (readThread != null) { readThread.Abort(); } }
private void Scan_KeyUp(object sender, KeyEventArgs e) { if (e.KeyData == Keys.F20) { int ret = Se955.Se955DecodeState(false); if (ret != 47 /*SUCCESS_SETTING*/ && ret != 55 /*ACK_FAILED*/) { string str = ""; if (ret == 53 /*DATA_ERR_SELECT*/) { str = "发送数据错误"; } MessageBox.Show(str); bnExit_Click(null, null); } resumeEvent.Set(); State = false; } }
public Scan() { InitializeComponent(); if (Se955.Se955SerialInit(4 /*com2*/, 0x06 /*B_RATE9600*/, 0x01 /*STOP_BITONE*/, 0x04 /*DAT_NONE*/) != 50 /*INIT_OK*/) { MessageBox.Show("启动通信失败"); //bnExit_Click(null, null); } resumeEvent = new ManualResetEvent(false); resumeEvent.Reset(); paused = true; readThread = new Thread(new ThreadStart(ReadBarcode)); readThread.Start(); //Pause(); ExePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); bmp_up = new Bitmap(ExePath + @"\up-ReadBarcode.bmp"); bmp_down = new Bitmap(ExePath + @"\down-ReadBarcode.bmp"); KeyPreview = true; }