本文整理汇总了Java中javax.usb.UsbPipe类的典型用法代码示例。如果您正苦于以下问题:Java UsbPipe类的具体用法?Java UsbPipe怎么用?Java UsbPipe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UsbPipe类属于javax.usb包,在下文中一共展示了UsbPipe类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: sendMessage
import javax.usb.UsbPipe; //导入依赖的package包/类
/**
* Sends an ADB Message.
*
* @param message
* The message to send.
* @throws UsbException
* When USB communication failed.
*/
public void sendMessage(Message message) throws UsbException
{
UsbEndpoint outEndpoint =
this.iface.getUsbEndpoint(this.outEndpoint);
UsbPipe outPipe = outEndpoint.getUsbPipe();
MessageHeader header = message.getHeader();
outPipe.open();
try
{
int sent = outPipe.syncSubmit(header.getBytes());
if (sent != MessageHeader.SIZE)
throw new InvalidMessageException(
"Invalid ADB message header size sent: " + sent);
sent = outPipe.syncSubmit(message.getData());
if (sent != header.getDataLength())
throw new InvalidMessageException(
"Data size mismatch in sent ADB message. Should be "
+ header.getDataLength() + " but is " + sent);
}
finally
{
outPipe.close();
}
}
开发者ID:usb4java,项目名称:usb4java-javax-examples,代码行数:33,代码来源:AdbDevice.java
示例2: sendBulkTransfer
import javax.usb.UsbPipe; //导入依赖的package包/类
private int sendBulkTransfer(UsbEndpoint usbEndpoint, byte[] data) throws UsbException{
int returnCode = -1;
if(UsbConst.ENDPOINT_DIRECTION_OUT == usbEndpoint.getDirection()){
mLogger.debug("sendBulkTransfer - direction: OUT, byteString: {}", getByteString(data));
}
UsbPipe usbPipe = usbEndpoint.getUsbPipe();
if (usbPipe != null) {
if(!usbPipe.isOpen()){
usbPipe.open();
}
if (usbPipe.isOpen()) {
UsbIrp usbIrp = usbPipe.createUsbIrp();
usbIrp.setData(data);
//TODO: data length does not need to be set explicitly
// int dataLength = (data == null) ? 0 : data.length;
// usbIrp.setLength(dataLength);
usbPipe.syncSubmit(usbIrp);
if (!usbIrp.isUsbException()) {
returnCode = usbIrp.getActualLength();
} else {
// throw usbControlIrp.getUsbException();
usbIrp.getUsbException().printStackTrace();
}
} else {
mLogger.error("usbPipe open ERROR");
}
} else {
mLogger.error("usbPipe is NULL");
}
if(UsbConst.ENDPOINT_DIRECTION_IN == usbEndpoint.getDirection()){
//TODO: show type of packet in debug log
mLogger.debug("sendBulkTransfer - direction: IN, byteString: {}", getByteString(data));
}
return returnCode;
}
开发者ID:fredg02,项目名称:se.bitcraze.crazyflie.lib,代码行数:40,代码来源:UsbLinkJava.java
示例3: testDataEvent
import javax.usb.UsbPipe; //导入依赖的package包/类
/**
* Tests the data event.
*/
@Test
public void testDataEvent()
{
final UsbPipeDataEvent event =
new UsbPipeDataEvent(mock(UsbPipe.class), null);
final UsbPipeListener a = mock(UsbPipeListener.class);
final UsbPipeListener b = mock(UsbPipeListener.class);
this.list.add(a);
this.list.add(b);
this.list.dataEventOccurred(event);
verify(a).dataEventOccurred(event);
verify(b).dataEventOccurred(event);
}
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:17,代码来源:PipeListenerListTest.java
示例4: testErrorEvent
import javax.usb.UsbPipe; //导入依赖的package包/类
/**
* Tests the error event.
*/
@Test
public void testErrorEvent()
{
final UsbPipeErrorEvent event =
new UsbPipeErrorEvent(mock(UsbPipe.class), new UsbException());
final UsbPipeListener a = mock(UsbPipeListener.class);
final UsbPipeListener b = mock(UsbPipeListener.class);
this.list.add(a);
this.list.add(b);
this.list.errorEventOccurred(event);
verify(a).errorEventOccurred(event);
verify(b).errorEventOccurred(event);
}
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:17,代码来源:PipeListenerListTest.java
示例5: receiveMessage
import javax.usb.UsbPipe; //导入依赖的package包/类
/**
* Receives an ADB message.
*
* @return The received ADB message.
* @throws UsbException
* When USB communication failed.
*/
public Message receiveMessage() throws UsbException
{
UsbEndpoint inEndpoint =
this.iface.getUsbEndpoint(this.inEndpoint);
UsbPipe inPipe = inEndpoint.getUsbPipe();
inPipe.open();
try
{
byte[] headerBytes = new byte[MessageHeader.SIZE];
int received = inPipe.syncSubmit(headerBytes);
if (received != MessageHeader.SIZE)
throw new InvalidMessageException(
"Invalid ADB message header size: " + received);
MessageHeader header = new MessageHeader(headerBytes);
if (!header.isValid())
throw new InvalidMessageException(
"ADB message header checksum failure");
byte[] data = new byte[header.getDataLength()];
received = inPipe.syncSubmit(data);
if (received != header.getDataLength())
throw new InvalidMessageException(
"ADB message data size mismatch. Should be "
+ header.getDataLength() + " but is " + received);
Message message = Message.create(header, data);
if (!message.isValid())
throw new InvalidMessageException(
"ADB message data checksum failure");
return message;
}
finally
{
inPipe.close();
}
}
开发者ID:usb4java,项目名称:usb4java-javax-examples,代码行数:42,代码来源:AdbDevice.java
示例6: getUsbPipe
import javax.usb.UsbPipe; //导入依赖的package包/类
@Override
public UsbPipe getUsbPipe()
{
return this.pipe;
}
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:6,代码来源:Endpoint.java
注:本文中的javax.usb.UsbPipe类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论