Arduino IDE2 - Serial Monitor sometimes does not work - continue from Upload Thread

Windows only ... See Tset. It makes a batch file that runs from Dos box or explorer or notepadd++ - anything that can run the batch file.
It is due for an update - to note the IDE 2 changes - local.txt option and it includes Arduino15 directories making it use IDE 2 install and removing those can have it use old install process instead.
Though others have worked out a linux script that can do the same. Though not ever seen it published.
>> Will update Use-Sublime-Text-as-an-Arduino-IDE-replacement when TSET is updated and can discuss there.

Thanks, I assumed it was Windows only:)
 
Ok, here is my first attempt a workaround for delayed or missing WM_DEVICECHANGE messages. It uses polling at 20 Hz when a change seems likely, then backs off to slow 1.2 seconds polling after 15 seconds of rapid polling to reduce CPU usage long-term. I tried to make it as efficient as reasonably possible, so hopefully it doesn't burn too much CPU even in those 15 seconds? WM_DEVICECHANGE is still used, for fastest possible response when Windows is delivering those messages.

As usual, this goes into C:/Users/me/AppData/Local/Arduino15/packages/teensy/tools/teensy-monitor/1.57.0/, replacing the copy of teensy-monitor.exe in that folder.

Arduino just released IDE 2.0.3. This works with 2.0.3 and should work with all 2.0.x versions.

Please let me know if this fully solves the problems? (and if I'm saved from having to run Windows 11) So far, I've tested only on a single Windows 10 machine, with Arduino 2.0.2 and 2.0.3.
 

Attachments

  • teensy-monitor-with-timer-polling.zip
    26.3 KB · Views: 29
Downloaded,

So far I have not run into the issue again. But it was not always getting consistent repeats before.

Keeping fingers crossed. Running on Windows 11 and hopefully will save me from having to run Ubuntu 22.04 ;)
 
Morning all

Downloaded and installed both IDE 2.0.3 and the new teensy-monitor. Reran in accordance with this:
Code:
I'm running Defragster's sketch from msg #7.

To reproduce the problem, after uploading and opening the serial monitor (with Teensy Port selected), I quit and restart the IDE. When the IDE restarts, it automatically opens the serial monitor. If the sketch is already running with the LED blinking, nothing is supposed to appear. The sketch only prints stuff when the sketch starts running.

Then with the serial monitor open, I press the pushbutton on Teensy. Teensy Loader uploads the code again.

On the first pushbutton-triggered upload after starting the IDE, when Teensy starts running the sketch again, the serial monitor fails to connect to the freshly reprogrammed Teensy. Its LED stays on solid, indicating it's waiting for the serial monitor to open.

But if I first kill the serial-discovery.exe process, then press the pushbutton, after upload and Teensy begins running Defragster's sketch, the serial monitor does connect. The 2 lines appear (0.33 and 1.33 seconds on my test machine) and the LED blinks, indicating the sketch saw the serial monitor open.

and it worked no hangs and output displayed:
Code:
D:\Users\Merli\Documents\Arduino\sketch_dec4a\sketch_dec4a.ino Dec  5 2022 09:45:43
run secs A=0.43

D:\Users\Merli\Documents\Arduino\sketch_dec4a\sketch_dec4a.ino Dec  5 2022 09:45:43
run secs B=1.43
See Me: 1
See Me: 2
See Me: 3

So at least for the test case its working. Will be playing more today with other stuff so will let you know if anything pops up.

NOTE: Running on a windows10x64 that had alot of junk on it - definitely not a fresh install.
 
Paul,

I did run into an issue here, not sure if related.

I was trying out some changes to USBHost on a few different examples. It was working fine on T4.1 with Teensy Serial Com 7. I opened up another one, and built again, pretty sure I had turned off Serial monitor in other window.... Built and no output. I then changed to the Arduino Com7 and built again and output showed up. I went back to Teensy port... Empty. Then rebuilt still empty. Unplugged Teensy, plugged it back in and Serial output worked.
 
Downloaded and copied into place and started and updated to IDE 2.0.3

Now I need to restart to get that offending Win EXE restarted like last time.

... now just pending reboot to test ...
 
Paul,

I did run into an issue here, not sure if related.

I was trying out some changes to USBHost on a few different examples. It was working fine on T4.1 with Teensy Serial Com 7. I opened up another one, and built again, pretty sure I had turned off Serial monitor in other window.... Built and no output. I then changed to the Arduino Com7 and built again and output showed up. I went back to Teensy port... Empty. Then rebuilt still empty. Unplugged Teensy, plugged it back in and Serial output worked.

was trying to duplicate with one IDE Window with a BLE Sketch and a second IDE window running the post 7 test sketch. Both cases they were on Teensy Port Com 10. With Serial Monitor open on both the output shows up in both windows:

Capture.PNG

I have noticed that unless I put in a delay of about 2500 ms the Seral Monitor doesn't capture the output of the test sketch unless the serial monitor is already open in the IDE:
Code:
delay 1500:
run secs B=5.70
See Me: 1
See Me: 2
See Me: 3

delay 2500:
D:\Users\Me\Documents\Arduino\sketch_dec4a\sketch_dec4a.ino Dec  5 2022 13:50:23
run secs A=5.68

D:\Users\Me\Documents\Arduino\sketch_dec4a\sketch_dec4a.ino Dec  5 2022 13:50:23
run secs B=6.68
See Me: 1
See Me: 2
See Me: 3
 
Luckily tried running before restart with Ctrl+U: Windows wouldn't allow it to execute as unsafe - it didn't say that with the 11/15 update? Didn't work right - - would have had to restart IDE?

Using POLLED TeensySerMon: Rebooted and slowest reconnect is 1.03 seconds, using Button or Ctrl+U, most about 0.95 seconds reported

Changed to IDE_SM and allowed EXE restored to the prior fix 11/25 version: 18 second - or NO CONNECT - behavior returned

Changed to IDE_SM and allowed EXE restored to POLLING_TeensySerialMonitor: Ctrl+U and Button showed sketch start at 0.90 seconds.

> IDE_SerMon gives about the same ~1 second timing.

Button Push does result in ALL CORES(real and HT) 100% SPIKE:
PollSpikes.png
 
...
I have noticed that unless I put in a delay of about 2500 ms the Seral Monitor doesn't capture the output of the test sketch unless the serial monitor is already open in the IDE:
Code:
delay 1500:
run secs B=5.70
See Me: 1
See Me: 2
See Me: 3

delay 2500:
D:\Users\Me\Documents\Arduino\sketch_dec4a\sketch_dec4a.ino Dec  5 2022 13:50:23
run secs A=5.68

D:\Users\Me\Documents\Arduino\sketch_dec4a\sketch_dec4a.ino Dec  5 2022 13:50:23
run secs B=6.68
See Me: 1
See Me: 2
See Me: 3

I have seen where the first "A=" section is missed (as above) - both with IDE and Teensy Sermon in some instances.

It is intermittent and not reliably reproducible. Just tried it here starting with Teensy SerMon closed and open after upload and: No Issue - all output captured and displayed.

For some reason IDE showed sketch output, then posted that 'teensy not available' and showed disconnected a second - then reconnected before the message could be captured. Will Not Repro.

Also: even with Serial Monitor active and in AutoScroll IDE 2.0.3 is no longer fully autoscrolling? A Button upload advances to "A=" section, but does not scroll to the end after "B=" section? Same happens when USB 'Message' characters sent that Teensy echoes back.
> Though there seems to be an IDE 2.0.3 change that the Serial Monitor windows is no longer BLANK when switched to, but it is showing and active on the top portion with No Autoscroll?

There is something in the IDE GUI system it seems where the buffered lines are segmented? Take the mouse and select all and COPY and paste into Notepad - often only a portion of the selection is shown in the Paste.
Change line 14 in setup() to: showSome( 19 );
Run (upload) it twice, select all output with Mouse Click Drag and paste and more than half is missing:
Code:
See Me: 5
See Me: 6
See Me: 7
See Me: 8
See Me: 9
See Me: 10
See Me: 11
See Me: 12
See Me: 13
See Me: 14
See Me: 15
See Me: 16
See Me: 17
See Me: 18
See Me: 19
 
.......

Button Push does result in ALL CORES(real and HT) 100% SPIKE:
View attachment 29878

So when you push the reset button on the Teensy you see all cores spiking to 100%? If so I tried that with the test sketch Win10x64, IDE2.0.3, 0.58.2 and didn;t see that,
Capture.PNG

the last spike is when I hit the button and the sketch ran - cores 4-9 were almost 0 usage.
 
So when you push the reset button on the Teensy you see all cores spiking to 100%? If so I tried that with the test sketch Win10x64, IDE2.0.3, 0.58.2 and didn;t see that,
...
the last spike is when I hit the button and the sketch ran - cores 4-9 were almost 0 usage.

Yes, Windows 11 with 10th Gen i7. Pressed 'Bootloader' Button to upload last HEX file. After Upload completed before Teensy restarted was LOW %, then as it started that spike hit all 8 cores and their imaginary HyperThread part most at near 100% for some 1-2 seconds across USB Chime OUT>IN, then dropped. Repro 6 of 6 times. Same with Ctrl+U where few cores working during the build.
 
Yes when a build completes and upload... There is a pretty good spike:
Screenshot.jpg

Looks like almost all 20 CPUs
 
@KurtE - @defragster

Redid it using the test sketch and ignored looking at all the cores.

On a Win10 machine:
Initial Upload: 68% utilization.
Button Push: 65-70%
Capture.PNG
 
Also: even with Serial Monitor active and in AutoScroll IDE 2.0.3 is no longer fully autoscrolling?

Yes, I saw that too. Pretty sure it's Arduino IDE, not anything about Teensy. Looks like auto-scroll which wasn't perfect in 2.0.2 got even worse in 2.0.3.
 
teensy-serialmon.exe has 4 threads, so in a worst case scenario it could tie up only 4 CPU cores. Whatever is hitting all 20 cores is probably from Arduino.
 
teensy-serialmon.exe has 4 threads, so in a worst case scenario it could tie up only 4 CPU cores. Whatever is hitting all 20 cores is probably from Arduino.

That seems to be CORRECT! When IDE SerMon is selected on Port the same Spike happens across all 'logical processors' as shown.

As for 'Autoscroll' - got feedback question on the update to IDE#1724 that was also 'title changed' - tested and replied there with clear fail of autoscroll - but most times text always shows - at least once IDE SerMon looked blank - but not always like before.
 
On the CPU usage from teensy-serialmon.exe polling, if you just unplug the USB cable while the serial monitor is open and working, it will go into rapid polling mode for 15 seconds. The polling is done by 1 of the 4 threads, so all the polling overhead should appear on 1 core. The other 3 threads are 1: communication with Arduino for managing the session, 2: data from Teensy to Arduino Serial Monitor, and 3: data from Arduino Serial Monitor to Teensy.
 
Indeed, all Logical Procs show spikes on either IDE plug and unplug.
Also Spikes about +60% with Serial Monitor closed.

And going to 'Processes' view sorted by CPU% - no SerMon puts IDE just under 10% and with T_SerMon it hits maybe 12%, and 20% with IDE_SerMon - so the rest is the OS.
 
I was trying out some changes to USBHost on a few different examples. It was working fine on T4.1 with Teensy Serial Com 7. I opened up another one, and built again, pretty sure I had turned off Serial monitor in other window.... Built and no output. I then changed to the Arduino Com7 and built again and output showed up. I went back to Teensy port... Empty. Then rebuilt still empty. Unplugged Teensy, plugged it back in and Serial output worked.

Might still be more issues to fix. Difficult to say without a way to reproduce the problem.

I'm going to put the timer code into teensy-discovery.exe too, but only slow polling, so it also doesn't fully depend on Windows WM_DEVICECHANGE messages.

Planning to package up 1.58-beta3 soon with that and all the recent fixes. Yesterday worked on bringing the new toolchain into the MacOS version, and now I'm trying to restore support for the 3 other Linux platforms (building the toolchain from source takes many hours, especially on Raspberry Pi).

Hopefully once we're all sync'd up to beta3 a way can be found to reproduce whatever problems remain.
 
Testing teensy-discovery.exe now, and yup, it too is suffering from Windows not delivering WM_DEVICECHANGE, or sending them far too late at times. Still the only case I can reliably reproduce is just having started the IDE, but I'm pretty sure others exist.

Going to set teensy-discovery.exe timer for 0.667 seconds for 1.58-beta3. On my old laptop that's slow enough that Windows 10 Task Manager shows it as 0% CPU usage. Interesting to see Arduino's serial-discovery.exe is running between 0.2% to 0.5% CPU, and using 8X the memory.
 
I'm pretty sure 1.58-beta3 (0.58.3 in Arduino IDE 2.0.x) fully solved the problems reported on this thread.

If anyone is still seeing these problems with 1.58-beta3, please let me know? Otherwise I'm going to consider this fully resolved.
 
Back
Top