Esempio n. 1
0
        private static int read(IntPtr deviceHandle, byte[] pData, uint dataSize, uint timeout)
        {
            try
            {
                uint tmpReadTO  = 0;
                uint tmpWriteTO = 0;
                int  status     = SIUSBXP.SI_SUCCESS;

                // Save timeout values.
                SIUSBXP.SI_GetTimeouts(ref tmpReadTO, ref tmpWriteTO);

                // Set a timeout for the read
                SIUSBXP.SI_SetTimeouts(timeout, 0);

                // Read the data
                uint recvDataSize = 0;
                status = SIUSBXP.SI_Read(deviceHandle, pData, dataSize, ref recvDataSize, IntPtr.Zero);

                // Restore timeouts
                SIUSBXP.SI_SetTimeouts(tmpReadTO, tmpWriteTO);

                return((status == SIUSBXP.SI_SUCCESS) ? (int)recvDataSize : -1);
            }
            catch { }
            return(-200);
        }
Esempio n. 2
0
 private static void close(IntPtr deviceHandle)
 {
     try
     {
         SIUSBXP.SI_Close(deviceHandle);
     }
     catch { }
 }
Esempio n. 3
0
 private static int getPID(uint index, StringBuilder builder)
 {
     try
     {
         if (index >= SiUSBController.count())
         {
             return(-100);
         }
         var status = SIUSBXP.SI_GetProductString(index, builder, SIUSBXP.SI_RETURN_PID);
         return((status == SIUSBXP.SI_SUCCESS) ? 1 : -1);
     }
     catch { }
     return(-200);
 }
Esempio n. 4
0
 private static bool open(uint index, ref IntPtr deviceHandle)
 {
     try
     {
         if (index >= SiUSBController.count())
         {
             return(false);
         }
         var status = SIUSBXP.SI_Open(index, ref deviceHandle);
         return(status == SIUSBXP.SI_SUCCESS);
     }
     catch { }
     return(false);
 }
Esempio n. 5
0
 ///////////////////////////// SiUSBXp ///////////////////////////
 private static uint count()
 {
     try
     {
         uint dwNumDevices = 0;
         var  status       = SIUSBXP.SI_GetNumDevices(ref dwNumDevices);
         if (status != SIUSBXP.SI_SUCCESS || dwNumDevices == 0)
         {
             return(0);
         }
         return(dwNumDevices);
     }
     catch { }
     return(0);
 }