RS232, Pleo Interface and Java

#pleo#java

So just for references, issuing commands through a serial interface can be very handy at times. Rather than pushing the code to a repository I’ll just paste it in here. This code runs on mac but any bash equipped system would probably do.

import java.io.*;

public class main {
	private static final long serialVersionUID = 1L;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		System.out.println("Issuing serial command...");
		String gulle; String rfid; String data; String command; String tag1;
		gulle = "/dev/ttyACM0";
		rfid = "/dev/ttyUSB0";
		tag1 = "358AF2";

		command = "sound play test_ok";
		System.out.println(rfid);
		try{
		    BufferedReader inFil = new BufferedReader(new FileReader(rfid));
	            BufferedWriter outFil = new BufferedWriter(new FileWriter(gulle));

	            while(true){
			data = inFil.readLine();
			System.out.println(data.substring(0, 6));
			if((data.substring(0, 6)).equals(tag1)){
				System.out.println(command);
				outFil.write(command);
				ProcessBuilder pb = new ProcessBuilder("bash",                                       "-c", "echo "sound play test_ok" > /dev/ttyACM0");
				final Process p = pb.start();

				Thread.sleep(1000);
				p.destroy();
		        }
		    }
                } catch(Exception e){System.out.println(e);}

	}

}

all writing