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: Select all
#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