1

I am working wit GPS and Pi4J. I am working with gps from adafuith and USB to TTL cable. But when I try to open serial it seem to give me a error. I can see the gps when I type in

ls /dev | grep USB

the error I get is where the line is

result=serirequired: int

the error message

found:    void
al.open(comPort, 4800);

working for this tutorial

my code

String comPort = "/dev/ttyUSB0";
serial.addListener(new SerialDataListener() {
    @Override
    public void dataReceived(SerialDataEvent event) {
        System.out.print("We received some data!");
    }            
});

//result=serial.open(comPort,2400);
int result=serial.open(comPort, 4800);
if ( result == -1 ) {
    System.out.println("Failed to open COM port!");
    return;
} else {
    System.out.println("COM port opened!");
}
try {
     // - Sleep for 20 seconds, (in ms)
    Thread.sleep(20000);

    // - Close port
    serial.close();
    System.out.println("COM port closed.");
} catch ( Exception ex ) {
    // - I am intentionally ignoring any exception.
}
1

serial.open(comPort, 4800) doesn't return a value. the signature of serial.open(...) is

void serial.open(String device, int baudrate);

try this:

serial.open(comPort, 4800);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.