コード例 #1
0
 // This gets called when module is connected
 void nur_ConnectedEvent(object sender, NurApi.NurEventArgs e)
 {
     // Connected, display module info
     NurApi.ReaderInfo ri = nur.GetReaderInfo();
     lstbox.Items.Add(ri.name + " connected");
     lstbox.Items.Add("Version: " + ri.GetVersionString());
 }
コード例 #2
0
        // This is called when NurApi is fully connected to device and ready to communicate
        private async void MApi_ConnectedEvent(object sender, NurApi.NurEventArgs e)
        {
            // Update reader info, run in task because NurApi calls may block
            await Task.Run(async() =>
            {
                try
                {
                    NurApi.ReaderInfo rdrInfo = mApi.GetReaderInfo();

                    // Update UI in UI thread
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        // Update listview item
                        if (mConnectedDev != null)
                        {
                            mConnectedDev.ConnState = NurApiTransport.State.Connected;
                            mConnectedDev.UpdateInfo();
                        }

                        // Update UI
                        ConnInfo.Text             = string.Format("Connected {0}  |  Serial {1}  |  FW {2}", rdrInfo.name, rdrInfo.serial, rdrInfo.GetVersionString());
                        InventoryButton.IsEnabled = true;
                        ConnButton.Content        = "Disconnect";
                    });
                }
                catch (Exception ex)
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        ConnInfo.Text = "Error " + ex.ToString();
                    });
                }
            });
        }
コード例 #3
0
        private void UpdateReaderInformation()
        {
            try
            {
                NurApi.ReaderInfo        readerInfo = hNur.GetReaderInfo();
                NurApi.DeviceCapabilites deviceCaps = hNur.GetDeviceCaps();

                AddLog(string.Format("Device: {0} - {1}",
                                     readerInfo.name,
                                     readerInfo.altSerial
                                     ));

                if ((deviceCaps.secChipMajorVersion != 0 ||
                     deviceCaps.secChipMinorVersion != 0) &&
                    deviceCaps.secChipMinorVersion != 255)
                {
                    AddLog(string.Format("Firmware: {0} / {1}.{2}.{3}.{4}",
                                         readerInfo.GetVersionString(),
                                         deviceCaps.secChipMajorVersion, deviceCaps.secChipMinorVersion,
                                         deviceCaps.secChipMaintenanceVersion, deviceCaps.secChipReleaseVersion));
                }
                else
                {
                    AddLog("Firmware: " + readerInfo.GetVersionString());
                }
            }
            catch (NurApiException e)
            {
                AddLog("Update reader information failed, error: " + e.error + ".");
                AddLog("Message: " + e.Message);
            }
        }
コード例 #4
0
        /// <summary>
        /// Handles the ConnectedEvent event of the hNur control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="NurApi.NurEventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        void hNur_ConnectedEvent(object sender, NurApi.NurEventArgs e)
        {
            if (hNur != null && hNur.IsConnected())
            {
                try
                {
                    // Get the ReaderInfo
                    readerInfo = hNur.GetReaderInfo();
                }
                catch (NurApiException)
                {
                    // Firmware may be too old so use the defaults
                    readerInfo.name = NA;
                }

                try
                {
                    // Get the Device Capabilites
                    devCaps = hNur.GetDeviceCaps();
                    if (devCaps.txAttnStep == 3)
                    {
                        throw new Exception("Firmware may be too old so use the defaults");
                    }
                }
                catch (Exception)
                {
                    // Firmware may be too old so use the defaults
                    devCaps.maxTxmW    = 500;
                    devCaps.maxTxdBm   = 27;
                    devCaps.txAttnStep = 1;
                    devCaps.txSteps    = 20;
                    devCaps.maxAnt     = 4;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Handles the ConnectedEvent 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_ConnectedEvent(object sender, NurApi.NurEventArgs e)
        {
            NurApi hNur = sender as NurApi;

            NurApi.ReaderInfo readerInfo = hNur.GetReaderInfo();
            this.Text = string.Format("{0} App:{1} Net:{2} Dll:{3} Dev:{4} Fw:{5}",
                                      System.Reflection.Assembly.GetEntryAssembly().GetName().Name,
                                      System.Reflection.Assembly.GetEntryAssembly().GetName().Version,
                                      NurUtils.NurApiDotNetVersion,
                                      hNur.GetFileVersion(),
                                      readerInfo.name,
                                      readerInfo.GetVersionString());
        }
コード例 #6
0
 private void TryUpdateInformation()
 {
     try
     {
         mReaderInfo = hNur.GetReaderInfo();
         AddLog("Device: " + mReaderInfo.name);
         AddLog("FW: " + mReaderInfo.GetVersionString());
     }
     catch (NurApiException e)
     {
         AddLog("Update reader information failed, error: " + e.error + ".");
         AddLog("Message: " + e.Message);
     }
 }
コード例 #7
0
        // This is called when NurApi is fully connected to device and ready to communicate
        private async void Api_ConnectedEvent(object sender, NurApi.NurEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Api_ConnectedEvent");

            NurApi connApi = sender as NurApi;

            App.NurApi = connApi;

            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                NurDeviceWatcherInfo knownDev = connApi.UserData as NurDeviceWatcherInfo;

                // Save connect spec to settings
                //mLocalSettings.Values["devicespec"] = DeviceSpecStr;
                mLocalSettings.Values["devicespec"] = knownDev.SpecStr;

                // Update listview entry
                knownDev.ConnState = NurApiTransport.State.Connected;
                knownDev.UpdateInfo();

                if (knownDev == SelectedDev)
                {
                    ConnButtonText = "Disconnect";
                }
            });

            // Update reader info
            await Task.Run(async() =>
            {
                try
                {
                    NurApi.ReaderInfo rdrInfo = App.NurApi.GetReaderInfo();
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        ConnInfo = string.Format("Connected {0}  |  Serial {1}  |  FW {2}", rdrInfo.name, rdrInfo.serial, rdrInfo.GetVersionString());
                    });
                }
                catch (Exception ex)
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                    {
                        ConnInfo = "Error";
                        await App.ShowException(ex);
                    });
                }
            });
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: opswip/nur_sample_windows
 void hNur_ConnectedEvent(object sender, NurApi.NurEventArgs e)
 {
     try
     {   //GetReaderInfo from module
         NurApi.ReaderInfo readerInfo = hNur.GetReaderInfo();
         //Show results in Listbox
         listBox1.Items.Add("Name\t" + readerInfo.name);
         listBox1.Items.Add("Version\t" + readerInfo.GetVersionString());
         listBox1.Items.Add("HW Ver\t" + readerInfo.hwVersion);
         listBox1.Items.Add("FCC\t  " + readerInfo.fccId);
         listBox1.Items.Add("Serial\t" + readerInfo.serial);
         listBox1.Items.Add("SW Ver\t" + readerInfo.swVerMajor + "." + readerInfo.swVerMinor);
     }
     catch (Exception ex) //Handle error by show error message in Listbox
     {
         listBox1.Items.Add("Error: GetReaderInfo:" + ex.Message);
     }
 }
コード例 #9
0
        private void TryUpdateReaderInfo()
        {
            try
            {
                BdrSelect.SelectedIndex = hNur.BaudRate;
            }
            catch { }

            try
            {
                mReaderInfo = hNur.GetReaderInfo();
                AddLog("Device: " + mReaderInfo.name);
            }
            catch (NurApiException e)
            {
                AddLog("Update reader information failed, error: " + e.error + ".");
                AddLog("Message: " + e.Message);
            }
        }
コード例 #10
0
        public bool Connect()
        {
            try
            {
                var deviceFound = false;
                var comPorts    = NurApi.EnumerateComPorts();

                // Try to find the wanted device (depending on serialNr)
                foreach (NurApi.ComPort comPort in comPorts)
                {
                    if (!comPort.friendlyName.StartsWith("NUR Module"))
                    {
                        continue;
                    }

                    try
                    {
                        hNur.ConnectSerialPort(comPort.port);
                        var info = hNur.GetReaderInfo();
                        if (_ReaderSerial.Equals(info.altSerial))
                        {
                            deviceFound = true;
                            break;
                        }
                        else
                        {
                            hNur.Disconnect();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex.InnerException;
                    }

                    Thread.Sleep(100);
                }
                if (!deviceFound)
                {
                    _Error = "No device found with the defined serial";
                    return(false);
                }

                if (hNur.IsConnected())
                {
                    _ReaderInfo = hNur.GetReaderInfo();
                    NurApi.ReaderInfo info = hNur.GetReaderInfo();
                    _ReaderAltSerial = info.altSerial;
                    _Connected       = true;
                    return(true);
                }
                else
                {
                    throw new Exception("RFID timeout");
                }
            }
            catch (Exception ex)
            {
                _Error = "Error connecting to RFID " + ex.Message;
                return(false);
            }
        }
コード例 #11
0
        /// <summary>
        /// Updates the info.
        /// </summary>
        /// <param name="hNur">The NUR module handler.</param>
        private void UpdateInfo(NurApi hNur)
        {
            bool outdated = false;

            treeView1.Nodes.Clear();

            TreeNode node;
            TreeNode dllNode = treeView1.Nodes.Add("DLL Versions");

            try
            {
                string fileVersion = hNur.GetFileVersion();
                dllNode.Nodes.Add("NurApi.dll - " + fileVersion);
                dllNode.Nodes.Add("NurApiDotNet.dll - " + NurUtils.NurApiDotNetVersion);
            }
            catch (NurApiException ex)
            {
                AddExceptionNode(dllNode, ex, true);
            }

            if (hNur.IsConnected())
            {
                TreeNode fwinfoNode  = treeView1.Nodes.Add("FWINFO (parsed string)");
                TreeNode structsNode = treeView1.Nodes.Add("Module settings (structs)");

                try
                {
                    NurApi.ReaderInfo readerInfo = hNur.GetReaderInfo();
                    tabPage1.Text = "Reader: " + readerInfo.name + ", " + readerInfo.GetVersionString();
                    DumpObject(structsNode, readerInfo, null);
                }
                catch (NurApiException ex)
                {
                    AddExceptionNode(structsNode, ex, false);
                }

                try
                {
                    DumpObject(structsNode, GetVersions(hNur), null);
                    //DumpObject(structsNode, hNur.GetVersions(), null);
                }
                catch (NurApiException ex)
                {
                    AddExceptionNode(structsNode, ex, false);
                }

                try
                {
                    NurFwInfoParser fwinfo = new NurFwInfoParser(hNur.GetFWINFO());
                    foreach (KeyValuePair <string, string> entry in fwinfo.keypairs)
                    {
                        fwinfoNode.Nodes.Add(entry.Key + " = " + entry.Value);
                    }
                }
                catch (NurApiException ex)
                {
                    AddExceptionNode(fwinfoNode, ex, false);
                    fwinfoNode.Expand();
                    outdated = true;
                }

                try
                {
                    DumpObject(structsNode, hNur.GetDeviceCaps(), null);
                }
                catch (NurApiException ex)
                {
                    AddExceptionNode(structsNode, ex, false);
                }

                try
                {
                    DumpObject(structsNode, hNur.GetEthConfig(), null);
                }
                catch (NurApiException ex)
                {
                    AddExceptionNode(structsNode, ex, false);
                }

                try
                {
                    DumpObject(structsNode, hNur.GetModuleSetup(), null);
                }
                catch (NurApiException ex)
                {
                    AddExceptionNode(structsNode, ex, false);
                }

                try
                {
                    DumpObject(structsNode, hNur.GetSensorConfig(), null);
                }
                catch (NurApiException ex)
                {
                    AddExceptionNode(structsNode, ex, false);
                }

                TreeNode regNode    = treeView1.Nodes.Add("Regions");
                int      numRegions = 0;
                try
                {
                    NurApi.ReaderInfo readerInfo = hNur.GetReaderInfo();
                    // Dump region infos
                    for (int i = 0; i < readerInfo.numRegions; i++)
                    {
                        NurApi.RegionInfo ri = hNur.GetRegionInfo(i);
                        DumpObject(regNode, ri, string.Format("{0}: {1}", i, ri.name));
                        numRegions++;
                    }
                    // Dump CustomHoptable
                    try
                    {
                        NurApi.CustomHoptableEx customHoptableEx = hNur.GetCustomHoptableEx();
                        DumpObject(regNode, customHoptableEx, string.Format("{0}: {1}", NurApi.REGIONID_CUSTOM, "customHoptableEx"));
                        numRegions++;
                    }
                    catch (NurApiException ex)
                    {
                        try
                        {
                            AddExceptionNode(regNode, ex, false);
                            NurApi.CustomHoptable customHoptable = hNur.GetCustomHoptable();
                            DumpObject(regNode, customHoptable, string.Format("{0}: {1}", NurApi.REGIONID_CUSTOM, "customHoptable"));
                            numRegions++;
                        }
                        catch (NurApiException ex2)
                        {
                            AddExceptionNode(regNode, ex2, false);
                        }
                    }
                }
                catch (NurApiException ex)
                {
                    AddExceptionNode(structsNode, ex, true);
                }
                regNode.Text = string.Format("{0} ({1} pcs)", regNode.Text, numRegions);

                TreeNode antNode = treeView1.Nodes.Add("Antennas");
                try
                {
                    antNode.Nodes.Add("Selected - " + (hNur.SelectedAntenna == -1 ? "Auto" : hNur.SelectedAntenna.ToString()));
                    antNode.Nodes.Add("Enabled - " + GetEnabledAntennas());
                    node = antNode.Nodes.Add("Reflected Powers");
                    if (MeasureReflectedPowers(hNur, node))
                    {
                        antNode.Expand();
                    }
                }
                catch (NurApiException)
                {
                    node           = antNode.Nodes.Add("Can't get antenna settings");
                    node.ForeColor = System.Drawing.Color.Red;
                    node.Expand();
                }
                structsNode.Expand();
            }
            else
            {
                tabPage1.Text = "No Connection";
            }

            if (outdated)
            {
                node           = treeView1.Nodes.Add("The NUR modules firmware might be outdated. Please check for updates.");
                node.ForeColor = System.Drawing.Color.Red;
                node.Nodes.Add("E-mail: [email protected]");
                node.Expand();
            }
        }