我从上上个礼拜开始接触,公司需要,所以开始在网上搜索相关资料,但是都没有找到合适的范例,但万幸终于测试出合适的代码。
import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.usb.*;
public class UsbTest {
private static short idVendor = ...;
private static short idProduct = ...;
public static void main(String[] args) {
try {
UsbPipe sendUsbPipe = new UsbTest().useUsb();
String string = "..." ;
byte[] buff =string.getBytes();
sendMassge(sendUsbPipe, buff);
} catch (Exception e1) {
e1.printStackTrace();
}
}
public UsbPipe useUsb() throws Exception{
UsbInterface iface = linkDevice();
if (iface == null) {
return null;
}
UsbEndpoint receivedUsbEndpoint,sendUsbEndpoint;
sendUsbEndpoint = (UsbEndpoint)iface.getUsbEndpoints().get(0);
if (!sendUsbEndpoint.getUsbEndpointDescriptor().toString().contains("OUT")) {
receivedUsbEndpoint = sendUsbEndpoint;
sendUsbEndpoint = (UsbEndpoint)iface.getUsbEndpoints().get(1