Frage

i am using java library rxtxx to send data to micro controller the application seems to work but a warning comes up :rxtxx2.1.7 version mismatch will it affect the sent data ?? I have tested it but no data was sent my code is:

    import java.util.*;
import gnu.io.*;
import java.io.*;



public class portwrit{
    static Enumeration        portList;
    static CommPortIdentifier portId;
   static String msgstr="100";
    static SerialPort         serialPort;
    static OutputStream       outputStream;
    static  InputStream inputStream;
    static  Thread readThread;


    static boolean        outputBufferEmptyFlag = false;

    public static void main(String[] args ) throws NoSuchPortException, PortInUseException {
    boolean portFound = false;
    String defaultPort = "COM6";


    portList = CommPortIdentifier.getPortIdentifiers();

    while (portList.hasMoreElements()) {
        portId = (CommPortIdentifier) portList.nextElement();

        if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

        if (portId.getName().equals(defaultPort)) {
            System.out.println("Found port " + defaultPort);
            portFound = true;
            try {
            serialPort = 
                (SerialPort) portId.open("SimpleWrite", 2000);
            } catch (PortInUseException e) {
            System.out.println("Port in use.");
            continue;
            } 

            try {
            outputStream = serialPort.getOutputStream();
            } catch (IOException e) {}

            try {
            serialPort.setSerialPortParams(9600, 
                               SerialPort.DATABITS_8, 
                               SerialPort.STOPBITS_1, 
                               SerialPort.PARITY_NONE);
            } catch (UnsupportedCommOperationException e) {}

            try {
                serialPort.notifyOnOutputEmpty(true);
            } catch (Exception e) {
            System.out.println("Error setting event notification");
            System.out.println(e.toString());
            System.exit(-1);
            }

            System.out.println(
                "Writing "+msgstr+"\" to "+serialPort.getName());
            try {
            outputStream.write(Byte.parseByte(msgstr));
            } catch (IOException e) {}

            try {
               Thread.sleep(2000);  // Be sure data is xferred before closing
            } catch (Exception e) {}
            serialPort.close();
            System.exit(1);

        } 
        } 
    } 

    if (!portFound) {
        System.out.println("port " + defaultPort + " not found.");
    } 
    } 


}
War es hilfreich?

Lösung

According to this article you may have multiple copies of the RXTX software installed. It suggests looking for comm.jar or RXTXcomm.jar or similar on your path/classpath.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top