Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 public virtual void Open(string i_path)
 {
     if (m_IsOpen)
     {
         Close();
     }
     m_HidPtr = LibHidAPI.hid_open_path(m_Address = i_path);
     if (m_HidPtr == LibHidAPI.INVALID_HANDLE_VALUE)
     {
         if (m_OpenCallback != null)
         {
             m_OpenCallback.OnStreamOpenFailure(this);
         }
     }
     else
     {
         m_IsOpen = true; s_NumHids++;
         if (m_OpenCallback != null)
         {
             m_OpenCallback.OnStreamOpenSuccess(this);
         }
         // Open the read thread.
         if (m_ReadCallback != null)
         {
             m_Thread = new Thread(ReadThread_Main);
             m_Thread.IsBackground = true;
             m_Thread.Priority     = ThreadPriority.AboveNormal;
             m_Thread.Start();
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 public override void Open()
 {
     //InitLibrary();
     //
     if (m_IsOpen)
     {
         Close();
     }
     //
     if (!string.IsNullOrEmpty(m_Address))
     {
         if (LibHidAPI.Exists(m_Address))
         {
             Open(m_Address);
             return;
         }
     }
     if (m_DID == -1)          //???
     {
         m_VID = m_PID = m_DID = 0;
     }
     else
     {
     }
     Open(m_VID, m_PID, m_DID);
 }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        public virtual void Open(int vId, int pId, int dId = 0)
        {
            var list = LibHidAPI.EnumerateDevices(vId, pId);

            if (dId < list.Count)
            {
                Open(list[dId].path);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 public override int Write(byte[] buffer, int offset, int count)
 {
     if (!m_IsOpen)
     {
         return(-1);
     }
     System.IntPtr ptr = Marshal.AllocHGlobal(count); // Alloc
     Marshal.Copy(buffer, offset, ptr, count);        // Copy
     LibHidAPI.hid_write(m_HidPtr, ptr, count);       // Do
     Marshal.FreeHGlobal(ptr);                        // Free
     return(0);
 }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 public static int InitLibrary()
 {
     if (!s_Inited)
     {
         int ret = LibHidAPI.hid_init();
         if (ret == 0)
         {
             s_Inited = true;
         }
         return(ret);
     }
     return(0);
 }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 public static int ExitLibrary()
 {
     //if(s_NumHids==0) {
     if (s_Inited)
     {
         int ret = LibHidAPI.hid_exit();
         if (ret == 0)
         {
             s_Inited = false;
         }
         return(ret);
     }
     //}
     return(0);
 }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        public virtual int ReadTimeout(byte[] buffer, int offset, int count, int milliseconds)
        {
            if (!m_IsOpen)
            {
                return(0);
            }
            System.IntPtr ptr = Marshal.AllocHGlobal(count);                                    // Alloc
            int           ret = LibHidAPI.hid_read_timeout(m_HidPtr, ptr, count, milliseconds); // Do

            if (ret > 0)
            {
                Marshal.Copy(ptr, buffer, offset, ret); // Copy
            }
            Marshal.FreeHGlobal(ptr);                   // Free
            return(ret);
        }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 public override void Close()
 {
     // Forcibly close the read thread.
     if (m_Thread != null)
     {
         ++m_ThreadLock;
         m_Thread.Abort();
         m_Thread = null;
     }
     // Forcibly set callbacks to null to avoid accessing callbacks in the read thread.
     m_OpenCallback = null;
     m_ReadCallback = null;
     //
     if (m_IsOpen)
     {
         if (m_HidPtr != LibHidAPI.INVALID_HANDLE_VALUE)
         {
             LibHidAPI.hid_close(m_HidPtr); m_HidPtr = LibHidAPI.INVALID_HANDLE_VALUE;
         }
         s_NumHids--;                //ExitLibrary();
         //
         m_IsOpen = false;
     }
 }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 public static List <LibHidAPI.hid_device_info> EnumerateDevices(int vId, int pId)
 {
     return(LibHidAPI.EnumerateDevices(vId, pId));
 }
Exemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 public static List <LibHidAPI.hid_device_info> EnumerateDevices()
 {
     return(LibHidAPI.EnumerateDevices(0, 0));
 }
Exemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 public static bool Exists(string path)
 {
     return(LibHidAPI.Exists(path));
 }