/// <summary> /// Sets the NurApi. /// </summary> /// <param name="hNur">The handle of NurApi.</param> public void SetNurApi(NurApi hNur) { try { this.hNur = hNur; // Set event handlers for NurApi hNur.DisconnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_DisconnectedEvent); hNur.ConnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_ConnectedEvent); // Update the status of the connection if (hNur.IsConnected()) { hNur_ConnectedEvent(hNur, null); } else { hNur_DisconnectedEvent(hNur, null); } } catch (NurApiException ex) { MessageBox.Show(ex.ToString(), Program.appName); } }
/// <summary> /// Handles the InventoryStreamEvent event of the hNur control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="NurApi.InventoryStreamEventArgs"/> instance containing the event data.</param> void hNur_InventoryStreamEvent(object sender, NurApi.InventoryStreamEventArgs e) { try { NurApi hNur = sender as NurApi; if (e.data.tagsAdded > 0) { NurApi.TagStorage inventoriedTags = hNur.GetTagStorage(); int numberOfNewTag = nxpTagListView.UpdateTagList(inventoriedTags); //beeperInventory.Beep(numberOfNewTag); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), Program.appName); } // Restart if stopped by TimeLimit if (e.data.stopped && continueInventory) { StartPsfInventory(); } //Keepd device alive HHUtils.KeepDeviceAlive(); }
public Form1() { InitializeComponent(); try { // Create NurApi instance with this form as notification receiver. // This will make all events to be called in UI thread context hNur = new NurApi(this); // Add event handler for receiving connected and disconnected status hNur.ConnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_ConnectedEvent); hNur.DisconnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_DisconnectedEvent); // Add inventory stream event, event is called when there's tags available hNur.InventoryStreamEvent += new EventHandler <NurApi.InventoryStreamEventArgs>(hNur_InventoryStreamReady); // Set window title UpdateAppTitle(); } catch (Exception ex) { // Handle error MessageBox.Show("Could not initialize NurApi, error: " + ex.ToString(), "Error"); Application.Exit(); } }
public Form1() { InitializeComponent(); try { // Create NurApi instance with this form as notification receiver. // This will make all events to be called in UI thread context hNur = new NurApi(this); // Set window title this.Text = "NurAPI Dll Version: " + hNur.GetFileVersion() + " (Disconnected)"; // Add event handler for receiving connected and disconnected status hNur.ConnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_ConnectedEvent); hNur.DisconnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_DisconnectedEvent); // Add inventory stream event, event is called when there's tags available hNur.InventoryStreamEvent += new EventHandler <NurApi.InventoryStreamEventArgs>(hNur_InventoryStreamReady); // Starts connecting to USB automatically. Keeps up connection until SetUsbAutoConnect(false) called. hNur.SetUsbAutoConnect(true); } catch (Exception ex) { // Handle error MessageBox.Show("Could not initialize NurApi, error: " + ex.ToString(), "Error"); Application.Exit(); } }
/// <summary> /// Handles the SelectedTagChanged event of the nxpTagListView control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void nxpTagListView_SelectedTagChanged(object sender, EventArgs e) { // Update tag list NurApi.Tag selectedTag = nxpTagListView.SelectedTag; if (selectedTag != null) { // Get EPC from selection byte[] targetEPC = selectedTag.epc; // Fill TargerTag fied targetEpcTextBox.Text = NurApi.BinToHexString(targetEPC); try { // Read NXP configuration word byte[] confWord = hNur.ReadSingulatedTag(0, false, NurApi.BANK_EPC, 32, selectedTag.epc, NurApi.BANK_EPC, 0x200 / 16, 2); configurationLabel.Text = "0x" + NurApi.BinToHexString(confWord); } catch (NurApiException) { configurationLabel.Text = "???"; } } // Update button(s) UpdateButtons(); }
/// <summary> /// Handles the DisconnectedEvent event of the NUR module. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="NurApi.NurEventArgs" /> instance containing the event data.</param> private void hNur_DisconnectedEvent(object sender, NurApi.NurEventArgs e) { NurApi hNur = sender as NurApi; conStatusDesc.Text = "Disconnected"; UpdateButtons(); }
private BitBuffer BuildCommand2(byte cmdValue, List <BitEntry> entries) { NurApi curApi = hApi != null ? hApi : hLocalApi; int localLen = 0; BitBuffer bb = new BitBuffer(); bb.bytes = new byte[NurApi.MAX_BITSTR_BITS / 8]; bb.actualLength = 0; localLen = NurApi.BitBufferAddValue(bb.bytes, CUSTOM_CMD_VALUE, 8, localLen); localLen = NurApi.BitBufferAddValue(bb.bytes, cmdValue, 8, localLen); if (entries != null) { foreach (BitEntry be in entries) { if (be.isEBV) { localLen = NurApi.BitBufferAddEBV32(bb.bytes, be.paramValue, localLen); } else { localLen = NurApi.BitBufferAddValue(bb.bytes, be.paramValue, be.bitLen, localLen); } } } bb.actualLength = localLen; return(bb); }
/// <summary> /// Sets the NurApi. /// </summary> /// <param name="hNur">The handle of NurApi.</param> public void SetNurApi(NurApi hNur) { try { this.hNur = hNur; // Set event handlers for NurApi hNur.DisconnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_DisconnectedEvent); hNur.ConnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_ConnectedEvent); hNur.InventoryStreamEvent += new EventHandler <NurApi.InventoryStreamEventArgs>(hNur_InventoryStreamEvent); hNur.TriggerReadEvent += new EventHandler <NurApi.TriggerReadEventArgs>(hNur_TriggerReadEvent); hNur.IOChangeEvent += new EventHandler <NurApi.IOChangeEventArgs>(hNur_IOChangeEvent); // Update the status of the connection if (hNur.IsConnected()) { hNur_ConnectedEvent(hNur, null); } else { hNur_DisconnectedEvent(hNur, null); } } catch (NurApiException ex) { MessageBox.Show(ex.ToString(), Program.appName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Starts the locating. /// </summary> /// <returns>true if succeed</returns> private bool StartLocating() { // Set a new target locatorTarget.Bank = bankCB.SelectedIndex; locatorTarget.Address = (int)startUD.Value; locatorTarget.Length = (int)lengthUD.Value; locatorTarget.Mask = NurApi.HexStringToBin(tagToLocate.Text); // Is Locator running if (IsRunning) { return(false); } // Initialize locator IsRunning = true; keepLocating = true; updTxLevel = -1; updScaledRSSI = -1; locatingSignal.NumberOfAntennas = hNur.GetReaderInfo().numAntennas; // Start beeper and so on updateTimer.Enabled = true; beeperLocator.Start(); // Create and start Locator thread Thread locateThread = new Thread(LocateThread); locateThread.IsBackground = true; locateThread.Start(); return(true); }
private async void DevWatcher_DeviceAdded(object sender, NurDeviceWatcherInfo e) { // Create new api instance for known device NurApi api = new NurApi(); api.UserData = e; e.Tag = api; AttachNurApiEvents(api); // We must update the collection on the UI thread because the collection is databound to a UI element. await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { // Attempt to find known device with same address // This might be true, if known device is added manually NurDeviceWatcherInfo devToDelete = null; foreach (var dev in KnownDevices) { if (dev.Address == e.Address) { devToDelete = dev; break; } } if (devToDelete != null) { DevWatcher_DeviceRemoved(sender, devToDelete); } KnownDevices.Add(e); }); }
public MainForm() { InitializeComponent(); ScanBtn.Enabled = false; AntennaBtn.Enabled = false; RefreshBtn.Enabled = false; DelaySel.SelectedIndex = 1; IntvalSel.SelectedIndex = 0; TxModSel.SelectedIndex = 0; GetSetupBtn.Enabled = false; SetSetupBtn.Enabled = false; CreateInvokers(); hNur = new NurApi(this); hNur.ConnectedEvent += new EventHandler <NurApi.NurEventArgs>(OnModuleConnect); hNur.DisconnectedEvent += new EventHandler <NurApi.NurEventArgs>(OnModuleDisconnect); _SetControlText(ConnLabel, "Not connected"); _SetControlColor(ConnLabel, RED, BLACK); _SetControlText(TagLabel, "No tag"); _SetControlColor(TagLabel, RED, BLACK); ConnGrp.Text = "Connection (" + NurApi.FileVersion + ", " + hNur.GetFileVersion() + ")"; StatesNotAvailable(false); mDownload = new DownloadDelegate(DownloadAndShow); hNur.SetUsbAutoConnect(true); }
public MainForm() { InitializeComponent(); // Read previous settings ethAddr.Text = Properties.Settings.Default.EthAddr; ethPort.Value = Properties.Settings.Default.EthPort; try { // Create nur api mApi = new NurApi(this); mApi.ConnectedEvent += mApi_ConnectedEvent; mApi.DisconnectedEvent += mApi_DisconnectedEvent; mApi.TagTrackingChangeEvent += hNur_TagTrackingChangeEvent; mApi.TagTrackingScanEvent += mApi_TagTrackingScanEvent; mApi.SetLogLevel(NurApi.LOG_VERBOSE | NurApi.LOG_ERROR); mApi.LogEvent += mApi_LogEvent; ResizeTagView(); ResizeSectorView(); // Not connected status SetInfo("Status", "Disconnected"); label1.Visible = false; startbutton.Enabled = false; } catch (Exception ex) { MessageBox.Show("ERROR: " + ex.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } }
/// <summary> /// This sample code demonstrates how to use the NurApiTagTracking-features as a GateReader. The feature operates so that /// When the tag moves from one of the inAntennas to outAntennas or vice versa and then the tag moves out of the RF-field, /// TagTracking will report a TTEV_INOUT event for the tag informing that the tag has moved from in to out or from out to in. /// The tag data contains also the antennaIds where the tag was seen first and last. /// </summary> public Form1() { InitializeComponent(); // Read previous settings ethAddr.Text = Properties.Settings.Default.EthAddr1; ethPort.Value = Properties.Settings.Default.EthPort2; try { // Create nur api mApi = new NurApi(this); mApi.ConnectedEvent += mApi_ConnectedEvent; mApi.DisconnectedEvent += mApi_DisconnectedEvent; mApi.TagTrackingChangeEvent += hNur_TagTrackingChangeEvent; mApi.SetLogToFile(false); //ResizeAntennaView(); // Not connected status SetInfo("Status", "Disconnected"); startbutton.Enabled = false; } catch (Exception ex) { MessageBox.Show("ERROR: " + ex.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } }
private void DoResetAlarms() { if (TagReady) { EM4325Tag.ConfigData cfg; try { cfg = CurrentTag.Configuration; AddLog("Can reset alarms: " + YesNo(cfg.resetEn)); AddLog("Bytes: "); AddLog(NurApi.BinToHexString(cfg.raw)); } catch (Exception e) { AddLog("Configuration read error: " + e.Message); } AddLog("Resetting alarms from " + CurrentTag.GetEpcString()); if (CurrentTag.ResetAlarms()) { AddLog("Alarms are reset."); } else { AddLog("Resetting alarms failed."); } } }
private void LogEvent(NurApi.TagTrackingChangeEventArgs e) { DateTime now = DateTime.Now; listbox_events.Items.Add(String.Format("{0:H:mm:ss}", now) + "\tchangedEventMask" + e.data.changedEventMask.ToString() + "\treadSource " + e.data.readSource.ToString() + "\tstopped " + e.data.stopped.ToString() + "\tchangedCount " + e.data.changedCount.ToString()); if ((e.data.changedEventMask & NurApi.TTEV_INOUT) != 0) { listbox_events.Items.Add(String.Format("{0:H:mm:ss}", now) + "\t TTEV_INOUT"); foreach (NurApi.TagTrackingTag tag in e.tags) { if ((tag.changedEvents & NurApi.TTEV_INOUT) != 0) { listbox_events.Items.Add(String.Format("{0:H:mm:ss}", now) + "\t" + NurApi.BinToHexString(tag.epc, tag.epcLen) + "\t TTEV_INOUT" + "\t direction " + tag.directionTTIO.ToString() + "\t first " + tag.firstTTIOReadSource.ToString() + "\t second " + tag.secondTTIOReadSource.ToString() + "\t visibility " + tag.visible.ToString()); } } } listbox_events.SelectedIndex = listbox_events.Items.Count - 1; }
public AntennaDlg(NurApi api) { InitializeComponent(); hNur = api; SettingsToControls(); EnableOkApplyBySelections(); }
private void Form1_Load(object sender, EventArgs e) { // Discover devices from the network new Thread(delegate() { try { // Run one Ethernet device discovery. The devices are received via device search // event. This is a synchronoous (blocking) call and return when the one discovery // operation is finished. genNurApi.DiscoverDevices(2000); } catch (Exception) { } }).Start(); // Connect to all reader that are found from the USB ports List <NurApi.UsbDevice> ports = NurApi.EnumerateUsbDevices(); for (int i = 0; i < ports.Count; i++) { nurApis.Add(new NurApi(this)); nurApis[i].ConnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_ConnectedEvent); nurApis[i].DisconnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_DisconnectedEvent); nurApis[i].InventoryStreamEvent += new EventHandler <NurApi.InventoryStreamEventArgs>(hNur_InventoryStreamReady); try { nurApis[i].ConnectUsb(ports[i].devPath); } catch (NurApiException) { } } }
// Inventory stream event, this is called when there's tags available in NurApi tag storage void hNur_InventoryStreamReady(object sender, NurApi.InventoryStreamEventArgs e) { // Get NurApi object that generated the event NurApi hNur = sender as NurApi; try { // Copy tags from NurApi internal tag storage to application tag storage NurApi.TagStorage intTagStorage = hNur.GetTagStorage(); lock (intTagStorage) { SendMessage(string.Format("Reader: {0}, Tags: {1}", hNur.GetReaderInfo().altSerial, intTagStorage.Count)); // Clear NurApi internal tag storage hNur.ClearTags(); } if (e.data.stopped) { // Start streaming again if stopped hNur.StartInventoryStream(); } } catch (Exception ex) { // Handle error SendMessage(ex.Message); } }
void hNur_TriggerReadEvent(object sender, NurApi.TriggerReadEventArgs e) { NurApi hNur = sender as NurApi; if (e.data.rssi > -127) { // Tag found byte[] epc = new byte[e.data.epcLen]; Array.Copy(e.data.epc, epc, e.data.epcLen); string eventString = string.Format("{0:N0}: TrigRead: {1} #{2}, Ant #{3}, {4} ({6} Bytes), RSSI {5}%", e.timestamp, e.data.sensor ? "Sensor" : "GPIO", e.data.source, e.data.antennaID, NurApi.BinToHexString(epc), e.data.scaledRssi, e.data.epcLen ); AddToEventList(eventString); } else { // Tag not be found string eventString = string.Format("{0:N0}: TrigRead: TAG NOT BE FOUND", e.timestamp); AddToEventList(eventString); } }
private ushort ReadUint16(NurApi hNur, byte[] epc, byte bank, uint addr) { byte[] rdData; rdData = hNur.ReadTagByEPC(0, false, epc, bank, addr, 2); System.Array.Reverse(rdData); return(BitConverter.ToUInt16(rdData, 0)); }
private ulong ReadULong64(NurApi hNur, byte[] epc, byte bank, uint addr) { byte[] rdData; rdData = hNur.ReadTagByEPC(0, false, epc, bank, addr, 8); System.Array.Reverse(rdData); return(BitConverter.ToUInt64(rdData, 0)); }
public void Config(NurApi hNur) { configuring = true; mApi = hNur; if (mApi != null && mApi.IsConnected()) { for (int n = 0; n < mCheckboxes.Length - 1; n++) { mCheckboxes[n].Checked = mApi.IsPhysicalAntennaEnabled("Beam" + mCheckboxes[n].Text); } try { lbl_eb.Text = "Extra beams"; for (int n = 0; n < mFarBeamCheckboxes.Length; n++) { mFarBeamCheckboxes[n].Checked = mApi.IsPhysicalAntennaEnabled("Beam" + mFarBeamCheckboxes[n].Text); mFarBeamCheckboxes[n].Enabled = true; } } catch { lbl_eb.Text = "Extra beams not available"; for (int n = 0; n < mFarBeamCheckboxes.Length; n++) { mFarBeamCheckboxes[n].Checked = false; mFarBeamCheckboxes[n].Enabled = false; } } } configuring = false; }
public static uint[] ReadDwords(NurApi hApi, byte[] epc, byte bank, uint addr, int dwLength) { byte[] rdData; rdData = ReadBytes(hApi, epc, bank, addr, dwLength * 4); return(BytesToDwords(rdData)); }
public static ushort[] ReadWords(NurApi hApi, byte[] epc, byte bank, uint addr, int wordLength) { byte[] rdData; rdData = ReadBytes(hApi, epc, bank, addr, wordLength * 2); return(BytesToWords(rdData)); }
private SensorValue SensorValueExchange(uint password, bool secured, uint sensorType, bool noSelection) { NurApi hCurApi = hApi != null ? hApi : hLocalApi; SensorValue sv = new SensorValue(); List <BitEntry> entries = new List <BitEntry>(); NurApi.CustomExchangeParams xch; NurApi.CustomExchangeResponse resp; int respLen; uint tmpVal; int ticks; BitBuffer bb; if (hCurApi == null) { throw new NurApiException("SensorValueExchange(): cannot find NurApi."); } entries.Add(BuildEntry(ADD_PARAMETER, sensorType, SENSOR_TYPE_BITS)); bb = BuildCommand(CMD_GETSENSORVAL, entries); /* 0 for possible error reception. */ xch = BuildDefault(bb, 0, false, false); ticks = System.Environment.TickCount; if (noSelection) { resp = hCurApi.CustomExchange(password, secured, xch); } else { resp = hApi.CustomExchangeSingulated(password, secured, NurApi.BANK_EPC, 32, epc.Length * 8, epc, xch); } sv.time = System.Environment.TickCount - ticks; respLen = resp.tagBytes.Length; if (resp.error != NurApiErrors.NUR_NO_ERROR) { if (respLen >= MIN_ERROR_RESP_LENGTH) { InterpretedException("Get sensor value", resp); } DoException("Get sensor value", resp); } tmpVal = resp.tagBytes[0]; tmpVal <<= 8; tmpVal |= resp.tagBytes[1]; sv.adError = IsMaskBitSet(tmpVal, SENSOR_AD_ERR_BIT); sv.rangeOrLimit = ((tmpVal >> SENSOR_RANGE_LSH) & SENSOR_RANGE_MASK_VAL); sv.adValue = (tmpVal & SENSOR_AD_VALMASK); return(sv); }
public Form1() { InitializeComponent(); genNurApi = new NurApi(this); genNurApi.DevInfoEvent += new EventHandler <NurApi.DevInfoEventArgs>(hNur_DevInfoEvent); UpdateAppTitle(); }
public static byte[] ReadBytes(NurApi hApi, byte[] epc, byte bank, uint addr, int byteLength) { hApi.ULog("Read bytes:"); hApi.ULog("EPC = " + NurApi.BinToHexString(epc)); hApi.ULog("SelBank / SelAddr / SelLen / = " + string.Format("{0} / {1} / {2}", NurApi.BANK_EPC, 32, epc.Length * 8)); hApi.ULog("Bank = " + bank + ", addr = 0, byteSize = " + byteLength); return(hApi.ReadSingulatedTag(0, false, NurApi.BANK_EPC, 32, epc.Length * 8, epc, bank, addr, byteLength)); }
public InventoryStreamer(ref NurApi hNur) { totalInvRounds = 0; myNur = hNur; //Copy Nur handler //Create InventoryStream event handler. Remeber to remove it when no longer use. myNur.InventoryStreamEvent += new EventHandler <NurApi.InventoryStreamEventArgs>(InventoryStreamEventHandler); }
public TagItem(NurApi.Tag tag) { this.Tag = tag; this.TagViewItem = new ListViewItem(new string[] { tag.rssi.ToString(), tag.GetEpcString(), tag.irData != null ? NurApi.BinToHexString(tag.irData) : "-" }); this.TagViewItem.Tag = this; }
public Form1() { InitializeComponent(); hNur = new NurApi(this);//Nur Api handle hNur.ConnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_ConnectedEvent); hNur.DisconnectedEvent += new EventHandler <NurApi.NurEventArgs>(hNur_DisconnectedEvent); //When NUR module connected via USB, this function finds it and connects automagically... hNur.SetUsbAutoConnect(true); }