Exemple #1
0
        /// <summary>
        /// Manejador del evento de la respuesta de la lectora
        /// </summary>
        /// <param name="EResponse"></param>
        void ProcessReaderResponse(EReader.Response EResponse)
        {
            try
            {
                //Now when reader response is MSG_OK we will process command.
                //MSG_OK means reader received command successfully and command was executed successfully.
                //It doesn't mean reader was able to read tag (in case of ReadTag() command).
                //It is just indicator of reader tried to read tag successfully.
                //But if we have message other than MSG_OK, it indicates failure.

                if (EResponse.ResponseCode == EReader.CommandCode.MSGOK)
                {
                    //Now parse response as we need
                    //Now most of the command like write tag, write tag memory, set hardware information
                    //just needs confirmation of successfull execution so MSG_OK response indicates success for such commands.
                    //Where as other commands like read tag, read tag memory, get hardware information, get firmware version
                    //response comes back with some kind of data in response to issued command.
                    //For such cases each command has different kind of response, so we need different way to parse it.
                    //We have made this easy for developer by using response class for each specific command.
                    //Here you will see how to use it.


                    //We know the respone is MSG_OK (inside if ) so we can check for command specific response.
                    //Here we have illustrated few commands. You can add more response as you need
                    switch (EResponse.CommandEcho)
                    {
                    case EReader.Command.GET_FIRMWARE_VERSION:
                        //If response is not null then
                        if (EResponse.CommandSpecificResponse != null)
                        {
                            //Now we want to parse specific response as per GET_FIRMWARE_VERSION command
                            //No problem
                            EReader.FirmwareResponse specificRes = (EReader.FirmwareResponse)EResponse.CommandSpecificResponse;     //This is easy
                            //Now you can process values easily Try yourself by typing specificRes.
                            //specificRes.MinorVersion
                        }
                        break;

                    case EReader.Command.READ_TAG:
                        //If response is not null then
                        if (EResponse.CommandSpecificResponse != null)
                        {
                            EReader.ReadTagResponse specificRes = (EReader.ReadTagResponse)EResponse.CommandSpecificResponse;     //This is easy
                            //Now for the case of read_tag command we have to see if we were able to find any tag or not before we can look for tag value
                            if (specificRes.Decode == EReader.ReadTagResponse.TagDecode.GOOD_TAG)
                            {
                                //Hurreyy..we found good tag now we can use tag value for business logic.
                                byte[] bTagData = specificRes.TagData;                //Get tag data as an array
                                string sTagData = Utility.ToHex(specificRes.TagData); //convert tag data as string of Hex
                                string tag      = Utility.ByteToString(bTagData);
                                tag.TrimStart();
                                tag = tag.Replace("\0", "");

                                //MessageBox.Show(this, "Hexa: " + sTagData + "\n" + "Barcode: " + tag, "Lectura", MessageBoxButtons.OK);
                                this.txtCodigoRFID.Text = sTagData;
                            }
                            else
                            {
                                //MessageBox.Show("no tag found. Display proper message");
                                //no tag found. Display proper message.
                            }
                        }
                        break;

                    case EReader.Command.READ_TAG_MEMORY:
                        //As per previous examples
                        if (EResponse.CommandSpecificResponse != null)
                        {
                            EReader.ReadTagMemoryResponse specificRes = (EReader.ReadTagMemoryResponse)EResponse.CommandSpecificResponse;     //This is easy
                            //Now for the case of read_tag command we have to see if we were able to find any tag or not before we can look for tag value
                            if (specificRes.Decode == EReader.ReadTagMemoryResponse.TagDecode.GOOD_TAG)
                            {
                                //Hurreyy..we found good tag now we can use tag value for business logic.
                                byte[] bTagData = specificRes.TagData;                //Get tag data as an array
                                string sTagData = Utility.ToHex(specificRes.TagData); //convert tag data as string of Hex
                            }
                            else
                            {
                                //no tag found. Display proper message.
                            }
                        }
                        break;
                    }
                }
                else
                {
                    //Print error message only in debugging mode
                    MessageBox.Show("Intente la operación nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                //Se guarda log del error
                MessageBox.Show("Ocurrió un error durante la operación d electura", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                string inner = "";
                if (ex.InnerException != null)
                {
                    inner = ex.InnerException.Message;
                }
                this.objUtil.LogError("Camiones", "ProcessReaderResponse", ex.Message, inner, CGlobal.IdUsuario);
            }
        }
Exemple #2
0
 void mReader_ReaderResponse(EReader.Response EResponse)
 {
     this.Invoke(new dlProcessResponse(ProcessReaderResponse), new object[] { EResponse });
 }