It is currently Sat Oct 25, 2014 7:53 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 54 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: USB HID Library
PostPosted: Mon Apr 05, 2010 1:28 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 710
Location: Russia
This library allows to gain access to USB HID device, from programs, written in PureBasic.

Download

x86
PureBasic 4.00 — 4.20
PureBasic 4.30 — 4.41
PureBasic 4.50 and 4.51
PureBasic 4.60, 4.61

x64
PureBasic 4.31 x64
PureBasic 4.50 x64
PureBasic 4.60, 4.61 x64

English help


Example:
Code:
#USB_PID=$1234
#USB_VID=$1212
#NO_Device="No HID device"
LoadFont(2,"Arial",22,#PB_Font_Bold)

Procedure FindDevice_Timer()
Shared DeviceHandle
Static Old_Test
Test=HID_Lib_DeviceTest(#USB_PID, #USB_VID)
 If Test<>Old_Test
  Old_Test=Test
  If Test
     HID_Lib_CloseDevice(DeviceHandle)
     DeviceHandle=HID_Lib_OpenDevice(#USB_PID, #USB_VID)
     SetGadgetText(0,"Discovered device")
  Else
     HID_Lib_CloseDevice(DeviceHandle)
     DeviceHandle=0
     SetGadgetText(0,#NO_Device)
     SetGadgetText(1,"OFF")
  EndIf
 EndIf
EndProcedure

Procedure ReadDevice_Thread(*x)
 Shared DeviceHandle
 Repeat
   If DeviceHandle
     In.l=0
     HID_Lib_ReadDevice(DeviceHandle, @In, 3)
       In=In>>8
       Result.f=In/16
       If Result<150 And Result>-50
         SetGadgetText(1,StrF(Result,1)+" °C")
       EndIf
   EndIf
   Delay(100)
 ForEver
EndProcedure

OpenWindow(0,0,0,170,70,"USB_Termo", #PB_Window_MinimizeGadget|#PB_Window_Invisible|#PB_Window_ScreenCentered)
 StickyWindow(0,1)
 TextGadget(0,4,4,162,16,#NO_Device,#PB_Text_Center)
 StringGadget(1,16,24,140,40,"OFF",#PB_Text_Center|#PB_String_ReadOnly)
   SetGadgetFont(1,FontID(2))
   SetGadgetColor(1,#PB_Gadget_FrontColor,$DF0000)
FindDevice_Timer()
HideWindow(0,0)

AddWindowTimer(0,1,400)
CreateThread(@ReadDevice_Thread(),0)

Repeat
   Event=WaitWindowEvent()
   If Event=#PB_Event_Timer
       If EventTimer()=1
         FindDevice_Timer()
       EndIf
   EndIf
Until Event=#PB_Event_CloseWindow

Image



Image

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Last edited by User_Russian on Fri Aug 03, 2012 8:39 pm, edited 11 times in total.

Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Mon Apr 05, 2010 3:11 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Oct 24, 2008 2:07 pm
Posts: 228
thanks for sharing :D


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Tue Apr 06, 2010 3:07 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2926
Location: New Zealand
thanks


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Tue Apr 06, 2010 9:37 am 
Offline
Addict
Addict

Joined: Sat Dec 31, 2005 5:24 pm
Posts: 2969
Location: Where ya would never look.....
Nice, Thank You. :)

_________________
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Tue Apr 06, 2010 10:17 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 658
Location: Cologne, Germany
Hi User_Russian,

looks promising. But could you provide us a Linux and/or Mac OS X-Lib?
I don't know if it's possible without big changes :-)

_________________
Regards,
JamiroKwai

---
5.10-x64/x86 - MacBook Pro, Mountain Lion
My Blog (German): http://www.quadworks.de


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Tue Apr 06, 2010 10:27 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 710
Location: Russia
In library were used WinAPI functions from hid.dll and setupapi.dll
In Linux and Mac OS all on other :(

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Tue Apr 06, 2010 2:53 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 658
Location: Cologne, Germany
User_Russian wrote:
In library were used WinAPI functions from hid.dll and setupapi.dll
In Linux and Mac OS all on other :(


Ok. That's a pity :-)
Hm. Going to search for something similar on Mac OS X now...

_________________
Regards,
JamiroKwai

---
5.10-x64/x86 - MacBook Pro, Mountain Lion
My Blog (German): http://www.quadworks.de


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Tue Apr 06, 2010 3:24 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 13, 2004 2:37 pm
Posts: 130
Location: Ottawa, Canada
If I have a USB HID device, like a barcode scanner, does that mean I can read the code scanned directly using this library, or is there another hump that needs to be conquered?

_________________
Colin


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Tue Apr 06, 2010 4:12 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 710
Location: Russia
ColBoy wrote:
If I have a USB HID device, like a barcode scanner, does that mean I can read the code scanned directly using this library, or is there another hump that needs to be conquered?

Probably yes
I did not use the library with scanner of the barcode.

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Wed Apr 07, 2010 9:03 pm 
Offline
User
User

Joined: Sat Mar 06, 2010 2:55 pm
Posts: 85
ColBoy wrote:
If I have a USB HID device, like a barcode scanner, does that mean I can read the code scanned directly using this library, or is there another hump that needs to be conquered?



Hi colboy,

You can just see the barcode scanner as a keyboard, it acts like one.
just plugin a barcode scanner, open up "notepad" and scan. You'll see what it does.

its typing for example : 3441344341243 and then place an ENTER.


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Thu Apr 08, 2010 2:10 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 13, 2004 2:37 pm
Posts: 130
Location: Ottawa, Canada
Hi doctorlove

Thanks I am aware of that. Sometimes however I want to access a barcode scanner in a serial mode, which many symbol Scanners support, with additional software. If I could do that without the Symbol serial driver that would be great. The problem with running a barcode scanner in wedge mode, is that you need to ensure a control has focus, to receive the data. IT's also much more inflexible.

Colin


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Thu Apr 08, 2010 4:23 pm 
Offline
Addict
Addict

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1140
Location: Germany
You can use a prefix with your barcodescanner like ALT+I .
And your application then needs a keyboardshortcut to get a note everytime a barcode gets scanned. We are using this method in our factory successfull (Symbol & Datalogic scanners).

BR Klaus

_________________
http://www.PureBasicPower.de


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Sat May 15, 2010 12:43 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 710
Location: Russia
The official website of the program BASCOM (compiler for microcontrollers) are placed several devices, computer programs which are written in PureBasic using the library HID_Lib.

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
 
 Post subject: Re: HID_Lib - Library
PostPosted: Mon Nov 01, 2010 5:45 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 710
Location: Russia
Updated list of libraries

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
 
 Post subject: Re: USB HID Library
PostPosted: Sun Jul 24, 2011 9:43 pm 
Offline
New User
New User

Joined: Sun Jul 24, 2011 9:35 pm
Posts: 3
hi, thanks for the library, but probably there is a bug:
1. HID_Lib_DeviceTest is 1 means ok
2. HID_Lib_OpenDevice is 0 means failure (by the way GetLastError_() returns 0)

my device is custom usb mouse.

I think this can help:

Why do I receive "Access denied" when attempting to access my HID?

Windows 2000 and later have exclusive read/write access to HIDs that are configured as a system keyboards or mice. An application can obtain a handle to a system keyboard or mouse by not requesting READ or WRITE access with CreateFile. Applications can then use HidD_SetFeature and HidD_GetFeature (if the device supports Feature reports).

see http://www.lvr.com/hidfaq.htm


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 54 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye