gpt4 book ai didi

java - 使用 jusbpmp lib 时出错

转载 作者:行者123 更新时间:2023-12-01 10:53:15 24 4
gpt4 key购买 nike

我正在尝试用 Java 访问 USB 端口。我正在使用 Jusbpmp 0.1.5 和 Java 1.7.0_45。我尝试在 Mac OS X 中测试它,但出现以下错误。

java.lang.Exception: Unknown OS

at jpmp.manager.DeviceManager.loadPmpLib(Unknown Source)
at jpmp.manager.DeviceManager.<init>(Unknown Source)
at jpmp.manager.DeviceManager.getInstance(Unknown Source)
at USB.main(USB.java:12)

这是我的代码:

import java.util.Iterator;
import java.util.LinkedList;
import jpmp.device.UsbDevice;
import jpmp.manager.DeviceManager;
import jpmp.notifier.IDeviceTransferNotifier;
import jpmp.notifier.IParseTreeNotifier;

public class USB {
public static void main(String[] args) {
try{
DeviceManager dm = DeviceManager.getInstance();
dm.createInstance();
dm.scanDevices();
Iterator it = dm.getDeviceList().keySet().iterator();
String devkey = (String)it.next();
UsbDevice usbdev = (UsbDevice)dm.getDeviceList().get(devkey);
System.out.println(usbdev.dump());
}catch(Exception e){
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
}
//USB 연결확인 함수
static boolean isConnected(String filterProductName, String filterProductid, String filterVendorid){
try {

DeviceManager dm;
dm = DeviceManager.getInstance();
dm.createInstance();
dm.scanDevices();

if (dm.getDeviceList() != null && dm.getDeviceList().size() > 0) {
for (Iterator it = dm.getDeviceList().keySet().iterator(); it.hasNext();) {
String devkey = (String) it.next();
UsbDevice usbdev = (UsbDevice) dm.getDeviceList().get(devkey);
if ((usbdev.getPid().equals(filterProductid) && usbdev.getVid().equals(filterVendorid)) || usbdev.getName().equals(filterProductName)) {
return true;
}
}
}
} catch (Throwable ex) {
ex.printStackTrace();
}
return false;
}
//USB 파일전송 함수
static void TransUsb() throws Throwable{
DeviceManager dm = DeviceManager.getInstance();
dm.createInstance();
dm.scanDevices();

String filterProductid = "0x2211"; //productid
String filterVendorid = "0x0ea0"; //vendorid

UsbDevice usbdevFound = null;
if (dm.getDeviceList() != null && dm.getDeviceList().size()>0){
for ( Iterator it = dm.getDeviceList().keySet().iterator(); it.hasNext(); ){
String devkey = (String)it.next();
UsbDevice usbdev = (UsbDevice)dm.getDeviceList().get(devkey);
if (usbdev.getPid().equals(filterProductid) && usbdev.getVid().equals(filterVendorid)){
usbdevFound = usbdev;

}
}
}

if (usbdevFound != null) {
String fileToSend = "C:\\videofile.avi";
usbdevFound.sendFile(fileToSend, "/Video", null, null);
}

dm.releaseInstance();
}
}

错误发生在线路上:

DeviceManager dm = DeviceManager.getInstance();

最佳答案

引用自jusbpmp home page (强调我的):

Jusbpmp is a Java library that allows to communicate with portable USB players (supporting MSC or MTP) on Linux or Windows.

看来这个库不适用于 Mac OS。

另一种方法是使用 usb4java ,明确支持 Linux、OS X 和 Windows:

Supported platforms are Linux (x86 32/64 bit, ARM 32 bit), OS X (x86 32/64 bit) and Windows (x86 32/64 bit). But other platforms may work as well (as long as they have at least Java 6 and are supported by libusb) by compiling the JNI library manually.

关于java - 使用 jusbpmp lib 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33734405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com