I want to write some hex data to the serial port and read back some data. I have a problem in the reading (reads nothing) could someone help???
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
public class Test {
public static void main(String[] args) throws IOException {
char c='s';
ProcessBuilder builder = new ProcessBuilder("c:\\windows\\system32\\mode.com", "portname",
"baud=115200", "parity=n", "data=8","stop=1");
Map<String, String> environ = builder.environment();
String portname="com6";
final Process process = builder.start();
String x="";
byte data[] = {(byte)0xF5, (byte)0xfa, (byte)0x01, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0xfe, (byte)0x0f};
FileOutputStream fos = new FileOutputStream(portname );
BufferedOutputStream bos = new BufferedOutputStream( fos );
fos.flush();
fos.write( data);
fos.close();
bos.close();
FileInputStream fstream1 = new FileInputStream(portname);
DataInputStream in = new DataInputStream(fstream1);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
int n = 0;
while ((n =(char) in.read()) !=-1 ){
System.out.println((char)fstream1.read());
}
}
}