<< hid_open HID Basic's commands hid_read_timeout >>

USB Comunication Toolbox for Scilab >> HIDAPI Library > HID Basic's commands > hid_read

hid_read

Read or receive a buffer from an USB HID Device

Calling Sequence

[rxBuff,read_success]=hid_read(_size);

Parameters

rxBuff
: Buffer to be read or transfer to the USB HID Device. The type of the data in the buffer has to be unsigned integer of 8 bits
_size
: Size of the buffer to be read into the USB HID Device. The type of _size has to be unsigned integer of 8 bits
read_success
: retun 0 if device has been read and -1 if the device can not be read. Check the USB HID device is properly connected to the host computer and properly opened.

Description

Read an HID USB Device

Read the data buffer sent by the USB HID 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.

Examples

n=5;
txBuff=init_buff(n);
for i=1:n
    txBuff=setBuffValue(txBuff,i,i);
end
VendorID="04D8";
ProductID="010B";
VendorID=uint16(hex2dec(VendorID));
ProductID=uint16(hex2dec(ProductID));
init_success=hid_init();
if ( init_success < 0 ) then
   disp("unable to initialize the HIDAPI Library");
   return
else
   disp("HIDAPI Library initialized");
end
open_success=hid_open(VendorID,ProductID);
if ( open_success < 0 ) then
   disp("unable to open device");
   return
else
   disp("device open");
end
write_success=hid_write(txBuff,uint8(n));
if ( write_success < 0 ) then
   disp("unable to write device");
else
   disp("device have been  written");
end
nonblocking_success=hid_set_nonblocking(%t);
if ( nonblocking_success < 0 ) then
   disp("unable to set nonblocking");
else
   disp("device have been set nonblocking");
end
[rxBuff,read_success]=hid_read(uint8(n));
if ( read_success < 0 ) then
   disp("unable to read device");
else
   disp("device have been read");
   disp(rxBuff);
end
close_success=hid_close();  
if ( close_success < 0 ) then
   disp("unable to closed device");
else
   disp("device closed");
end
exit_success=hid_exit();
if ( init_success < 0 ) then
   disp("unable to free static data associated with HIDAPI Library");
   return
else
   disp("HIDAPI Library have been freed all of the static data associated");
end

See Also

Authors

<< hid_open HID Basic's commands hid_read_timeout >>