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() {
    public void dataReceived(SerialDataEvent event) {
        System.out.print("We received some data!");

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

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

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.