Code: Select all
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class SOtest {
public static void main(String[] args) {
SOtest sot = new SOtest();
sot.rx(); // or sot.tx() for the transmit side
}
public void tx() {
FileOutputStream nmoutfile;
try {
nmoutfile = new FileOutputStream("/dev/ttyS0");
nmoutfile.write(49); // ascii value 10 still needed...?
nmoutfile.close(); // doesn't force value 49 to send
} catch (Exception ex) {
System.out.println(ex.getMessage().toString());
}
}
public void rx() {
FileInputStream nminfile;
try {
nminfile = new FileInputStream("/dev/ttyS0");
while (true) {
System.out.println(nminfile.read());
}
} catch (Exception ex) {
System.out.println(ex.getMessage().toString());
}
}
}