像C这样的Java Write / Read硬件端口如何? (出,在...等)

时间:2014-05-22 08:44:49

标签: java hardware-port

我有一个C应用程序。该应用程序写入和读取一些I / O端口地址。

我认为Java本身无法访问低级I / O地址。我是对的吗?

以下是C ++应用程序的示例:

#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <sys/io.h>

int main(int argc, char *argv[])
{
    cout << "Refresh watchdog program" << endl;

    outb(0x87,0x2E);     //Extended Function Mode
    outb(0x30,0x2E);     //Set Watch Dog Timer Activate
    outb(0x01,0x2F);
    int reg = inb(0x2f);
    outb(reg|0x08, 0x2f);

}

我怎样才能在Java中做同样的事情?

1 个答案:

答案 0 :(得分:3)

我认为sun.misc.Unsafe可能会帮助你。它有void putAddress(long address, long value)等方法可能适合您的需要。说实话,我还没有做过这个,但你可以从

了解更多

http://mydailyjava.blogspot.co.uk/2013/12/sunmiscunsafe.html

http://mishadoff.github.io/blog/java-magic-part-4-sun-dot-misc-dot-unsafe/

http://highlyscalable.wordpress.com/2012/02/02/direct-memory-access-in-java/

可以在

上找到一个小样本程序

http://robaustin.wikidot.com/how-to-write-to-direct-memory-locations-in-java