Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 07-04-2016
petercat petercat is offline
Miembro
 
Registrado: feb 2012
Posts: 23
Poder: 0
petercat Va por buen camino
Deshabilitar HID-USB

Buneas
Resulta que en el programa que estoy haciendo tengo un teclado por USB y ahora un dispositivo RFID tambien por USB que emula el teclado, ahora necesito deshabilitar el lectro USB del RFID mientras no me haga falta para que cuando alguien se aproxime al lector RFID no interfiere con parte del programa en ejecucion, es decir lo que quiero es solicirtar al lector que actue cuando realmente sea necesario, para ello lo que se me ocurre es identificar el HID-USB mediante el ID Venderdor y deshabilitarlo hasta que realmente me haga falta y una vez leido o trascurrido un tiempo con un timer que lo vuelva a deshabilitar.
Podeis orientarme de como podria deshabilitar dicho HID-USB mediante el ID del Vendedor ó productID?'

Muchas gracias
Responder Con Cita
  #2  
Antiguo 07-04-2016
bitbow bitbow is offline
Miembro
 
Registrado: jul 2006
Posts: 366
Poder: 18
bitbow Va camino a la fama
El objetivo de estos lectores es que funcionen desatendidos por lo cual lo que quieres hacer (a como yo los he usado) v en contra de para lo que se pensaron (kioscos, pasarelas, controles de acceso), basta con identificar el dispositivo de interfaz humana y deshabilitarlo/habilitarlo dependiendo de como lo requieras (no he realizado esta acción en delphi pero seguramente se puede).

Saludos.
__________________
¡Ni como ayudarte Niño!!
bitbow
Responder Con Cita
  #3  
Antiguo 08-04-2016
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Poder: 28
Lepe Va por buen camino
Sea como fuere, échale un vistazo a esta web: http://www.ajpdsoft.com/modules.php?...rticle&sid=463

Creo tiene todo lo que necesitas.

Saludos y suerte!
__________________
Si usted entendió mi comentario, contácteme y gustosamente,
se lo volveré a explicar hasta que no lo entienda, Gracias.
Responder Con Cita
  #4  
Antiguo 10-04-2016
petercat petercat is offline
Miembro
 
Registrado: feb 2012
Posts: 23
Poder: 0
petercat Va por buen camino
Gracias pero el ejemplo de apjsoft es para pendrive de memoria.
Lo que realmente quiero es poder habilitar y deshabilitar es el HID del Keyboar, en la actualidad me reconoce dos dispositivos uno HID que el el teclado y otro HID que es el Barcode Reader (Lector RFID), los dos los identifcio mediante el PID y el VID y de momento lo hago con mcHID.dll, pero no se como poder habilitar y deshabilitar o que no estre en uso uno de ellos, es dejarlo inactivo el Lector para cuando realmente me haga falta, de esta manera no interfiere con el programa, dado que si estan escribiendo y pasan sin querer el Tag del lector por encima les sale un chorro de numeros.

Gracias
Responder Con Cita
  #5  
Antiguo 11-04-2016
petercat petercat is offline
Miembro
 
Registrado: feb 2012
Posts: 23
Poder: 0
petercat Va por buen camino
Buenas sigo con el tema y quizas pueda solucionarlo de otra manera en vez de deshabilitar el lector o teclado. Expongo como estoy viendo la posible solucion pero aun asi necesito ayuda.
Tengo un teclado por USB-HID con un numero VID (Vendedor_ID) "VID:046D:" y un PID (Product_ID) "PID:C31C"
Tengo un lector por USB-HID con un numero VID (Vendedor_ID) "VID:13BA" y un PID (Product_ID) "PID:0018"
Dicha informacion la puedo sacar del Regedit o desde el administrador de dispositivos, los dos utilizan el mismo controlador.
Luego dispongo de dos TEdit "Edit1" y "Edit2" la tecla 0 el la key=#48, pues bien la intencion es que si lee la tecla 0 del dispositivo HID de teclado vaya ela "Edit1" pero si por el contrario leo con el lector, que para ello le he dicho que la primera letra sea un 0, vaya al "Edit2".

Sabria alguien decirme si sepuede identificar del dispositivo de donde viene el numero 0????

Muchas gracias

PD si es necesario cambio el titulo
Responder Con Cita
  #6  
Antiguo 12-04-2016
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.020
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Si deshabilitas el teclado ¿cómo lo habilitas después?
Responder Con Cita
  #7  
Antiguo 12-04-2016
petercat petercat is offline
Miembro
 
Registrado: feb 2012
Posts: 23
Poder: 0
petercat Va por buen camino
Cita:
Empezado por Casimiro Notevi Ver Mensaje
Si deshabilitas el teclado ¿cómo lo habilitas después?
Por eso he cambiado la idea, la idea es poder saber si los números vienen del HID del teclado o del HID del lector.
No sé si Delphi podrá saber si vienen por uno o por otro dependiendo de si se puede leer el VID y o el PID de donde vengan.
Responder Con Cita
  #8  
Antiguo 12-04-2016
Delfino Delfino is offline
Miembro
 
Registrado: jul 2003
Ubicación: Madrid
Posts: 974
Poder: 21
Delfino Va por buen camino
Has mirado el componente TJvHidDeviceController de la suite JVCL?
__________________
¿Microsoft? No, gracias..
Responder Con Cita
  #9  
Antiguo 15-04-2016
Noiro Noiro is offline
Registrado
NULL
 
Registrado: abr 2016
Posts: 1
Poder: 0
Noiro Va por buen camino
Puedes utilizar RegisterRawInputDevices.

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  USHORT = Word;
  HRAWINPUT = THandle;
  LPVOID = Pointer;

  tagRAWINPUTDEVICE = record
    usUsagePage: USHORT;
    usUsage: USHORT;
    dwFlags: DWORD;
    hwndTarget: HWND;
  end;
  RAWINPUTDEVICE = tagRAWINPUTDEVICE;
  TRawInputDevice = RAWINPUTDEVICE;
  PRawInputDevice = ^TRawInputDevice;
  LPRAWINPUTDEVICE = PRawInputDevice;
  PCRAWINPUTDEVICE = PRawInputDevice;

  tagRAWINPUTHEADER = record
    dwType: DWORD;
    dwSize: DWORD;
    hDevice: THandle;
    wParam: WPARAM;
  end;
  RAWINPUTHEADER = tagRAWINPUTHEADER;
  TRawInputHeader = RAWINPUTHEADER;
  PRawInputHeader = ^TRawInputHeader;

  tagRAWMOUSE = record
    usFlags: WORD;
    union: record
    case Integer of
      0: (
        ulButtons: ULONG);
      1: (
        usButtonFlags: WORD;
        usButtonData: WORD);
    end;
    ulRawButtons: ULONG;
    lLastX: LongInt;
    lLastY: LongInt;
    ulExtraInformation: ULONG;
  end;
  RAWMOUSE = tagRAWMOUSE;
  TRawMouse = RAWMOUSE;
  PRAWMOUSE = ^RAWMOUSE;
  LPRAWMOUSE = ^RAWMOUSE;

  tagRAWKEYBOARD = record
    MakeCode: USHORT;
    Flags: USHORT;
    Reserved: USHORT;
    VKey: USHORT;
    Message: UINT;
    ExtraInformation: ULONG;
  end;
  RAWKEYBOARD = tagRAWKEYBOARD;
  TRawKeyboard = RAWKEYBOARD;
  PRawKeyboard = ^TRawKeyboard;
  LPRAWKEYBOARD = PRawKeyboard;

  tagRAWHID = record
    dwSizeHid: DWORD;    // byte size of each report
    dwCount: DWORD;      // number of input packed
    bRawData: array [0..0] of BYTE;
  end;
  RAWHID = tagRAWHID;
  TRawHID = RAWHID;
  PRawHID = ^TRawHID;
  LPRAWHID = PRawHID;


  tagRAWINPUT = record
    header: TRawInputHeader;
    case Integer of
      0: (mouse: RAWMOUSE);
      1: (keyboard: RAWKEYBOARD);
      2: (hid: RAWHID);
  end;
  RAWINPUT = tagRAWINPUT;
  TRawInput = RAWINPUT;
  PRawInput = ^TRawInput;
  LPRAWINPUT = PRawInput;

  TForm1 = class(TForm)
  private
  protected
    procedure CreateWindowHandle(const Params: TCreateParams); override;
    procedure WMInput(var Message: TMessage); message WM_INPUT;
    { Private declarations }
  public
    { Public declarations }
    
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  GenericDesktopControls: USHORT = 01;
  Keyboard: USHORT = 06;
  RIDEV_INPUTSINK = $00000100;

  RIM_INPUT = 0;
  RIM_INPUTSINK = 1;
  RID_INPUT = $10000003;

  RIM_TYPEMOUSE      = 0;
  RIM_TYPEKEYBOARD   = 1;
  RIM_TYPEHID        = 2;

  RI_KEY_MAKE = 0;
  RI_KEY_BREAK = 1;


function RegisterRawInputDevices(
  pRawInputDevices: PCRAWINPUTDEVICE;
  uiNumDevices: UINT;
  cbSize: UINT): BOOL; stdcall; external user32;

function GetRawInputData(
  hRawInput: HRAWINPUT;
  uiCommand: UINT;
  pData: LPVOID;
  var pcbSize: UINT;
  cbSizeHeader: UINT): UINT; stdcall; external user32;


{ TForm1 }

procedure TForm1.CreateWindowHandle(const Params: TCreateParams);
var
  RID: TRawInputDevice;
begin
  inherited;

  RID.usUsagePage := GenericDesktopControls;
  RID.usUsage := Keyboard;
  RID.dwFlags := RIDEV_INPUTSINK;
  RID.hwndTarget := Handle;
  Win32Check(RegisterRawInputDevices(@RID, 1, SizeOf(RID)));
end;

procedure TForm1.WMInput(var Message: TMessage);
var
  Size: UINT;
  Data: array of Byte;
  RawKeyboard: TRawKeyboard;
  RawHID: TRawHID;
begin
  if (Message.WParam and $FF) in [RIM_INPUT, RIM_INPUTSINK] then
    inherited;

  if (GetRawInputData(Message.LParam, RID_INPUT, nil, Size,
      SizeOf(TRawInputHeader)) = 0) then begin
    SetLength(Data, Size);
    if (GetRawInputData(Message.LParam, RID_INPUT, Data, Size,
        SizeOf(TRawInputHeader)) <> UINT(-1)) then
    begin
      if (PRawInput(Data)^.header.dwType = RIM_TYPEKEYBOARD) then
      begin
        RawKeyboard := PRawInput(Data)^.keyboard;

        if (RawKeyboard.VKey = VK_CONTROL) then begin
          if RawKeyboard.Flags and RI_KEY_BREAK = RI_KEY_BREAK then
            Cursor := crDefault
          else
            Cursor := crSizeAll; // will call continously until key is released
        end;
        // might opt to reset the cursor regardless of pointer position...


        if (RawKeyboard.VKey = Ord('A')) then
        begin
          // ....
        end;
      end
      else if (PRawInput(Data)^.header.dwType = RIM_TYPEHID) then
      begin
        RawHID := PRawInput(Data).hid;
        // ....
      end;
    end;

  end;
end;

end.

Para poder "escuchar" el HID tendrás que registrarlo en la llamada RegisterRawInputDevices pasando un array con el total de dispositivos.
Responder Con Cita
  #10  
Antiguo 19-04-2016
petercat petercat is offline
Miembro
 
Registrado: feb 2012
Posts: 23
Poder: 0
petercat Va por buen camino
Identificar multiteclado HID-USB

Gracias a nuestro amigo Noiro he podido conseguir distinguir el dispositivo Teclado del dispositivo RFID, podria valer para distinguir un teclado de un lector de codigo de barras etc.
Tan solo al codigo que pego Noiro se le han cambiado algunos parametros y con ello nos da el resultado del teclado en el Label1 y el lector en el Label2.
Una vez conseguido esto definido cada una de las direcciones del dispositivo y podemos aislar el teclado del lector tanto en un edit como en un memo.
Pego el codigo por si alguno esta buscando una solucion parecida a la mia.
Gracias a todos
PD si es necesario cambiar el titulo: "Deshabiliar HID-USB" por el de "Identificar multiteclado HID-USB"

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  USHORT = Word;
  HRAWINPUT = THandle;
  LPVOID = Pointer;
  HANDLE = THandle;

  tagRAWINPUTDEVICE = record
    usUsagePage: USHORT;
    usUsage: USHORT;
    dwFlags: DWORD;
    hwndTarget: HWND;
  end;
  RAWINPUTDEVICE = tagRAWINPUTDEVICE;
  TRawInputDevice = RAWINPUTDEVICE;
  PRawInputDevice = ^TRawInputDevice;
  LPRAWINPUTDEVICE = PRawInputDevice;
  PCRAWINPUTDEVICE = PRawInputDevice;

  tagRAWINPUTHEADER = record
    dwType: DWORD;
    dwSize: DWORD;
    hDevice: THandle;
    wParam: WPARAM;
  end;
  RAWINPUTHEADER = tagRAWINPUTHEADER;
  TRawInputHeader = RAWINPUTHEADER;
  PRawInputHeader = ^TRawInputHeader;

  tagRAWMOUSE = record
    usFlags: WORD;
    union: record
    case Integer of
      0: (
        ulButtons: ULONG);
      1: (
        usButtonFlags: WORD;
        usButtonData: WORD);
    end;
    ulRawButtons: ULONG;
    lLastX: LongInt;
    lLastY: LongInt;
    ulExtraInformation: ULONG;
  end;
  RAWMOUSE = tagRAWMOUSE;
  TRawMouse = RAWMOUSE;
  PRAWMOUSE = ^RAWMOUSE;
  LPRAWMOUSE = ^RAWMOUSE;

  tagRAWKEYBOARD = record
    MakeCode: USHORT;
    Flags: USHORT;
    Reserved: USHORT;
    VKey: USHORT;
    Message: UINT;
    ExtraInformation: ULONG;
  end;
  RAWKEYBOARD = tagRAWKEYBOARD;
  TRawKeyboard = RAWKEYBOARD;
  PRawKeyboard = ^TRawKeyboard;
  LPRAWKEYBOARD = PRawKeyboard;

  tagRAWHID = record
    dwSizeHid: DWORD;    // byte size of each report
    dwCount: DWORD;      // number of input packed
    bRawData: array [0..0] of BYTE;
  end;
  RAWHID = tagRAWHID;
  TRawHID = RAWHID;
  PRawHID = ^TRawHID;
  LPRAWHID = PRawHID;


  tagRAWINPUT = record
    header: TRawInputHeader;
    case Integer of
      0: (mouse: RAWMOUSE);
      1: (keyboard: RAWKEYBOARD);
      2: (hid: RAWHID);
  end;
  RAWINPUT = tagRAWINPUT;
  TRawInput = RAWINPUT;
  PRawInput = ^TRawInput;
  LPRAWINPUT = PRawInput;

  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
  private
  protected
    procedure CreateWindowHandle(const Params: TCreateParams); override;
    procedure WMInput(var Message: TMessage); message WM_INPUT;
    { Private declarations }
  public
    { Public declarations }

  end;

var
    Form1: TForm1;
    KBName: array[0..1023] of AnsiChar;

implementation

{$R *.dfm}

const
  GenericDesktopControls: USHORT = 01;
  Keyboard: USHORT = 06;
  RIDEV_INPUTSINK = $00000100;

  RIM_INPUT = 0;
  RIM_INPUTSINK = 1;
  RID_INPUT = $10000003;

  RIDI_DEVICENAME = $20000007;
  RIDI_DEVICEINFO = $2000000b;
  RIDI_PREPARSEDDATA = $20000005;

  RIM_TYPEMOUSE      = 0;
  RIM_TYPEKEYBOARD   = 1;
  RIM_TYPEHID        = 2;

  RI_KEY_MAKE = 0;
  RI_KEY_BREAK = 1;


function RegisterRawInputDevices(
  pRawInputDevices: PCRAWINPUTDEVICE;
  uiNumDevices: UINT;
  cbSize: UINT): BOOL; stdcall; external user32;

function GetRawInputData(
  hRawInput: HRAWINPUT;
  uiCommand: UINT;
  pData: LPVOID;
  var pcbSize: UINT;
  cbSizeHeader: UINT): UINT; stdcall; external user32;

function GetRawInputDeviceInfoA(hDevice: THANDLE; uiCommand: UINT; pData: POINTER;
    var pcbSize: UINT): UINT; stdcall; external user32;


{ TForm1 }



procedure TForm1.CreateWindowHandle(const Params: TCreateParams);
var
  RID: TRawInputDevice;
begin
  inherited;

  RID.usUsagePage := GenericDesktopControls;
  RID.usUsage := Keyboard;
  RID.dwFlags := RIDEV_INPUTSINK;
  RID.hwndTarget := Handle;
  Win32Check(RegisterRawInputDevices(@RID, 1, SizeOf(RID)));
end;


procedure TForm1.WMInput(var Message: TMessage);
var
  Size: UINT;
  Data: array of Byte;
  RawKeyboard: TRawKeyboard;
  RawHID: TRawHID;
  devName: array of Byte;
//lo pasamos al var general
 // KBName: array[0..1023] of AnsiChar;
  Key :Char;
begin
  if (Message.WParam and $FF) in [RIM_INPUT, RIM_INPUTSINK] then
    inherited;

  if (GetRawInputData(Message.LParam, RID_INPUT, nil, Size,
      SizeOf(TRawInputHeader)) = 0) then begin
    SetLength(Data, Size);
    if (GetRawInputData(Message.LParam, RID_INPUT, Data, Size,
        SizeOf(TRawInputHeader)) <> UINT(-1)) then
    begin
      if (PRawInput(Data)^.header.dwType = RIM_TYPEKEYBOARD) then
      begin
        RawKeyboard := PRawInput(Data)^.keyboard;

        if (RawKeyboard.VKey = VK_CONTROL) then begin
          if RawKeyboard.Flags and RI_KEY_BREAK = RI_KEY_BREAK then
            Cursor := crDefault
          else
            Cursor := crSizeAll; // will call continously until key is released
        end;
        // might opt to reset the cursor regardless of pointer position...

// Al pulsar la tecla 'A' nos devolvera en el Label1 en KBName nos dara
//la ruta de acceso a la instancia del dispositivo
        if (RawKeyboard.VKey = Ord('A')) then
        begin
          Size := 1024;
          if (GetRawInputDeviceInfoA(PRawInput(Data)^.header.hDevice, RIDI_DEVICENAME,
            @KBName, Size) <> UINT(-1)) then
          begin
          Label1.Caption := Ansistring(KBName);
          end;
          // ....
        end;

// Al pulsar la tecla '0' nos devolvera en el Label2 en KBName nos dara
//la ruta de acceso a la instancia del dispositivo
                if (RawKeyboard.VKey = Ord('0')) then
        begin
          Size := 1024;
          if (GetRawInputDeviceInfoA(PRawInput(Data)^.header.hDevice, RIDI_DEVICENAME,
            @KBName, Size) <> UINT(-1)) then
          begin
          Label2.Caption := Ansistring(KBName);
          end;
          // ....
        end;

      end
      else if (PRawInput(Data)^.header.dwType = RIM_TYPEHID) then
      begin
        RawHID := PRawInput(Data).hid;
        // ....
      end;
    end;

  end;
end;

end.

Última edición por petercat fecha: 19-04-2016 a las 19:01:12. Razón: Error en el codigo
Responder Con Cita
  #11  
Antiguo 27-06-2023
Alexandro Prado Alexandro Prado is offline
Registrado
 
Registrado: jun 2023
Posts: 1
Poder: 0
Alexandro Prado Va por buen camino
Post me podrias ayudar con este descubrimiento tuyo

Hola petercat, vengo de Brasil, tengo un problema que solucionaste. ¿Podría darme un ejemplo más completo de cómo está reconociendo el lector hid rfid y cómo está trabajando con sus lecturas?
También tengo un lector HID que simula el teclado y quiero controlar cuándo empezar a leer o capturar su respuesta sin que afecte lo que está haciendo el operador.
si me pueden ayudar se los agradecere
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Deshabilitar Alt-Tab director0407031 API de Windows 2 30-05-2008 21:24:26
Deshabilitar datatimepicker schaka Varios 2 27-04-2008 23:56:55
Deshabilitar el tab un for eldonfsr C++ Builder 4 25-07-2007 11:36:25
Deshabilitar FKs micayael Firebird e Interbase 1 09-03-2007 19:52:53
deshabilitar los iconos superhopi Varios 8 23-12-2006 03:30:21


La franja horaria es GMT +2. Ahora son las 10:46:50.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi