B4J Question [Solved] jSerial on Mac

yo3ggx

Active Member
Licensed User
Longtime User
HI,

I have an application that use USBserial devices through the jSerial library.
Everything is working as expected on Windows and Linux, but on Mac not all available serial ports are listed with serial.ListPorts.
For example CH340 modules are listed, but CP2105 or Bluetooth Serial not. The official SILAB drivers are correctly installed on the Mac.
In other Mac applications (ex. SerialTools) all serial ports are correctly listed.

The available virtual serial ports are shown on Mac as:
/dev/tty.Bluetooth-Incoming-Port
/dev/tty.SLAB_USBtoUART
/dev/tty.SLAB_USBtoUART2
/dev/tty.usbserial-14140 <----- only this one is listed.

The rights on the 4 ports are the same:
crw-rw-rw- 1 root wheel 0x16000006 Nov 9 14:50 /dev/tty.Bluetooth-Incoming-Port
crw-rw-rw- 1 root wheel 0x16000002 Nov 9 15:44 /dev/tty.SLAB_USBtoUART
crw-rw-rw- 1 root wheel 0x16000004 Nov 9 15:44 /dev/tty.SLAB_USBtoUART2
crw-rw-rw- 1 root wheel 0x16000000 Nov 9 15:44 /dev/tty.usbserial-14140


I'm running the application through b4j-bridge, so jssc library for Mac is not used.

Any hints on how to solve this?
 
Last edited:

yo3ggx

Active Member
Licensed User
Longtime User
Seems that the issue is related to the jssc library.
https://github.com/FabehaMalik04/java-simple-serial-connector/issues/16
On a Mac, the library list only the ports containing tty.serial.* or tty-usbserial.*

Update: Checked the jssc source code for the latest version and recompiled the libjssc for Mac. The pattern is ok, but still /dev/cu.* devices are not listed.
I think the problem is in the jSerial library. Is jSerial library source code available?
I want to check with different SerialPortList.getPortNames() formats based on OS.

B4X:
  if (SerialNativeInterface.getOsType() == SerialNativeInterface.OS_MAC_OS_X) {
    // for MAC OS default pattern of jssc library is too restrictive
    portNames = SerialPortList.getPortNames("/dev/", Pattern.compile("cu\\..*"));
  } else {
    portNames = SerialPortList.getPortNames();
  }

https://www.tabnine.com/code/java/methods/jssc.SerialPortList/getPortNames
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…