Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用java控制Windows上的通用键盘应用程序?_Java_Serial Port_Rxtx - Fatal编程技术网

如何用java控制Windows上的通用键盘应用程序?

如何用java控制Windows上的通用键盘应用程序?,java,serial-port,rxtx,Java,Serial Port,Rxtx,我正在尝试开发一个通用键盘的应用程序,用于控制摄像机。我能够在Linux over/dev/ttyACM0伪终端设备上以某种基本方式与设备通信。但据我所知,这在Windows中并不存在,当我检查comm API和rxtx库的示例时,我有点困惑 我怎样才能像在Linux上那样与这个设备通信?这是键盘使用说明手册: 代码如下: Class1.java package customkeyboard; import java.io.FileInputStream; import org.apache.

我正在尝试开发一个通用键盘的应用程序,用于控制摄像机。我能够在Linux over/dev/ttyACM0伪终端设备上以某种基本方式与设备通信。但据我所知,这在Windows中并不存在,当我检查comm API和rxtx库的示例时,我有点困惑

我怎样才能像在Linux上那样与这个设备通信?这是键盘使用说明手册:

代码如下:

Class1.java

package customkeyboard;

import java.io.FileInputStream;
import org.apache.commons.codec.binary.Hex;

public class CustomKeyboard {

    public static void main(String[] args) {
        // TODO code application logic here
        FileInputStream in = null;
        try {
            in = new FileInputStream("/dev/ttyACM0");
            int c = 0;

            int streamCounter = 0;
            String command = "";
            CustomKeyboard2 key2 = new CustomKeyboard2();
            key2.main(null);
            while ((c = in.read()) != -1) {
                if (streamCounter < 6) {
                    //System.out.print( + " - ");
                    command += Integer.toHexString(c);
                    streamCounter++;
                    if (streamCounter == 6) {
                        streamCounter = 0;
                        System.out.println(command);
                        byte[] bytes = Hex.decodeHex(command.toCharArray());
                        String deastranza = new String ( bytes, "UTF-8");
                        System.out.println(deastranza);
                        command = "";
                }
            } else {
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
package customkeyboard;

import java.io.FileOutputStream;
import org.apache.commons.codec.binary.Hex;

public class CustomKeyboard2 {
    public static void main(String[] args) {
        try {
            FileOutputStream out = null;
            out = new FileOutputStream("/dev/ttyACM0");
            String command = "[LedImmediate]";
            byte[] message = command.getBytes("UTF-8");
            out.write(message);

            command = "[Led+45]";
            message = command.getBytes();
            out.write(message);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

说真的,伙计们,还是没有答案??:/