public static bool EndReadBcr(object sStn) { SocketPort dPort = (SocketPort)(hBcrPort[sStn]); bool bRec = true; if (dPort.bStart == false) { return(false); } Byte[] pBuf = new Byte[50]; Array.Clear(pBuf, 0, 50); try { pBuf[0] = 0x02; pBuf[1] = 0x32; pBuf[2] = 0x32; pBuf[3] = 0x03; dPort.Write(pBuf, 0, 4); dPort.bStart = false; Thread.Sleep(2); } catch (Exception ex) { Log.WriteLog(cLog.Exception, ex.Message + "\r\n" + ex.StackTrace); bRec = false; } return(bRec); }
public static string ReadBcr(object sStn) { SocketPort dPort = (SocketPort)(hBcrPort[sStn]); string strValue = string.Empty; Byte[] pBuf = new Byte[4]; Array.Clear(pBuf, 0, 4); try { if (dPort.bStart == false) { dPort.ClearReadBuffer(); pBuf[0] = 0x02; pBuf[1] = 0x32; pBuf[2] = 0x31; pBuf[3] = 0x03; dPort.Write(pBuf, 0, 4); dPort.bStart = true; Thread.Sleep(2); } strValue = dPort.Read(); Log.WriteLog(cLog.RunLog, string.Format("Stn:{0} 读条码原始:{1}", sStn, strValue)); while (strValue.Length > 10) { if (strValue.StartsWith(sBcrHead)) { if (strValue.Length >= 16) { if (strValue.Substring(15, 1) == sBcrEnd) { dPort.bStart = false; strValue = strValue.Substring(9, 6); } else { dPort.DiscaredChars(4); //continue; } } else { strValue = string.Empty; } break; } else { dPort.DiscaredChars(1); } strValue = dPort.GetReaded(); } } catch (Exception ex) { Log.WriteLog(cLog.Exception, ex.Message + "\r\n" + ex.StackTrace); strValue = string.Empty; } if (strValue.Length != 6) { strValue = string.Empty; } return(strValue); }