Read or receive a buffer from an USB Device with timeout
[rxBuff,read_success]=bulk_read_timeout(_size,_timeout);
Read an USB Device
Read the data buffer sent by the USB Device
Keep in mind that USB 2.0 and older are a master/slave protocol. The USB device will send data only if the master (the host, its mean the computer), asked for it.
n=5; txBuff=init_buff(n); for i=1:n txBuff=setBuffValue(txBuff,i,i); end VendorID="04D8"; ProductID="0204"; VendorID=uint16(hex2dec(VendorID)); ProductID=uint16(hex2dec(ProductID)); enpIn=1; enpOut=1; enpIn=uint16(enpIn); enpOut=uint16(enpOut); timeout=100; timeout=int32(timeout); n=uint8(n) init_success=bulk_init(); if ( init_success < 0 ) then disp("unable to initialize the Libusb-1.0 Library"); return else disp("Libusb-1.0 Library initialized"); end open_success=bulk_open(VendorID,ProductID); if ( open_success < 0 ) then disp("unable to open device"); return else disp("device open"); end endP_success=bulk_set_endpoint(enpIn,enpOut); if ( endP_success < 0 ) then disp("unable to set end points"); else disp("end points has been set"); end write_success=bulk_write(txBuff,n); if ( write_success < 0 ) then disp("unable to write device"); else disp("device have been written"); end [rxBuff,read_success]=bulk_read(n,timeout); if ( read_success < 0 ) then disp("unable to read device"); else disp("device have been read"); disp(rxBuff); end close_success=bulk_close(); if ( close_success < 0 ) then disp("unable to closed device"); else disp("device closed"); end exit_success=bulk_exit(); if ( init_success < 0 ) then disp("unable to free static data associated with Libusb-1.0 Library"); return else disp("Libusb-1.0 Library have been freed all of the static data associated"); end | ![]() | ![]() |