示例#1
0
        public string ReadBarcode()
        {
            lock (this.lockObj)
            {
                try
                {
                    string reStr     = "";
                    string barCode   = "";
                    int    reworkNum = 0;
                    this.recBuffer.Clear();
                    byte[] readCodeCmd       = null;
                    bool   readCodeCmdStatus = sr750Dev.ReadCodeCmd(ref readCodeCmd);
                    if (readCodeCmdStatus == false)
                    {
                        return(string.Empty);
                    }
                    this.recvAutoEvent.Reset();
                    if (this.mySocket.Send(readCodeCmd, ref reStr) == false)
                    {
                        ShowLog("发送读取条码命令失败!");
                    }
                    ShowLog("发送读取条码命令:" + DataConvert.ByteToHexStr(readCodeCmd));

                    if (this.recvAutoEvent.WaitOne(TIMEWAITOUT) == true)
                    {
                        while (reworkNum < MAXREWORKNUM)
                        {
                            if (this.sr750Dev.ReadCodeCmdReponse(this.recBuffer.ToArray(), ref barCode, ref reStr) == false)
                            {
                                reworkNum++;
                                ShowLog("接收条码数据数据:" + DataConvert.AsciiBytesToHex(this.recBuffer.ToArray()));
                                System.Threading.Thread.Sleep(WAITTIME);
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (reworkNum >= MAXREWORKNUM)
                        {
                            ShowLog("接收条码数据数据错误!");
                            return(string.Empty);
                        }
                        CloseScan();
                        return(barCode);
                    }
                    else
                    {
                        CloseScan();
                        reStr = "接收条码数据超时!";
                        return(string.Empty);
                    }
                }
                catch
                {
                    CloseScan();
                    return(string.Empty);
                }
            }
        }
示例#2
0
        public bool StopReadCodeCmdResponse(byte[] recBytes, ref string reStr)
        {
            string recStr = DataConvert.AsciiBytesToHex(recBytes).ToUpper();

            if (recStr != ERROR)
            {
                return(false);
            }
            return(true);
        }
示例#3
0
        public bool ReadCodeCmdReponse(byte[] recBytes, ref string barcode, ref string reStr)
        {
            barcode = DataConvert.AsciiBytesToHex(recBytes).Trim();

            //if (barcode.Length < PROLENTH)
            //{
            //    reStr = "接收数据协议长度错误!";
            //    return false;
            //}
            barcode = barcode.Substring(0, PROLENTH);
            return(true);
        }