LordShade Posted January 5, 2016 Share Posted January 5, 2016 Hello. I am want to send and receive data to/from standard "USB HID device" ( physically it is an atmega chip with V-USB library on it ). How can I do it? Can anyone post examples please? Link to comment Share on other sites More sharing options...
LordShade Posted January 5, 2016 Author Share Posted January 5, 2016 or may be anyone has a UDF? Link to comment Share on other sites More sharing options...
LordShade Posted January 5, 2016 Author Share Posted January 5, 2016 I am found the example for PureBasic, that uses HID_Lib, so that is what I need, but on AutoIt:#USB_PID=$F4EF#USB_VID=$AB80Global W_DeviceHandle=0, R_DeviceHandle=0 ; Глобальные переменныеProcedure FindDevice_Timer() ; periodically find usb device connectionStatic Old_TestTest=HID_Lib_DeviceTest(#USB_PID, #USB_VID) ; Устройство подключено (1), или нет (0) If Test<>Old_Test Old_Test=Test If Test ; Если устройство подключили HID_Lib_CloseDevice(W_DeviceHandle) HID_Lib_CloseDevice(R_DeviceHandle) R_DeviceHandle=HID_Lib_OpenDevice(#USB_PID, #USB_VID) ; Получаем доступ для чтения W_DeviceHandle=HID_Lib_OpenDevice(#USB_PID, #USB_VID) ; и записи в устройство. SetGadgetText(1,"Подключено HID устройство") DisableGadget(2,0) : DisableGadget(3,0) Else ; Если устройство отключили HID_Lib_CloseDevice(W_DeviceHandle) ; Освобождаем ресурсы, связанные с ним HID_Lib_CloseDevice(R_DeviceHandle) W_DeviceHandle=0 : R_DeviceHandle=0 SetGadgetText(1,"Устройство не обнаружено") SetGadgetText(5,"Отпущена") DisableGadget(2,1) : DisableGadget(3,1) EndIf EndIfEndProcedureProcedure SendDevice(Command.a) ; Передача команды USB устройству. Dim Out.a(2) Out(0) = 0 Out(1) = Command If W_DeviceHandle HID_Lib_WriteDevice(W_DeviceHandle, @Out(),2) ; Запись данных (2 байта) в устройство Else MessageRequester("", "Нет связи с устройством!", 48) EndIfEndProcedureProcedure Thread(*xx) ; Эта процедура выполняется в отдельном потоке. Dim In.a(2) Repeat If R_DeviceHandle In(0) = 0 If HID_Lib_ReadDevice(R_DeviceHandle, @In(), 2) = 2 ; Чтение данных из USB устройства. If In(1) = 0 SetGadgetText(5,"Нажата") Else SetGadgetText(5,"Отпущена") EndIf EndIf EndIf Delay(10) ForEverEndProcedureOpenWindow(0,0,0,320,100,"Пример работы с HID устройством",#PB_Window_MinimizeGadget|#PB_Window_Invisible|#PB_Window_ScreenCentered) TextGadget(1,10,10,300,16,"Устройство не обнаружено",#PB_Text_Center) ButtonGadget(2,40,70,120,24,"Зажечь светодиод") : DisableGadget(2,1) ButtonGadget(3,170,70,120,24,"Погасить светодиод") : DisableGadget(3,1) TextGadget(4,50,40,108,16,"Состояние кнопки:") StringGadget(5,158,36,70,20,"Отпущена",1|#PB_String_ReadOnly)FindDevice_Timer()HideWindow(0,0)AddWindowTimer(0,2,200) ; Запуск таймера, с периодом генерации событий 200 милисекундCreateThread(@Thread(),0) ; Запуск кода процедуры Thread() в отдельном потокеRepeat ; Главный цикл программы Event=WaitWindowEvent() If Event=#PB_Event_Gadget ; Произошло событие в одном из гаджетов Select EventGadget() Case 2 ; Клик по кнопке "Зажечь светодиод" SendDevice(1) Case 3 ; Клик по кнопке "Погасить светодиод" SendDevice(0) EndSelect ElseIf Event=#PB_Event_Timer If EventTimer()=2 FindDevice_Timer() EndIf EndIf Link to comment Share on other sites More sharing options...
Danyfirex Posted January 5, 2016 Share Posted January 5, 2016 Do you have some .dll to work with? Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
LordShade Posted January 6, 2016 Author Share Posted January 6, 2016 No, I have not. But I think I can use standard libusb0.dll, but I don't know how. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now