/* * * IMU.java 1.0 * Main PRogram for Serial Communication * * Created: March 27, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * qjiang@tsinghua.edu * */
import java.io.*;
class IMU { public static void main(String[] args) { //TO DO: Add your JAVA codes here
File ComPort = new File("COM1");
SerialBuffer SB = new SerialBuffer(); ReadSerial r1 = new ReadSerial(SB, ComPort); ReadBuffer r2 = new ReadBuffer(SB); WriteSerial r3 = new WriteSerial(ComPort);
r1.start(); r2.start(); r3.start(); } }
/* * * ReadBuffer.java 1.0 * Program to Read the Serial Buffer * * Created: March 27, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * qjiang@tsinghua.edu
* */
import java.io.*;
public class ReadBuffer extends Thread { private SerialBuffer ComBuffer;
public ReadBuffer(SerialBuffer SB) { ComBuffer = SB; }
public void run() { String Msg;
while (true) { Msg = ComBuffer.GetMsg(); System.out.println(Msg); }
} }
/* * * ReadSerial.java 1.0 * Program to read characters from the serial port and put it * to the buffer * * Created: March 27, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * qjiang@tsinghua.edu * */
import java.io.*;
public class ReadSerial extends Thread { private SerialBuffer ComBuffer; private File ComPort;
public void run() { int c; try { FileReader in = new FileReader(ComPort); while (true) { c = in.read(); ComBuffer.PutChar(c); } try { FileReader in = new FileReader(ComPort); while (true) { c = in.read();
public synchronized void PutChar(int c) { Character d = new Character((char) c); Content = Content.concat(d.toString()); if (c == '*') { available = true; } notifyAll(); } }
/* * * WriteSerial.java 1.0 * Program to send a character to the serial port * * Created: March 27, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * qjiang@tsinghua.edu * */
import java.io.*;
public class WriteSerial extends Thread { private SerialBuffer ComBuffer; private File ComPort;
public WriteSerial(File Port) { ComPort = Port; }
public void run() { int c; try { FileWriter out = new FileWriter(ComPort); while (true) { out.write('*'); } } catch (IOException e) { System.out.println(e.getMessage()); } } } /* * * SendCom.java 1.0 * * Project: Java Based Information Exchange Support System * Onboard Plug-in System * Sending data through serial port * * Created: March 15, 2001 * * Author : Qingye Jiang (John) * American GNC Corporation * 888 Easy St, Simi Valley CA 93065-1812 * * Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax) * */