JSSC not recognizing Arduino board

82 views Asked by At

I am trying to use the JSSC library to connect to my Arduino Nano. I have a driver for my Mac, and it works with the Arduino editor, and everything, but the JSSC library won't recognize the board. No errors, just doesn't find my board.

Here's my code:

package com.apstamp45.arduino_test;

import jssc.SerialPortList;

/**
 * This class is used to comunicate with
 * an Arduino through a serial port using
 * the JSSC library.
 * @see https://github.com/scream3r/java-simple-serial-connector/releases/tag/v2.8.0
 * @author apstamp45
 * @since 10/20/2020
 */
public class Main {
    
    /**
     * The main method.
     * @param args The command line arguments.
     */
    public static void main(String[] args) {
        String[] portNames = SerialPortList.getPortNames();
        for (int i = 0; i < portNames.length; i++) {
            System.out.println(portNames[i]);
        }
    }
}

Any advice would be very much appreciated.

1

There are 1 answers

0
apstamp45 On

In SerialPortList.java line 56:

PORTNAMES_REGEXP = Pattern.compile("tty.(serial|usbserial|usbmodem).*");

The regular expression doesn't contain the usb type of the Arduino Nano (or all boards idk). Fix this by changing the line to:

PORTNAMES_REGEXP = Pattern.compile("tty.((serial|usbserial|usbmodem).*|wchusbserial*)");

This lets the library recognize this usb type.