PC hardware port access from Java on Linux

喜夏-厌秋 提交于 2019-12-11 07:55:27

问题


What is the Java-on-Linux equivalent to the C byte-sized PC-architecture hardware port input/output functions?

For output there is outb as in this:

tmp = inb(0x61);
if (tmp != (tmp | 0x01)) 
    outb(0x61, tmp | 0x01);

For input there is inb as in this:

tmp = (inb(0x61) & 0xfe);
outb(0x61, tmp);

Purpose: I want to implement something that imposes less overhead than this:

try { Runtime.getRuntime().exec("beep") } catch (IOException e) {}

as an alternative to sending code 7 (the bell char) to the standard output because that seems to have been aggressively disabled in Ubuntu. Toolkit's beep is also mute.


回答1:


I think you're barking up the wrong train.

Java is a object-oriented high-level language compiling to a virtual machine architecture. Assembler I/O instructions are hardware processor specific. There is no direct equivalence between the two.

The best you could hope for is to interface your Java code (using pipes, shared memory, sockets, etc) with a native Linux app which performs the required I/O.



来源:https://stackoverflow.com/questions/8925489/pc-hardware-port-access-from-java-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!