Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"pkg test arduino" is very slow on Mac #5

Open
dasergatskov opened this issue Mar 12, 2025 · 26 comments
Open

"pkg test arduino" is very slow on Mac #5

dasergatskov opened this issue Mar 12, 2025 · 26 comments

Comments

@dasergatskov
Copy link

Running "pkg test arduino" is very slow on Mac (almost 10x slower than on linux; the same board)

octave:9> pkg test arduino
Testing functions in package 'arduino':

Integrated test scripts:

                                                                                  [ CPU    /  CLOCK ]
  ../api-v60/packages/arduino-0.12.1/+arduinoio/boardTypeString.m  pass    1/1    [ 0.001s /  0.001s]
  ..e/api-v60/packages/arduino-0.12.1/+arduinoio/getBoardConfig.m  pass    1/1    [ 0.001s /  0.001s]
  ..are/octave/api-v60/packages/arduino-0.12.1/@arduino/arduino.m  pass    5/5    [ 0.312s / 103.673s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/checkI2CAddress.m  pass    1/1    [ 0.087s / 33.298s]
  ..ctave/api-v60/packages/arduino-0.12.1/@arduino/configurePin.m  pass    1/1    [ 0.101s / 33.345s]
  ..i-v60/packages/arduino-0.12.1/@arduino/configurePinResource.m  pass    2/2    [ 0.091s / 33.274s]
  ..v60/packages/arduino-0.12.1/@arduino/decrementResourceCount.m  pass    1/1    [ 0.105s / 33.295s]
  ..e/octave/api-v60/packages/arduino-0.12.1/@arduino/getEndian.m  pass    1/1    [ 0.086s / 33.286s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/getI2CTerminals.m  pass    1/1    [ 0.094s / 33.280s]
  ..-v60/packages/arduino-0.12.1/@arduino/getInterruptTerminals.m  pass    1/1    [ 0.061s / 33.250s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/getLEDTerminals.m  pass    1/1    [ 0.076s / 33.264s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/@arduino/getMCU.m  pass    1/1    [ 0.079s / 33.262s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/getPWMTerminals.m  pass    1/1    [ 0.087s / 33.282s]
  ..octave/api-v60/packages/arduino-0.12.1/@arduino/getPinAlias.m  pass    1/1    [ 0.083s / 33.275s]
  ../octave/api-v60/packages/arduino-0.12.1/@arduino/getPinInfo.m  pass    4/4    [ 0.097s / 33.289s]
  ..i-v60/packages/arduino-0.12.1/@arduino/getPinsFromTerminals.m  pass    3/3    [ 0.089s / 33.277s]
  ..e/api-v60/packages/arduino-0.12.1/@arduino/getResourceCount.m  pass    1/1    [ 0.081s / 33.275s]
  ..e/api-v60/packages/arduino-0.12.1/@arduino/getResourceOwner.m  pass    1/1    [ 0.077s / 33.269s]
  ../packages/arduino-0.12.1/@arduino/getSharedResourceProperty.m  pass    1/1    [ 0.082s / 33.267s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/getTerminalMode.m  pass    1/1    [ 0.091s / 33.305s]
  ..v60/packages/arduino-0.12.1/@arduino/incrementResourceCount.m  pass    1/1    [ 0.085s / 33.271s]
  ..e/api-v60/packages/arduino-0.12.1/@arduino/isTerminalAnalog.m  pass    6/6    [ 0.114s / 33.304s]
  ../api-v60/packages/arduino-0.12.1/@arduino/isTerminalDigital.m  pass    7/7    [ 0.120s / 33.311s]
  ..re/octave/api-v60/packages/arduino-0.12.1/@arduino/playTone.m  pass    4/4    [ 0.138s / 33.391s]
  ..tave/api-v60/packages/arduino-0.12.1/@arduino/readAnalogPin.m  pass    6/6    [ 0.163s / 33.518s]
  ..ave/api-v60/packages/arduino-0.12.1/@arduino/readDigitalPin.m  pass    5/5    [ 0.134s / 33.428s]
  ..octave/api-v60/packages/arduino-0.12.1/@arduino/readVoltage.m  pass    6/6    [ 0.116s / 33.560s]
  ..share/octave/api-v60/packages/arduino-0.12.1/@arduino/reset.m  pass    1/1    [ 0.057s / 34.302s]
  ..octave/api-v60/packages/arduino-0.12.1/@arduino/sendCommand.m  pass    7/7    [ 0.096s / 33.416s]
  ../packages/arduino-0.12.1/@arduino/setSharedResourceProperty.m  pass    1/1    [ 0.059s / 33.281s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/@arduino/uptime.m  pass    1/1    [ 0.060s / 34.335s]
  ..octave/api-v60/packages/arduino-0.12.1/@arduino/validatePin.m  pass    6/6    [ 0.088s / 33.337s]
  ..are/octave/api-v60/packages/arduino-0.12.1/@arduino/version.m  pass    1/1    [ 0.058s / 33.298s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/writeDigitalPin.m  pass    5/5    [ 0.101s / 33.419s]
  ../api-v60/packages/arduino-0.12.1/@arduino/writePWMDutyCycle.m  pass    8/8    [ 0.096s / 33.373s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/writePWMVoltage.m  pass    8/8    [ 0.092s / 33.365s]
  ..share/octave/api-v60/packages/arduino-0.12.1/@device/device.m  pass    4/4    [ 0.440s / 130.220s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/@device/subsref.m  pass    1/1    [ 0.107s / 33.426s]
  ..re/octave/api-v60/packages/arduino-0.12.1/@device/writeRead.m  pass    3/3    [ 0.303s / 96.347s]
  ..share/octave/api-v60/packages/arduino-0.12.1/@i2cdev/i2cdev.m  pass    2/2    [ 0.149s / 62.799s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/@i2cdev/subsref.m  pass    1/1    [ 0.098s / 33.325s]
  ..ve/api-v60/packages/arduino-0.12.1/@rotaryEncoder/readCount.m  pass    2/2    [ 0.146s / 33.478s]
  ..ve/api-v60/packages/arduino-0.12.1/@rotaryEncoder/readSpeed.m  pass    1/1    [ 0.105s / 33.371s]
  ..e/api-v60/packages/arduino-0.12.1/@rotaryEncoder/resetCount.m  pass    1/1    [ 0.110s / 33.401s]
  ..pi-v60/packages/arduino-0.12.1/@rotaryEncoder/rotaryEncoder.m  pass    5/5    [ 0.186s / 33.656s]
  ..tave/api-v60/packages/arduino-0.12.1/@rotaryEncoder/subsref.m  pass    1/1    [ 0.108s / 33.421s]
  ../octave/api-v60/packages/arduino-0.12.1/@servo/readPosition.m  pass    2/2    [ 0.149s / 33.507s]
  ..l/share/octave/api-v60/packages/arduino-0.12.1/@servo/servo.m  pass    3/3    [ 0.105s / 33.374s]
  ..share/octave/api-v60/packages/arduino-0.12.1/@servo/subsref.m  pass    1/1    [ 0.100s / 33.326s]
  ..octave/api-v60/packages/arduino-0.12.1/@servo/writePosition.m  pass    3/3    [ 0.151s / 33.445s]
  ..pi-v60/packages/arduino-0.12.1/@shiftRegister/shiftRegister.m  pass    1/1    [ 0.137s / 33.487s]
  ..tave/api-v60/packages/arduino-0.12.1/@shiftRegister/subsref.m  pass    1/1    [ 0.111s / 33.372s]
  ..share/octave/api-v60/packages/arduino-0.12.1/@spidev/spidev.m  pass    3/3    [ 0.358s / 96.681s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/@spidev/subsref.m  pass    1/1    [ 0.102s / 33.417s]
  ..re/octave/api-v60/packages/arduino-0.12.1/@spidev/writeRead.m  pass    3/3    [ 0.262s / 96.327s]
  ..ve/api-v60/packages/arduino-0.12.1/@ultrasonic/readDistance.m  pass    2/2    [ 0.111s / 33.363s]
  ..ve/api-v60/packages/arduino-0.12.1/@ultrasonic/readEchoTime.m pass    2/2    [ 0.108s / 33.350s]
  ../octave/api-v60/packages/arduino-0.12.1/@ultrasonic/subsref.m  pass    1/1    [ 0.095s / 33.348s]
  ..tave/api-v60/packages/arduino-0.12.1/@ultrasonic/ultrasonic.m  pass    4/4    [ 0.285s / 129.362s]
  ..share/octave/api-v60/packages/arduino-0.12.1/sensors/bme280.m  pass    1/1    [ 0.004s /  0.004s]
  ..share/octave/api-v60/packages/arduino-0.12.1/sensors/bno055.m  pass    1/1    [ 0.004s /  0.004s]
  ..share/octave/api-v60/packages/arduino-0.12.1/sensors/lis3dh.m  pass    1/1    [ 0.002s /  0.002s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/sensors/lps22hb.m  pass    1/1    [ 0.003s /  0.003s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/sensors/lsm6dso.m  pass    1/1    [ 0.003s /  0.003s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/sensors/mpu6050.m  pass    1/1    [ 0.002s /  0.002s]
  ..share/octave/api-v60/packages/arduino-0.12.1/sensors/si7021.m  pass    1/1    [ 0.002s /  0.002s]
  ..i/.local/share/octave/api-v60/packages/arduino-0.12.1/addon.m  pass    1/1    [ 0.144s / 33.374s]
  ..ocal/share/octave/api-v60/packages/arduino-0.12.1/isarduino.m  pass    5/5    [ 0.079s / 33.270s]
  ..octave/api-v60/packages/arduino-0.12.1/listArduinoLibraries.m  pass    4/4    [ 0.074s /  0.074s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/scanForArduinos.m  pass    3/3    [ 0.088s / 59.387s]
  ..cal/share/octave/api-v60/packages/arduino-0.12.1/scanI2Cbus.m  pass    1/1    [ 0.474s / 35.745s]

Fixed test scripts:

                                                        total time (CPU / CLOCK)  [   8.6s / 2547.6s]
Summary:

  PASS                              172
  FAIL                                0

On linux those "33.3 sec" test are "4.5 sec".
My wild guess is that the board does not register "End-of-Comm" and just times out.
I do not have Arduinio IDE on Mac, I programmed it on linx and rhen plugged it into Mac.
The board is SparkFun UNO clone.

@dasergatskov
Copy link
Author

Not sure if that helps:

octave:24> tic; test @arduino/configurePin; toc
PASSES 1 out of 1 test
Elapsed time is 30.3114 seconds.
octave:25> profile off
octave:26> profshow
   #                                                                                           Function Attr     Time (s)   Time (%)        Calls
-------------------------------------------------------------------------------------------------------------------------------------------------
 118                                                                                    @arduino/delete            20.045      66.14            5
  71                                                                                              pause             8.013      26.44            4
  85                                                                                      __srlp_read__             1.638       5.40           30
  70                                                                                         serialport             0.526       1.74            4

@dasergatskov
Copy link
Author

dasergatskov commented Mar 15, 2025

I looked around and I think the issue is with scanning for arduino on the weird ports like /dev/tty.Bluetooth-Incoming-Port
(/dev/tty.debug-console also took few seconds). So, short of writing serialport_class_macos I did some cheating (two steps). First, blacklist some ports with names to be unlikely an arduino port ; second, search the serial port list in reverse order since arduinos tend to be near the end. Here is the diff:

diff --git a/inst/scanForArduinos.m b/inst/scanForArduinos.m
index cf56848..ea110c3 100644
--- a/inst/scanForArduinos.m
+++ b/inst/scanForArduinos.m
@@ -154,12 +154,35 @@
 
   # get list of serial ports to try
   ports = serialportlist ();
-
-  for i = 1:numel (ports)
+  
+  # Filter out ports that are unlikely to be Arduino
+  filtered_ports = {};
+  for i = 1:numel(ports)
+    port_lower = lower(ports{i});
+    # Skip Bluetooth ports and other unlikely ports
+    if strfind(port_lower, "bluetooth") || ...
+       strfind(port_lower, "airpods") || ...
+       strfind(port_lower, "phone") || ...
+       strfind(port_lower, "console") || ...
+       strfind(port_lower, "debug") || ...
+       strfind(port_lower, "irda") || ...
+       strfind(port_lower, "virtual")
+      if debug_flag
+        printf("* skipping unlikely port: %s\n", ports{i});
+      endif
+    else
+      filtered_ports{end+1} = ports{i};
+    endif
+  endfor
+  
+  # Scan ports in reverse order since Arduino ports are typically at the end
+  for i = numel(filtered_ports):-1:1
+#  for i = 1:numel (ports)
     try
       s = {};
       unwind_protect
-        portname = ports{i};
+#        portname = ports{i};
+        portname = filtered_ports{i};
 
         if debug_flag
           printf("* trying comport %s\n", portname);   

I also reduced the pause in __initArduino__.m to 1 sec. For my board 0.5 was too short.
With all these I see:

octave:9> pkg test arduino
Testing functions in package 'arduino':

Integrated test scripts:

                                                                                  [ CPU    /  CLOCK ]
  ../api-v60/packages/arduino-0.12.1/+arduinoio/boardTypeString.m  pass    1/1    [ 0.004s /  0.004s]
  ..e/api-v60/packages/arduino-0.12.1/+arduinoio/getBoardConfig.m  pass    1/1    [ 0.001s /  0.001s]
  ..are/octave/api-v60/packages/arduino-0.12.1/@arduino/arduino.m  pass    5/5    [ 0.218s /  8.799s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/checkI2CAddress.m  pass    1/1    [ 0.055s /  2.501s]
  ..ctave/api-v60/packages/arduino-0.12.1/@arduino/configurePin.m  pass    1/1    [ 0.061s /  2.548s]
  ..i-v60/packages/arduino-0.12.1/@arduino/configurePinResource.m  pass    2/2    [ 0.052s /  2.481s]
  ..v60/packages/arduino-0.12.1/@arduino/decrementResourceCount.m  pass    1/1    [ 0.061s /  2.485s]
  ..e/octave/api-v60/packages/arduino-0.12.1/@arduino/getEndian.m  pass    1/1    [ 0.048s /  2.473s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/getI2CTerminals.m  pass    1/1    [ 0.051s /  2.475s]
  ..-v60/packages/arduino-0.12.1/@arduino/getInterruptTerminals.m  pass    1/1    [ 0.061s /  2.482s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/getLEDTerminals.m  pass    1/1    [ 0.070s /  2.488s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/@arduino/getMCU.m  pass    1/1    [ 0.060s /  2.477s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/getPWMTerminals.m  pass    1/1    [ 0.064s /  2.488s]
  ..octave/api-v60/packages/arduino-0.12.1/@arduino/getPinAlias.m  pass    1/1    [ 0.059s /  2.480s]
  ../octave/api-v60/packages/arduino-0.12.1/@arduino/getPinInfo.m  pass    4/4    [ 0.080s /  2.502s]
  ..i-v60/packages/arduino-0.12.1/@arduino/getPinsFromTerminals.m  pass    3/3    [ 0.074s /  2.497s]
  ..e/api-v60/packages/arduino-0.12.1/@arduino/getResourceCount.m  pass    1/1    [ 0.065s /  2.482s]
  ..e/api-v60/packages/arduino-0.12.1/@arduino/getResourceOwner.m  pass    1/1    [ 0.065s /  2.495s]
  ../packages/arduino-0.12.1/@arduino/getSharedResourceProperty.m  pass    1/1    [ 0.067s /  2.491s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/getTerminalMode.m  pass    1/1    [ 0.070s /  2.515s]
  ..v60/packages/arduino-0.12.1/@arduino/incrementResourceCount.m  pass    1/1    [ 0.066s /  2.478s]
  ..e/api-v60/packages/arduino-0.12.1/@arduino/isTerminalAnalog.m  pass    6/6    [ 0.099s /  2.533s]
  ../api-v60/packages/arduino-0.12.1/@arduino/isTerminalDigital.m  pass    7/7    [ 0.102s /  2.539s]
  ..re/octave/api-v60/packages/arduino-0.12.1/@arduino/playTone.m  pass    4/4    [ 0.120s /  2.622s]
  ..tave/api-v60/packages/arduino-0.12.1/@arduino/readAnalogPin.m  pass    6/6    [ 0.140s /  2.748s]
  ..ave/api-v60/packages/arduino-0.12.1/@arduino/readDigitalPin.m  pass    5/5    [ 0.109s /  2.591s]
  ..octave/api-v60/packages/arduino-0.12.1/@arduino/readVoltage.m  pass    6/6    [ 0.160s /  2.795s]
  ..share/octave/api-v60/packages/arduino-0.12.1/@arduino/reset.m  pass    1/1    [ 0.066s /  3.500s]
  ..octave/api-v60/packages/arduino-0.12.1/@arduino/sendCommand.m  pass    7/7    [ 0.114s /  2.727s]
  ../packages/arduino-0.12.1/@arduino/setSharedResourceProperty.m  pass    1/1    [ 0.072s /  2.502s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/@arduino/uptime.m  pass    1/1    [ 0.072s /  3.534s]
  ..octave/api-v60/packages/arduino-0.12.1/@arduino/validatePin.m  pass    6/6    [ 0.098s /  2.521s]
  ..are/octave/api-v60/packages/arduino-0.12.1/@arduino/version.m  pass    1/1    [ 0.064s /  2.508s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/writeDigitalPin.m  pass    5/5    [ 0.129s /  2.645s]
  ../api-v60/packages/arduino-0.12.1/@arduino/writePWMDutyCycle.m  pass    8/8    [ 0.119s /  2.592s]
  ..ve/api-v60/packages/arduino-0.12.1/@arduino/writePWMVoltage.m  pass    8/8    [ 0.117s /  2.586s]
  ..share/octave/api-v60/packages/arduino-0.12.1/@device/device.m  pass    4/4    [ 0.515s /  9.671s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/@device/subsref.m  pass    1/1    [ 0.131s /  2.700s]
  ..re/octave/api-v60/packages/arduino-0.12.1/@device/writeRead.m  pass    3/3    [ 0.289s /  6.611s]
  ..share/octave/api-v60/packages/arduino-0.12.1/@i2cdev/i2cdev.m  pass    2/2    [ 0.124s /  3.768s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/@i2cdev/subsref.m  pass    1/1    [ 0.082s /  2.556s]
  ..ve/api-v60/packages/arduino-0.12.1/@rotaryEncoder/readCount.m  pass    2/2    [ 0.146s /  2.734s]
  ..ve/api-v60/packages/arduino-0.12.1/@rotaryEncoder/readSpeed.m  pass    1/1    [ 0.094s /  2.615s]
  ..e/api-v60/packages/arduino-0.12.1/@rotaryEncoder/resetCount.m  pass    1/1    [ 0.100s /  2.642s]
  ..pi-v60/packages/arduino-0.12.1/@rotaryEncoder/rotaryEncoder.m  pass    5/5    [ 0.146s /  2.896s]
  ..tave/api-v60/packages/arduino-0.12.1/@rotaryEncoder/subsref.m  pass    1/1    [ 0.065s /  2.570s]
  ../octave/api-v60/packages/arduino-0.12.1/@servo/readPosition.m  pass    2/2    [ 0.086s /  2.608s]
  ..l/share/octave/api-v60/packages/arduino-0.12.1/@servo/servo.m  pass    3/3    [ 0.074s /  2.589s]
  ..share/octave/api-v60/packages/arduino-0.12.1/@servo/subsref.m  pass    1/1    [ 0.038s /  2.500s]
  ..octave/api-v60/packages/arduino-0.12.1/@servo/writePosition.m  pass    3/3    [ 0.092s /  2.621s]
  ..pi-v60/packages/arduino-0.12.1/@shiftRegister/shiftRegister.m  pass    1/1    [ 0.088s /  2.687s]
  ..tave/api-v60/packages/arduino-0.12.1/@shiftRegister/subsref.m  pass    1/1    [ 0.060s /  2.560s]
  ..share/octave/api-v60/packages/arduino-0.12.1/@spidev/spidev.m  pass    3/3    [ 0.278s /  6.861s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/@spidev/subsref.m  pass    1/1    [ 0.084s /  2.649s]
  ..re/octave/api-v60/packages/arduino-0.12.1/@spidev/writeRead.m  pass    3/3    [ 0.171s /  6.473s]
  ..ve/api-v60/packages/arduino-0.12.1/@ultrasonic/readDistance.m  pass    2/2    [ 0.093s /  2.585s]
  ..ve/api-v60/packages/arduino-0.12.1/@ultrasonic/readEchoTime.m  pass    2/2    [ 0.086s /  2.576s]
  ../octave/api-v60/packages/arduino-0.12.1/@ultrasonic/subsref.m  pass    1/1    [ 0.063s /  2.566s]
  ..tave/api-v60/packages/arduino-0.12.1/@ultrasonic/ultrasonic.m  pass    4/4    [ 0.196s /  8.750s]
  ..share/octave/api-v60/packages/arduino-0.12.1/sensors/bme280.m  pass    1/1    [ 0.005s /  0.005s]
  ..share/octave/api-v60/packages/arduino-0.12.1/sensors/bno055.m  pass    1/1    [ 0.005s /  0.005s]
  ..share/octave/api-v60/packages/arduino-0.12.1/sensors/lis3dh.m  pass    1/1    [ 0.003s /  0.003s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/sensors/lps22hb.m  pass    1/1    [ 0.003s /  0.003s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/sensors/lsm6dso.m  pass    1/1    [ 0.004s /  0.004s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/sensors/mpu6050.m  pass    1/1    [ 0.004s /  0.004s]
  ..share/octave/api-v60/packages/arduino-0.12.1/sensors/si7021.m  pass    1/1    [ 0.002s /  0.002s]
  ..i/.local/share/octave/api-v60/packages/arduino-0.12.1/addon.m  pass    1/1    [ 0.127s /  2.596s]
  ..ocal/share/octave/api-v60/packages/arduino-0.12.1/isarduino.m  pass    5/5    [ 0.051s /  2.477s]
  ..octave/api-v60/packages/arduino-0.12.1/listArduinoLibraries.m  pass    4/4    [ 0.100s /  0.100s]
  ..hare/octave/api-v60/packages/arduino-0.12.1/scanForArduinos.m  pass    3/3    [ 0.041s /  2.494s]
  ..cal/share/octave/api-v60/packages/arduino-0.12.1/scanI2Cbus.m  pass    1/1    [ 0.411s /  5.066s]

Fixed test scripts:

                                                        total time (CPU / CLOCK)  [   7.2s /  194.6s]
Summary:

  PASS                              172
  FAIL                                0

@lostbard
Copy link
Collaborator

serialportlist is very naive in instrument control grabbing anything thats /dev/tty.*
Not sure if theres something better it could be doing as well as something similar happening in arduino

@lostbard
Copy link
Collaborator

Interestly, the change makes it take longer for me on my fedora machine.
I believe because serialport list returns:

{
[1,1] = /dev/ttyACM0
[2,1] = /dev/ttyS0
[3,1] = /dev/ttyS1
[4,1] = /dev/ttyS10
[5,1] = /dev/ttyS11
[6,1] = /dev/ttyS12
[7,1] = /dev/ttyS13
[8,1] = /dev/ttyS14
[9,1] = /dev/ttyS15
[10,1] = /dev/ttyS16
[11,1] = /dev/ttyS17
[12,1] = /dev/ttyS18
[13,1] = /dev/ttyS19
[14,1] = /dev/ttyS2
....
}
So the reversed list try tries the serial port last.

@lostbard
Copy link
Collaborator

perhaps a change that effects just mac:

@@ -155,6 +155,30 @@ function arduinos = scanForArduinos (varargin)
   # get list of serial ports to try
   ports = serialportlist ();
 
+  if ismac()
+    filtered_ports = {};
+    for i = 1:numel(ports)
+      port_lower = lower(ports{i});
+      # Skip Bluetooth ports and other unlikely ports
+      if strfind(port_lower, "bluetooth") || ...
+         strfind(port_lower, "airpods") || ...
+         strfind(port_lower, "phone") || ...
+         strfind(port_lower, "console") || ...
+         strfind(port_lower, "debug") || ...
+         strfind(port_lower, "irda") || ...
+         strfind(port_lower, "virtual")
+
+        if debug_flag
+          printf("* skipping unlikely port: %s\n", ports{i});
+        endif
+      else
+        # add in reverse order since arduinos are typically at the end
+        filtered_ports = [ports{i}; filtered_ports];
+      endif
+    endfor
+    ports = filtered_ports;
+  endif
+

@dasergatskov
Copy link
Author

dasergatskov commented Mar 18, 2025

Absolutely. I timed it and it was really hanging on "closing" on Bluetooth port (see the profile trace above). Does it need to wait for something, could it just hang up?
I was also plugging my board into different machines and noticed it was always on the last port (with the names like "USB", "usbserial-3120" on Mac), so I thought why not to switch the order? But I guess if you board name starts with "A" it is a different story. On my main linux machine there are 32 serial ports but flies through them in no time so the change was minimal (though noticeable). On my mac there were 3 ports -- one is Bluetooth, one is debug-console, and one is arduino. So blacklist pretty much eliminated all but arduino.

I have also noticed that a = arduino() would still make two connections (I guess one is during scanning, and another one is for the final connection), so perhaps this could be optimized further, but may be it is OK as it is.

@dasergatskov
Copy link
Author

BTW, most of the names in this backlist I just made up. I had one "Bluetooth" and another is "debug-console" so I just thought what else could be on the Mac?

@lostbard
Copy link
Collaborator

For the closing, Im not sure why its doing that - I am guessing something portwise settingwise rather than we are actually deliberately waiting for the port to hangup.

Is it possibly waiting for modem signal lines on close ?

@lostbard
Copy link
Collaborator

i pushed up a change that filters out the ports and makes a reverse order llst when ismac, so hopefully that captures most of your speedups

the longer term fix will be in part working out why some ports stick. I believe I have seen it do it on my linux machine as well - probally when some bluetooth device was plugged in so if I get a chance I will relook at that.

@dasergatskov
Copy link
Author

No, I think the order was specific to my board (it was also the last one on linux) not to the OS. I also do not like to rely on things like ismac(). Could you undo this reverse order?

@dasergatskov
Copy link
Author

I believe I have seen it do it on my linux machine as well - probally when some bluetooth device was plugged in so if I get a chance I will relook at that.

Good :) That means the blacklist patch should help linux as well. Perhaps we should keep an eye on some weird ports that may pop up and expand the list accordingly.

@lostbard
Copy link
Collaborator

yeah its too bad the naming on linux doesnt reflect what it is like it seems to on mac

@dasergatskov
Copy link
Author

I rechecked the latest git. You still have sed rather than `$(SED) in Makefile:

gmake[1]: Entering directory '/Users/dmitri/src/octave-arduino/release/arduino-0.12.1'
cd doc && ./mkfuncdocs.py --src-dir=../inst/ --src-dir=../inst/sensors/ ../INDEX | sed 's/@seealso/@xseealso/g' > functions.texi
Generating doc/version.texi
cd doc && SOURCE_DATE_EPOCH= texi2pdf -q arduino.texi
/opt/homebrew/bin/texi2dvi: Your TeX installation appears to be broken - texi2dvi
cannot determine auxiliary files output from a TeX run.

Also my TeX installation should be fine:

% pdftex -v
pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025)
kpathsea version 6.4.1
% texi2dvi -v
texi2dvi (GNU Texinfo 7.2)
 % texi2pdf -q ./release/arduino-0.12.1/doc/arduino.texi

works and produces a nice-looking pdf.

@lostbard
Copy link
Collaborator

No, I think the order was specific to my board (it was also the last one on linux) not to the OS. I also do not like to rely on things like ismac(). Could you undo this reverse order?

the reverse order is putting the order to the way you had it (but by building the list in reverse order rather than iterating in reverse order) - just is only doing it for mac - since on my linux machine it was making it longer in time
So you are saying dont reverse order for mac ?

@lostbard
Copy link
Collaborator

lostbard commented Mar 28, 2025

I rechecked the latest git. You still have sed rather than `$(SED) in Makefile:

gmake[1]: Entering directory '/Users/dmitri/src/octave-arduino/release/arduino-0.12.1'
cd doc && ./mkfuncdocs.py --src-dir=../inst/ --src-dir=../inst/sensors/ ../INDEX | sed 's/@seealso/@xseealso/g' > functions.texi
Generating doc/version.texi
cd doc && SOURCE_DATE_EPOCH= texi2pdf -q arduino.texi
/opt/homebrew/bin/texi2dvi: Your TeX installation appears to be broken - texi2dvi
cannot determine auxiliary files output from a TeX run.

In the makefile it is:

cd doc && ./mkfuncdocs.py --src-dir=../inst/ --src-dir=../inst/sensors/ ../INDEX | $(SED) 's/@seealso/@xseealso/g' > functions.texi

@dasergatskov
Copy link
Author

dasergatskov commented Mar 28, 2025

So you are saying dont reverse order for mac ?

Yes. There is nothing Mac-specific about it. It Worked for me on both Mac and Linux because my board name was usbserial-1420 on mac and [33,1] = /dev/ttyUSB0 on linux.

@lostbard
Copy link
Collaborator

so with the reverse order it works faster for you both on mac and linux, but does not on my machine where the arduino devices seem to enumerate starting a /dev/ttypACM0 - i trued a couple of clones as well as offical arduinos in they did the same (fedora)

@dasergatskov
Copy link
Author

Exactly. So it just depends on the board, not computer / OS

@lostbard
Copy link
Collaborator

lostbard commented Mar 28, 2025

which linux and whch board do you have ?

An alternative way of detecting boards may be using the usb info rather than serial port, which may be a better option to detect connected arduis rather than scanning all teh serial ports

@dasergatskov
Copy link
Author

Fedora. The board is a SparkFun RedBoard (UNO clone). There is no much info from linux misc. usb facilities.
"Vendor Id." = 1a86; "Product Id." = 7523

@dasergatskov
Copy link
Author

dasergatskov commented Mar 28, 2025

Some photos (CPU and USB-Serial converter):

Image

Image

@lostbard
Copy link
Collaborator

yeah i have one of those floating around here somewhere will see if I can dig it up

@lostbard
Copy link
Collaborator

lostbard commented Mar 29, 2025

found it - mine I think was the older rev when was still using the ftdi chip, but it does at least come up ttyUSB0

I guess solution for linux at least is prioritise the ports - It will be far more like that a non /dev/ttySXX one will be the port (Unless they do actually have it looked up via a real serial port) so they should be checked first

@lostbard
Copy link
Collaborator

Perhaps related to mac, I see on arduino-ide images on mac, it appears to be using the /dev/cu.xxxx ports rather than the tty ones, and I sawa reference about the cu versions dont wait for the control signals to assert on open, so perhaps a hint for the serializ ports ?

@dasergatskov
Copy link
Author

dasergatskov commented Mar 31, 2025

Perhaps related to mac, I see on arduino-ide images on mac, it appears to be using the /dev/cu.xxxx ports rather than the tty ones,

I wonder if this is a kernel issue (old vs new Macs). On mine (MacOS 15.3.2) serialportlist shows only tty.

@lostbard
Copy link
Collaborator

lostbard commented Apr 1, 2025

Perhaps related to mac, I see on arduino-ide images on mac, it appears to be using the /dev/cu.xxxx ports rather than the tty ones,

I wonder if this is a kernel issue (old vs new Macs). On mine (MacOS 15.3.2) serialportlist shows only tty.

Yeah serialportlist basically just gets a list or /dev/tty.*, nothing else, rather than listing both - a few examples of mac matlab code only show them BUT could have just been the examples I have seen.

For the ide, comment, I just noticed on some of screenshots of the arduino running on mac and showing the serialport list, that they were only /dev/cu.xxx - perhaps also just limited examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants