Fazecast / jSerialComm

Platform-independent serial port access for Java
GNU Lesser General Public License v3.0
1.32k stars 279 forks source link

Error open port: lastErrorCode:25 lastErrorLocation:758 #543

Open nunoms86 opened 7 months ago

nunoms86 commented 7 months ago

Can I obtain more info about the reason for the following error? lastErrorCode:25 lastErrorLocation:758

This code is working in systems with apparently the same specs/OS, I'm lost on why is not woking on the others...

Code:

serialPort = SerialPort.getCommPort(comPort);
serialPort.setComPortParameters(9600,8,1,SerialPort.NO_PARITY, false);
serialPort.disablePortConfiguration();
serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
if(!serialPort.openPort(500)){
          LOG.log(Level.WARNING, "Printer.init openPort failed: comPort:{0} lastErrorCode:{1} lastErrorLocation:{2}", new Object[]{comPort, serialPort.getLastErrorCode(), serialPort.getLastErrorLocation()});
      }
}

Output: Printer.init openPort failed: comPort:/dev/usb/lp0 lastErrorCode:25 lastErrorLocation:758

Host/OS info: Raspberry 4 JDK 1.8 and version 2.10.4 of the library.

root@rpi4:~# cat /etc/os-release PRETTY_NAME="Raspbian GNU/Linux 10 (buster)" NAME="Raspbian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)" VERSION_CODENAME=buster ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/" SUPPORT_URL="http://www.raspbian.org/RaspbianForums" BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

root@rpi4:~# uname -a Linux rpi4 5.4.79-v7l+ #1373 SMP Mon Nov 23 13:27:40 GMT 2020 armv7l GNU/Linux

hedgecrw commented 4 months ago

I'm not sure about this. From what I can tell "/dev/usb/lp0" is a printer device (not a true serial/tty device), and the error code 25 at the indicated line corresponds to the Linux error ENOTTY. So perhaps the underlying device driver for talking to this device emulates TTY better on some devices than on others (or the driver is different between the systems you are seeing where it works vs. where it doesn't). In either case, this doesn't seem like something I can do anything about from the library side of things.

nunoms86 commented 1 week ago

In the same system we can open the port for read/write with no error using our native code 🤔

Our C code (JNI) that works: open( "/dev/usb/lp0", O_RDWR | O_NOCTTY);