Ejemplo n.º 1
0
 private void filteredWatcherReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
 {
     try
     {
         // Event
         var e = new FindDeviceEventArgs(args);
         FindDevice?.Invoke(this, e);
     }
     catch (Exception ex)
     {
         Logger.Err($"Exception...{ex.Message})");
     }
 }
Ejemplo n.º 2
0
        private void watcherReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
        {
            bool find = false;

            {
                // search FIDO service
                if (args.Advertisement.ServiceUuids.Contains(Common.Gatt_Service_FIDO_GUID))
                {
                    /*
                     * foreach(var d in args.Advertisement.DataSections) {
                     *  // Local Name
                     *  if( d.DataType == 0x09) {
                     *      byte[] readBytes = new byte[d.Data.Length];
                     *      using (DataReader reader = DataReader.FromBuffer(d.Data)) {
                     *          reader.ReadBytes(readBytes);
                     *          //ASCII エンコード | ASCII encoding
                     *          string text = System.Text.Encoding.ASCII.GetString(readBytes);
                     *      }
                     *  }
                     * }
                     */
                    find = true;
                    Logger.Log("Scan FIDO Device");
                }
            }

            if (find)
            {
                try {
                    // Event
                    var e = new FindDeviceEventArgs(args);
                    FindDevice?.Invoke(this, e);
                } catch (Exception ex) {
                    Logger.Err($"Exception...{ex.Message})");
                }
            }
            return;
        }
Ejemplo n.º 3
0
        public void LoadLibs()
        {
            busy = true;

            IntPtr _dllHandle;
            IntPtr _fptr;
            string _dll1 = "DLL\\eSPAEAWBCtrl.dll";
            string _dll2 = "DLL\\eSPDI.dll";
            string Function_Name = "";

            SetDllDirectory("DLL\\");
            _dllHandle = LoadLibrary(_dll1);
            if (_dllHandle == IntPtr.Zero)
            {
                errors.Add("Error loading DLL: " + _dll2 + "\n" + Marshal.GetLastWin32Error().ToString()); // Error Code while loading DLL
            }

            Function_Name = "_eSPAEAWB_EnumDevice@4";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _enumDevice = (enumDevice)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(enumDevice));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_GetDevicename@12";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _GetDeviceName = (GetDeviceName)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(GetDeviceName));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_SelectDevice@4";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _SelectDevice = (SelectDevice)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SelectDevice));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_SetSensorType@4";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _SetSensorType = (SetSensorType)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SetSensorType));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_SWUnlock@4";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _SWUnlock = (SWUnlock)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SWUnlock));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_SWLock@4";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _SWLock = (SWLock)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SWLock));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_DisableAE@0";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _DisableAE = (DisableAE)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(DisableAE));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_DisableAWB@0";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _DisableAWB = (DisableAWB)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(DisableAWB));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_GetGPIOValue@8";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _GetGPIOValue = (GetGPIOValue)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(GetGPIOValue));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_SetGPIOValue@8";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _SetGPIOValue = (SetGPIOValue)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SetGPIOValue));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_GetAccMeterValue@12";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _GetAccMeterValue = (GetAccMeterValue)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(GetAccMeterValue));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "_eSPAEAWB_ReadFlash@8";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _ReadFlash = (ReadFlash)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(ReadFlash));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            // Switching to functions from second (ETron) DLL file now
            _dllHandle = LoadLibrary(_dll2);
            if (_dllHandle == IntPtr.Zero)
            {
                errors.Add("Error loading DLL: " + _dll2 + "\n" + Marshal.GetLastWin32Error().ToString()); // Error Code while loading DLL
            }

            Function_Name = "EtronDI_Init";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _SPDI_Init = (SPDI_Init)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SPDI_Init));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "EtronDI_GetDeviceNumber";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _GetDeviceNumber = (GetDeviceNumber)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(GetDeviceNumber));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }

            Function_Name = "EtronDI_FindDevice";
            _fptr = GetProcAddress(_dllHandle, Function_Name);
            if (_fptr != IntPtr.Zero)
            {
                _FindDevice = (FindDevice)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(FindDevice));
            }
            else
            {
                errors.Add("Error loading DLL function: " + Function_Name);
            }
            if (errors.Count == 0)
            {
                messages.Add("Loaded Libraries!");
            }

            busy = false;
        }