Esempio n. 1
0
        private bool ExecuteCMD(string tCMD)
        {
            if (m_Reader == null)
            {
                return(false);
            }
            byte[] aFieldSeparator = { (byte)' ' };
            byte[] aRespBuf;
            string tMsg = null;

            logThis("Sending->" + tCMD);
            try
            {
                if (m_Reader.IsConnected)
                {
                    tMsg = m_Reader.Execute(tCMD);
                }
                else
                {
                    logThis("Reader disconnected, please Connect");
                    return(false);
                }
            }
            catch (BasicReaderException eBRI)
            {
                logThis("BasicReaderException: " + eBRI.ToString());
                return(false);
            }
            catch (System.NullReferenceException nr)
            {
                logThis("Null Ref Exception: " + nr.Message);
                logThis("stack: " + nr.StackTrace);
                return(false);
            }

            // if tags were successfully read
            if (tMsg.IndexOf("BRI ERR") >= 0)
            {
                System.Diagnostics.Debugger.Break();
            }
            //"H112233445566778899001122 HE2001040\r\nOK>"
            // System.Diagnostics.Debug.WriteLine("Msg: "+tMsg);
            //Show TAG ID
            #region READ EPCID/TAGID
            if (sCurrentCMD.StartsWith("READ "))     //TAGID
            {
                if (tMsg.IndexOf("RDERR") >= 0)
                {
                    //ChangeStatus(eStatus.TagReadError);
                    return(false);
                }
                aRespBuf = tools.StrToByteArray(tMsg);
                tags     = BRIParser.GetTags(aRespBuf, aFieldSeparator);
                System.Diagnostics.Debug.WriteLine("tags.Length: " + tags.Length);

                if (tags == null)
                {
                    return(false);
                }
                System.Diagnostics.Debug.WriteLine("Msg: " + tMsg);
#if !NORMALTAG
                #region ReadUserMemory
                // remove newline and carriage returns
                tMsg = tMsg.Replace('\n', ' ');
                tMsg = tMsg.Replace("\r", "");
                string[] ids = tMsg.Split(' ');
                // get the even arguments only
                System.Diagnostics.Debug.WriteLine("id num " + ids.Length);
                if (ids.Length > 1)
                {
                    for (int j = 1; j < ids.Length; j += 2)
                    {
                        // System.Diagnostics.Debug.WriteLine("tag " +j+"  "+ tags[j].ToString());
                        string s = ids[j];
                        System.Diagnostics.Debug.WriteLine(j + "  Read id: " + s);
                        s = s.Substring(1, s.Length - 1);

                        for (int i = 0; i < s.Length; i++)
                        {
                            // remove first part of byte '3'
                            if (s.Substring(i, 1) == "3")
                            {
                                s = s.Remove(i, 1);
                            }
                            else
                            {
                                // chop off ending zeroes
                                s = s.Substring(0, i);
                                break;
                            }
                            //System.Diagnostics.Debug.WriteLine(i+"  length: "+start.Length+"   newString " + start);
                        }
                        // make multiple tags comma delimited
                        string sOut = "";
                        if (s.Length > 1)
                        {
                            //if (j != ids.Length - 2) s = s + ",";
                            for (int i = 0; i < tags.Length; i++)
                            {
                                sOut += s[i];
                                if (i != s.Length - 1)
                                {
                                    sOut += ",";
                                }
                            }
                            s = sOut;
                        }
                        __MyEvent(this, new MyEventArgs(s));
                    }
                }
                #endregion
#else
                #region ReadNormalTagMemory
                // make multiple tags comma delimited
                string sOut = "";
                if (tags.Length > 1)
                {
                    //if (j != ids.Length - 2) s = s + ",";
                    for (int i = 0; i < tags.Length; i++)
                    {
                        sOut += tags[i];
                        if (i != tags.Length - 1)
                        {
                            sOut += ",";
                        }
                    }
                }
                else
                {
                    sOut = tags[0].ToString();
                }
                __MyEvent(this, new MyEventArgs(sOut));
                #endregion
#endif

                /*
                 #region READ single TAG
                 * if (tags.Length == 1)
                 * {
                 *  //read data from the tag
                 *  System.Diagnostics.Debug.WriteLine("READ TAGID tag data: " + tags[0].ToString());
                 * }
                 #endregion
                 * /
                 *
                 * //read tag data (aka EPCID)
                 * /*
                 * if (tMsg.StartsWith("H"))
                 * {
                 *  string s;
                 *  s = tMsg.Substring(1, 24);
                 *  System.Diagnostics.Debug.WriteLine("Read data: " + s);
                 *  string[] args = tMsg.Split(' ');
                 *  if (args.Length > 1)
                 *  {
                 *      System.Diagnostics.Debug.WriteLine("Arg 2: " + args[1]);
                 *      string start = args[1].Substring(1,args[1].Length-1);
                 *
                 *      for (int i = 0; i < start.Length; i++)
                 *      {
                 *          start = start.Remove(i, 1);
                 *          //System.Diagnostics.Debug.WriteLine(i+"  length: "+start.Length+"   newString " + start);
                 *      }
                 *      System.Diagnostics.Debug.WriteLine("final ver " + start);
                 *
                 *      __MyEvent(this, new MyEventArgs(start));
                 *  }
                 *  //txtTagID.Text = s;
                 * }
                 */
            }
            #endregion
            #region ATTRIB
            if (sCurrentCMD.Equals("ATTRIB TAGTYPE=EPCC1G2") == true)
            {
                if (tMsg.IndexOf("OK") >= 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if ((tMsg.IndexOf("ERR") >= 0) & (sCurrentCMD.Equals("ATTRIB SCHEDOPT=1") == false))
            {
                //MessageBox.Show("Warning, BRI ERR occured for: " + tCMD + "\r\n" + tMsg);
                logThis("BRI ERR for: " + tCMD + "\r\n" + tMsg);
                return(false);
            }
            #endregion
            return(true);
        }
Esempio n. 2
0
        private bool ExecuteCMD(string tCMD)
        {
            string tMsg = null;

            Add2List("Sending->" + tCMD);
            try
            {
                if (m_Reader.IsConnected)
                {
                    tMsg = m_Reader.Execute(tCMD);
                }
                else
                {
                    ChangeStatus(eStatus.Offline);
                    Add2List("Reader disconnected, please Connect");
                    return(false);
                }
            }
            catch (BasicReaderException eBRI)
            {
                Add2List("BasicReaderException: " + eBRI.ToString());
                //MessageBox.Show("BasicReaderException: IDL ERR occured for CMD: " + tCMD + "\r\n" + eBRI.ToString());
                ChangeStatus(eStatus.Offline);
                return(false);
            }
            //"H112233445566778899001122 HE2001040\r\nOK>"
            Add2List("--->" + tMsg);
            //Show TAG ID
            if (sCurrentCMD.Equals("READ TAGID"))
            {
                sbyte[] aFieldSeparator = { (sbyte)' ' };
                sbyte[] aRespBuf        = tools.StrToSByteArray(tMsg);
                Tag[]   tags            = BRIParser.GetTags(aRespBuf, aFieldSeparator);
                if (tags == null)
                {
                    return(false);
                }
                if (tags.GetLength(0) == 1)
                {
                    //only one tag should be visible
                    //save the last 22Bits as Box ID
                    if (VWGTLTAG.IsValidTag(tags[0].ToString()) == false)
                    {
                        DialogResult ant = MessageBox.Show("Tag does not meet specs. Overwrite?", "VW tag demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                        if (ant == DialogResult.Yes)
                        {
                            UInt32 uBox = vwTag.BoxID;
                            vwTag       = new VWGTLTAG();
                            vwTag.BoxID = uBox;
                        }
                        else
                        {
                            ChangeStatus(eStatus.InvalidTag);
                            return(false);
                        }
                    }
                    else
                    {
                        vwTag = new VWGTLTAG(tags[0].ToString()); //create a new tag with the tag data read
                    }
                    //read the box id from the tag
                    iCurrentBoxID = vwTag.BoxID;
                    txtBoxID.Text = iCurrentBoxID.ToString();

                    //fill txtbox with data from tag
                    txtTagDataStr.Text = vwTag.sFilter + " " +
                                         vwTag.iSupplierID.ToString() + " " +
                                         vwTag.iItemNumber.ToString();

                    System.Diagnostics.Debug.WriteLine("READ TAGID tag data: " + vwTag.ToString());
                    //tagKey is the same as tag data
                    //System.Diagnostics.Debug.WriteLine("READ TAGID: tags[0].tagkey: " + tools.Hex2Asc(sByteArrayToString(tags[0].TagKey)));

                    //store TAGID
                    sHexCurrentTagID = tags[0].TagFields.FieldArray[0].DataString.Substring(1);
                    ChangeStatus(eStatus.WriteTag);
                }
                else
                {
                    //only one tag should be visible
                    ChangeStatus(eStatus.TooManyTags);
                }

                //read tag data (aka EPCID)
                if (tMsg.StartsWith("H"))
                {
                    string s;
                    s = tMsg.Substring(1, tMsg.IndexOf(" ") - 1);
                    txtTagData.Text = s;
                    s             = tMsg.Substring(s.Length + 1);
                    s             = tools.CopyToR(s);
                    s             = s.Substring(s.IndexOf("H") + 1);
                    txtTagID.Text = s;
                }
            }

            if (sCurrentCMD.Equals("ATTRIB TAGTYPE=EPCC1G2") == true)
            {
                if (tMsg.IndexOf("OK") >= 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (tMsg.IndexOf("ERR") >= 0 && sCurrentCMD.Equals("ATTRIB SCHEDOPT=1") == false)
            {
                //MessageBox.Show("Warning, BRI ERR occured for: " + tCMD + "\r\n" + tMsg);
                Add2List("Warning, BRI ERR occured for: " + tCMD + "\r\n" + tMsg);
                return(false);
            }

            if (sCurrentCMD.StartsWith("W "))
            {
                if (tMsg.IndexOf("ERR") >= 0 && CurrentStatus == eStatus.WriteTag)
                {
                    ChangeStatus(eStatus.WriteTagError);
                    return(false);
                }

                if (tMsg.IndexOf("WROK") >= 0 && (CurrentStatus == eStatus.WriteTagError) || (CurrentStatus == eStatus.WriteTag))
                {
                    HighBeep.Play();
                    ChangeStatus(eStatus.ReadBarcode);
                    if (tMsg.StartsWith("H"))//"H303033353032393035343135 HE2001040 WROK\r\nOK>"
                    {
                        string s;
                        s = tMsg.Substring(1, tMsg.IndexOf(" ") - 1);
                        txtTagData.Text = s;
                        System.Diagnostics.Debug.WriteLine("WROK: tag data string: " + s);
                        s = tMsg.Substring(s.Length + 1);
                        s = tools.CopyToR(s);
                        s = s.Substring(s.IndexOf("H") + 1);
                        //"E2001040 WROK"
                        txtTagID.Text = s.Substring(1, s.IndexOf(" ") - 1);
                        System.Diagnostics.Debug.WriteLine(s);
                    }
                }
            }
            return(true);
        }