Exemplo n.º 1
0
        private int ReadTagChange(OpcNodeId nodeId)
        {
            try
            {
                ServiceConfig.Reader readerConfig = null;
                foreach (var serviceConfig in RfidService.ServiceConfigs)
                {
                    readerConfig =
                        serviceConfig.Readers.FirstOrDefault(reader =>
                                                             reader.Tags.ReaderTag.ReadTag == nodeId.ToString());
                    if (readerConfig != null)
                    {
                        break;
                    }
                }

                if (readerConfig == null)
                {
                    _eventLog.WriteEntry("Unable to find matching config. Check system settings.", EventLogEntryType.Error, (int)EventIds.Ids.NullReaderError);
                    _client.WriteNode(nodeId, false);
                    return(1);
                }

                using (var reader = new RfidReader(readerConfig, ref _eventLog))
                {
                    if (!reader.GetStatus())
                    {
                        _client.WriteNode(readerConfig.Tags.ErrorTag.ErrorBool, true);
                        _client.WriteNode(readerConfig.Tags.ErrorTag.ErrorString, "Reader not online!");
                        _client.WriteNode(nodeId, false);
                        return(1);
                    }

                    var nodeVal = reader.Read_Epc();
                    if (string.IsNullOrEmpty(nodeVal))
                    {
                        _client.WriteNode(readerConfig.Tags.ErrorTag.ErrorBool, true);
                        _client.WriteNode(readerConfig.Tags.ErrorTag.ErrorString, "No Tags Detected!");
                        _client.WriteNode(readerConfig.Tags.UuidTag.UuidTag, string.Empty);
                    }
                    else
                    {
                        _client.WriteNode(readerConfig.Tags.UuidTag.UuidTag, nodeVal);
                    }
                    _client.WriteNode(nodeId, false);
                }
                return(0);
            }
            catch (Exception e)
            {
                _eventLog.WriteEntry($"Unknown Error\n{e.Message}\n{e.StackTrace}\n\n{e.InnerException}", EventLogEntryType.Error, (int)EventIds.Ids.UnknownError);
                return(1);
            }
        }
Exemplo n.º 2
0
 public RfidReader(ServiceConfig.Reader readerConfig, ref EventLog log)
 {
     _eventLog = log;
     try
     {
         var connected = Connect(readerConfig.Address, readerConfig.PortNum);
         if (connected != 0x35 || connected != 0x00) //Success
         {
             _eventLog.WriteEntry($"Unsuccessfully Connected\n{EventIds.GetReturnCodeDesc(connected)}", EventLogEntryType.FailureAudit, (int)EventIds.Ids.UnsuccessfulRFIDConnection);
         }
     }
     catch (Exception e)
     {
         _eventLog.WriteEntry($"Unknown Error\n{e.Message}\n{e.StackTrace}\n\n{e.InnerException}", EventLogEntryType.Error, (int)EventIds.Ids.UnknownError);
     }
 }