Пример #1
0
        internal bool GetNumberOfInputBuffers(int hidDeviceObject, ref int numberOfInputBuffers)
        {
            bool flag1 = false;

            try
            {
                bool flag2;
                if (!IsWindows98Gold())
                {
                    flag2 = HidApiDeclarations.HidD_GetNumInputBuffers(hidDeviceObject, ref numberOfInputBuffers);
                }
                else
                {
                    numberOfInputBuffers = 2;
                    flag2 = true;
                }
                flag1 = flag2;
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Hid.HandleException("Hid", ex);
                ProjectData.ClearProjectError();
            }
            return(flag1);
        }
Пример #2
0
 internal HidApiDeclarations.HIDP_CAPS GetDeviceCapabilities(int hidHandle)
 {
     byte[] inArray  = new byte[30];
     byte[] numArray = new byte[1024];
     HidApiDeclarations.HIDP_CAPS capabilities = new HidApiDeclarations.HIDP_CAPS();
     try
     {
         IntPtr PreparsedData = new IntPtr();
         bool   flag          = HidApiDeclarations.HidD_GetPreparsedData(hidHandle, ref PreparsedData);
         Convert.ToBase64String(inArray);
         if (HidApiDeclarations.HidP_GetCaps(PreparsedData, ref Capabilities) != 0)
         {
             HidApiDeclarations.HidP_GetValueCaps((short)0, ref numArray[0], ref Capabilities.NumberInputValueCaps, PreparsedData);
             flag = HidApiDeclarations.HidD_FreePreparsedData(ref PreparsedData);
         }
         capabilities = Capabilities;
     }
     catch (Exception ex)
     {
         ProjectData.SetProjectError(ex);
         Hid.HandleException("Hid", ex);
         ProjectData.ClearProjectError();
     }
     return(capabilities);
 }
Пример #3
0
 protected override void ProtectedRead(int readHandle, int hidHandle, int writeHandle, ref bool myDeviceDetected, ref byte[] inputReportBuffer, ref bool success)
 {
     try
     {
         success = HidApiDeclarations.HidD_GetInputReport(hidHandle, ref inputReportBuffer[0], checked (Information.UBound((Array)inputReportBuffer, 1) + 1));
     }
     catch (Exception ex)
     {
         ProjectData.SetProjectError(ex);
         Hid.HandleException("Hid", ex);
         ProjectData.ClearProjectError();
     }
 }
Пример #4
0
            protected override bool ProtectedWrite(int hidHandle, byte[] outputReportBuffer)
            {
                bool flag = false;

                try
                {
                    flag = HidApiDeclarations.HidD_SetOutputReport(hidHandle, ref outputReportBuffer[0], checked (Information.UBound((Array)outputReportBuffer, 1) + 1));
                }
                catch (Exception ex)
                {
                    ProjectData.SetProjectError(ex);
                    Hid.HandleException("Hid", ex);
                    ProjectData.ClearProjectError();
                }
                return(flag);
            }
Пример #5
0
        internal bool FlushQueue(int hidHandle)
        {
            bool flag = false;

            try
            {
                flag = HidApiDeclarations.HidD_FlushQueue(hidHandle);
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Hid.HandleException("Hid", ex);
                ProjectData.ClearProjectError();
            }
            return(flag);
        }
Пример #6
0
        //TODO: Refatorar método
        public bool Conectado()
        {
            if (UpdatedAt == null || (DateTime.Now - UpdatedAt).Seconds > 2)
            {
                string[] devicePathName = new string[128];
                try
                {
                    Guid empty = Guid.Empty;
                    MyDeviceDetected = false;
                    FileIOApiDeclarations.SECURITY_ATTRIBUTES lpSecurityAttributes = new FileIOApiDeclarations.SECURITY_ATTRIBUTES();
                    lpSecurityAttributes.lpSecurityDescriptor = 0;
                    lpSecurityAttributes.bInheritHandle       = -1;
                    lpSecurityAttributes.nLength = Strings.Len(lpSecurityAttributes);
                    //short num1 = checked((short)Math.Round(Conversion.Val("&h" + vid)));
                    //short num2 = checked((short)Math.Round(Conversion.Val("&h" + pid)));

                    short num1 = checked ((short)Math.Round(Conversion.Val("&h0483")));
                    short num2 = checked ((short)Math.Round(Conversion.Val("&h0035")));

                    HidApiDeclarations.HidD_GetHidGuid(ref empty);
                    empty.ToString();
                    if (MyDeviceManagement.FindDeviceFromGuid(empty, ref devicePathName))
                    {
                        int index = 0;
                        do
                        {
                            HIDHandle = FileIOApiDeclarations.CreateFile(devicePathName[index], 0, 3, ref lpSecurityAttributes, 3, 0, 0);
                            if (HIDHandle != -1)
                            {
                                MyHID.DeviceAttributes.Size = Marshal.SizeOf((object)MyHID.DeviceAttributes);
                                bool flag;
                                if (HidApiDeclarations.HidD_GetAttributes(HIDHandle, ref MyHID.DeviceAttributes))
                                {
                                    if ((int)MyHID.DeviceAttributes.VendorId == (int)num1 & (int)MyHID.DeviceAttributes.ProductId == (int)num2)
                                    {
                                        MyDeviceDetected = true;
                                        MyDevicePathName = devicePathName[index];
                                        NobreakInfo.StatusComunicacaoOk = true;
                                    }
                                    else
                                    {
                                        MyDeviceDetected = false;
                                        flag             = FileIOApiDeclarations.CloseHandle(HIDHandle);
                                    }
                                }
                                else
                                {
                                    MyDeviceDetected = false;
                                    flag             = FileIOApiDeclarations.CloseHandle(HIDHandle);
                                }
                            }
                            checked { ++index; }
                        }while (!(MyDeviceDetected | index == checked (Information.UBound((Array)devicePathName, 1) + 1)));
                    }

                    lastStatusConectado = MyDeviceDetected;
                    UpdatedAt           = DateTime.Now;
                    return(MyDeviceDetected);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERRO!!! " + ex.Message);
                    //throw new NobreakNotConnectedException("Não foi possível conectar-se ao Nobreak");
                }
            }

            return(lastStatusConectado);
        }