08/01/23 21:43:13
:プログラム:
//rs232c.java
import java.io.*;
import java.util.*;
import java.text.*;
import javax.comm.*;
import gnu.io.UnsupportedCommOperationException;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
class rs232c1{
public static void main(String args[]){
byte rs232c[];
rs232c = new byte[10];
try{
CommPortIdentifier ports = CommPortIdentifier.getPortIdentifier( "COM1" );
SerialPort port = ( SerialPort )ports.open( "RS232C", 1000 );
port.setSerialPortParams( 9600,SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE );
port.setFlowControlMode( SerialPort.FLOWCONTROL_NONE );
InputStream in232c = port.getInputStream();
//読み込み
in232c.read(rs232c);
System.out.println("read="+rs232c);
in232c.close();
port.close();
}
catch( Exception e ) {
System.out.println( "Error:" + e.getMessage() );
}
}
}