I dont know what JNI means but I think it's about Streams an stuff? Well here is how
I did it on short anyway:
import java.lang.*;
import java.io.*;
//import java.net.*;
public class RTListener1 implements Runnable{
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ****** VARIABLER ******
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public Thread listen = null;
DataInputStream in;
String fifoIn;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ****** KONSTRUKTORER ******
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public RTListener1(String fifo) {
fifoIn = fifo;
}
//-------------- connectRTFifo -------------------
public int connectRTFifo(String rtFifoIn) {
try {
in = new DataInputStream(
new BufferedInputStream(new FileInputStream(rtFifoIn),8));
// in = new DataInputStream(new FileInputStream(rtFifoIn));
} catch (IOException e) {
return -1; // RTFifo not oppend-ERROR!
}
listen = new Thread (this);
listen.setPriority(Thread.MAX_PRIORITY);
listen.start();
return 0; // RTLinux connected
}
//-------------- run -----------------------------
public void run() {
byte[] dataInHead = new byte[Protocol.HEADSIZE];
while (!Thread.interrupted()) {
Message m = new Message();
try {
in.readFully(dataInHead); // reads msgSize:nr of bytes
m.msgType = dataInHead[0];
m.dataLength = dataInHead[1];
m.dataType = dataInHead[2];
m.NU = dataInHead[3];
switch (m.msgType) {
......... reacieve according to your protocol......
}
useData(m);
} catch (IOException e) {
...error...
break;
}
}
}
//-------------- useMsg --------------------------
private void useData(Message m) {
switch (m.msgType) {
......
//-------------- closeRTFifo ---------------------
public int closeRTFifo() {
listen.interrupt();
listen = null;
try {
in.close();
} catch (IOException e) {
return -1; // error when closing RTFifo-ERROR!
}
return 0; // RTFifo closed!
}
//--------------------------------------------------
}
/++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
import java.io.*;
public class RTSender1 {
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ****** VARIABLER ******
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DataOutputStream streamOut;
String fifoOut;
..... same as before...
//-------------- connectRTFifo -------------------
public int connectRTFifo(String rtFifo) {
try {
streamOut = new DataOutputStream(new FileOutputStream(rtFifo));
} catch (IOException e) {
return -1; // RTFifo ej oppnad-ERROR!
}
return 0; // RTFifo from Java to RTLinux connected
}
//-------------- send ----------------------------
public int send(byte type, int data) {
try {
streamOut.writeByte(type);
streamOut.writeInt(data);
} catch (IOException e) {
return -1; // !!
}
return 0;
}
//-------------- closeRTFifo ---------------------
public int closeRTFifo() {
try {
streamOut.close();
} catch (IOException e) {
return -1; // error when closing RTFifo-ERROR!
}
return 0; // RTFifo closed!
}
//--------------------------------------------------
Hope it can help in anyway.
/Marcus
Cyrille AUFFRET wrote:
> Hi ,
> I've red in the mailing list that it was possible to interface java with
> RTLinux with JNI (Java Native Interface).
> Does somebody has experienced this solution and if there is another solution?
> In fact I'm using RTAI but it's very similar.
> I need to communicate with a process Java through fifos. I'm a begginner in
> Java and I need some help. Does somedy could send me
> a sample code with JNI?
> Thanks by advance and sorry for my english.
>
> -- [rtl] ---
> To unsubscribe:
> echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
> echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
> --
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/rtlinux/
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/