Changeset 229
- Timestamp:
- 08/12/08 18:10:57 (5 years ago)
- Location:
- branches/behrens/libusb_win_example
- Files:
-
- 2 modified
-
USB_Test_modified.m (modified) (9 diffs)
-
libusb_win_proto.m (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/behrens/libusb_win_example/USB_Test_modified.m
r228 r229 12 12 %packet = hex2dec(['01';'02';'03';'04']); 13 13 DevHandle = USBTest_OpenHandle(); 14 [ok] = USBTest_SendPacket(ton, DevHandle); 14 15 % play tones 16 for i=200:50:200 17 ton(1) = 128; % Direct command no reply 18 ton(2) = 3; %PLAYTONE 19 ton(3:4)=typecast(int16(i), 'uint8'); %frequency [Hz] Uword 200-14000 Hz 20 ton(5:6)=typecast(int16(200), 'uint8'); %duration [ms] Uword 21 22 [ok] = USBTest_SendPacket(ton, DevHandle); 23 % if ok > 0 24 % [len data] = USBTest_RecievePacket(DevHandle); 25 % fprintf('\nAntwortlaenge (PlayTon): %d\n', len); 26 % end 27 pause(0.3); 28 end 29 30 % get battery level 31 packet = [0;11]; % Direct command no reply / GetBatteryLevel 32 [ok] = USBTest_SendPacket(packet, DevHandle); 15 33 if ok > 0 16 [len data] = USBTest_RecievePacket(DevHandle); 17 fprintf('\nAntwortlaenge (PlayTon): %d\n', len); 18 if len == 3 19 [ok] = USBTest_SendPacket(packet, DevHandle); 20 if ok > 0 21 [len data] = USBTest_RecievePacket(DevHandle); 22 fprintf('\nAntwortlaenge (GetSpannung): %d\n', len); 23 if len == 5 24 fprintf('Restspannung in mV: %d\n', wordbytes2dec(data(4:5),2)); 25 end 26 end 27 end 34 [len data] = USBTest_RecievePacket(DevHandle); 35 fprintf('\nAntwortlaenge (GetSpannung): %d\n', len); 36 if len == 5 37 fprintf('Restspannung in mV: %d\n', wordbytes2dec(data(4:5),2)); 38 end 28 39 end 40 41 % % get inputstate 42 % packet = [0;7;0]; 43 % [ok] = USBTest_SendPacket(packet, DevHandle); 44 % if ok > 0 45 % [len data] = USBTest_RecievePacket(DevHandle); 46 % fprintf('\nAntwortlaenge (GetSpannung): %d\n', len); 47 % BlockTachoCount = wordbytes2dec(data(19:22), 4, 'signed') %signed 48 % % if len == 5 49 % % fprintf('Restspannung in mV: %d\n', wordbytes2dec(data(4:5),2)); 50 % % end 51 % end 52 53 % % get outputstate 54 % packet = [0;6;0]; 55 % [ok] = USBTest_SendPacket(packet, DevHandle); 56 % if ok > 0 57 % [len data] = USBTest_RecievePacket(DevHandle); 58 % fprintf('\nAntwortlaenge (GetSpannung): %d\n', len); 59 % BlockTachoCount = wordbytes2dec(data(19:22), 4, 'signed') %signed 60 % % if len == 5 61 % % fprintf('Restspannung in mV: %d\n', wordbytes2dec(data(4:5),2)); 62 % % end 63 % end 64 % [ok] = USBTest_SendPacket(ton, DevHandle); 65 % if ok > 0 66 % [len data] = USBTest_RecievePacket(DevHandle); 67 % fprintf('\nAntwortlaenge (PlayTon): %d\n', len); 68 % if len == 3 69 % [ok] = USBTest_SendPacket(packet, DevHandle); 70 % if ok > 0 71 % [len data] = USBTest_RecievePacket(DevHandle); 72 % fprintf('\nAntwortlaenge (GetSpannung): %d\n', len); 73 % if len == 5 74 % fprintf('Restspannung in mV: %d\n', wordbytes2dec(data(4:5),2)); 75 % end 76 % end 77 % end 78 % end 29 79 USBTest_Close(DevHandle); 30 80 … … 36 86 37 87 % int ret = usb_bulk_write(nxt->hdl, 0x1, buf, len, 10000); 38 hp = char(uint8(packet)); % setstr depriciated88 hp = uint8(packet); % setstr depriciated 39 89 fprintf('\nSending USB packet (%s), total len = %d bytes... \n', dec2hex(hp), length(hp)); 40 ret = calllib(USBLIB, 'usb_bulk_write', DevHandle, 1, hp, length(packet), 100 00);90 ret = calllib(USBLIB, 'usb_bulk_write', DevHandle, 1, hp, length(packet), 100); 41 91 if ret < 0 42 92 msg = ['Libusb error ' num2str(ret) ' while sending data: ' getLibusbErrorString(ret)]; … … 53 103 data = []; 54 104 % int ret = usb_bulk_read(nxt->hdl, 0x82, buf, len, 500); 55 buffer = char(uint8(blanks(64))); 105 % buffer = char(uint8(blanks(64))); 106 buffer = uint8(zeros(64,1)); 107 buffer = uint8(zeros(1,64)); 56 108 % vp = libpointer('voidPtr',buffer); 57 ret= calllib(USBLIB, 'usb_bulk_read', DevHandle, uint8(130), buffer, 64, 500);109 [ret something reply] = calllib(USBLIB, 'usb_bulk_read', DevHandle, uint8(130), buffer, 64, 500); 58 110 if ret < 0 59 111 msg = ['Libusb error ' num2str(ret) ' while recieving data: ' getLibusbErrorString(ret)]; … … 63 115 recBytes = ret; 64 116 data = buffer(1:ret); 117 data = reply; 65 118 end 66 119 end … … 83 136 if ~libisloaded(USBLIB) 84 137 % use "our" wrapper file... 85 loadlibrary(USBLIB, @ usblib_proto);138 loadlibrary(USBLIB, @libusb_win_proto); 86 139 end 87 140 … … 259 312 disp(' . discarding any data') 260 313 buffer = char(uint8(blanks(64))); 314 buffer = uint8(zeros(64,1)); 261 315 ret = 1; 262 316 while ret > 0 … … 271 325 % } 272 326 disp(' . open stream modus') 327 buffer = char(uint8(blanks(64))); 273 328 ret = calllib(USBLIB, 'usb_control_msg', DevHandle, 65, 3, 0, 0, buffer, 0, 1000); 274 329 if ret < 0 … … 301 356 % usb_bulk_write(nxt->hdl, 0x1, buf, 0, 1000); 302 357 buffer = blanks(64); 358 buffer = uint8(zeros(64,1)); 303 359 calllib(USBLIB, 'usb_bulk_read', DevHandle, 1, buffer, 0, 1000); 304 360 % // Turn off stream mode 305 361 % usb_control_msg(nxt->hdl, 0x41, 0x1, 0, 0, NULL, 0, 5000); 362 buffer = blanks(64); 306 363 calllib(USBLIB, 'usb_control_msg', DevHandle, 65, 1, 0, 0, buffer, 0, 5000); 307 364 % // Discard any data that is left in the buffer … … 310 367 ret = 1; 311 368 while ret > 0 369 buffer = uint8(zeros(64,1)); 312 370 ret = calllib(USBLIB, 'usb_bulk_read', DevHandle, 130, buffer, 64, 1); 313 371 end -
branches/behrens/libusb_win_example/libusb_win_proto.m
r228 r229 20 20 fcns.name{fcnNum}='usb_get_descriptor'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'usb_dev_handlePtr', 'uint8', 'uint8', 'voidPtr', 'int32'};fcnNum=fcnNum+1; 21 21 % int usb_bulk_write ( usb_dev_handle * dev , int ep , char * bytes , int size , int timeout ); 22 fcns.name{fcnNum}='usb_bulk_write'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'usb_dev_handlePtr', 'int32', ' cstring', 'int32', 'int32'};fcnNum=fcnNum+1;22 fcns.name{fcnNum}='usb_bulk_write'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'usb_dev_handlePtr', 'int32', 'voidPtr', 'int32', 'int32'};fcnNum=fcnNum+1; 23 23 % int usb_bulk_read ( usb_dev_handle * dev , int ep , char * bytes , int size , int timeout ); 24 fcns.name{fcnNum}='usb_bulk_read'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'usb_dev_handlePtr', 'int32', ' cstring', 'int32', 'int32'};fcnNum=fcnNum+1;24 fcns.name{fcnNum}='usb_bulk_read'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'usb_dev_handlePtr', 'int32', 'voidPtr', 'int32', 'int32'};fcnNum=fcnNum+1; 25 25 % int usb_interrupt_write ( usb_dev_handle * dev , int ep , char * bytes , int size , int timeout ); 26 26 fcns.name{fcnNum}='usb_interrupt_write'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'usb_dev_handlePtr', 'int32', 'cstring', 'int32', 'int32'};fcnNum=fcnNum+1;
