1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| package portserie;
import java.io.*;
public class SerialTest {
public static void main( String args[]) {
Runtime rt = Runtime.getRuntime();
Process p = null;
String portname = "com1:";
String cmd[] = {
"c:\\windows\\system32\\cmd.exe", "/c",
"start", "/min",
"c:\\windows\\system32\\mode.com", portname,
"baud=9600", "parity=n", "data=8",
"stop=1",
};
try {
p = rt.exec( cmd );
if( p.waitFor() != 0 ) {
System.out.println("Error executing commznd: " + cmd );
System.exit( -1 );
}
byte data[] =
"Hello world".getBytes();
FileOutputStream fos = new FileOutputStream( portname );
BufferedOutputStream bos = new BufferedOutputStream( fos );
fos.write( data, 0, data.length );
fos.close();
}
catch( Exception e ) {
e.printStackTrace();
}
}
} |
Partager