Serial port opening more successful in IDE's serial monitor than in Max

Status
Not open for further replies.

amundsen

Well-known member
Hello,

I have a setup with a Teensy 3.2 and a Pozyx UWB shield connected over a Sparkfun Arduino shield adaptor. The Teensy is connected to a computer running Cycling'74's Max 7 over a USB cable. The setup is sensitive because the Pozyx stuff is made for regular Arduino boards and no compatibility with Teensy is provided. However, with a few tweaks, I have the expected data.

Still I have some issues to start the program on the Teensy. If I open the serial port directly in Max (using the serial object) I do not always have the data flowing into the computer. However, if I first open the port using the Arduino/Teensy IDE's serial monitor I get the expected data flowing into the computer most of the time. Then, if I close the serial monitor and opens the serial connection in Max, I still have them.

So, the questions are:
1. How is the serial monitor configured and why does it success more often than Max?
2. Is the serial monitor specifically adapted to the Teensy boards, especially when using USB?

Thank you in advance for helping.
 
2. Is the serial monitor specifically adapted to the Teensy boards, especially when using USB?

It depends on what you've selected in the Tools > Ports menu.

The Tools > USB Type menu also comes into play if you select a non-Serial type like MIDI. In those cases, HID protocol is used to emulate serial and no serial device is used at all. Sounds like you're not using those. (but really, I can't even tell if you're using Mac, Windows or Linux...)

If you select something under "Serial ports" in the Ports menu, then Arduino uses the Java JSSC library to open the serial device.

If you select something under "Teensy" in the Ports menu, then "teensy_serialmon" is run and Java talks to it using stdin/stdout (anonymous pipes on Windows). How teensy_serialmon works is slightly different on each platform, but essentially it just opens the port using the native platform APIs (eg, WIN32 CreateFile on Windows) and native platform functions to sending & receiving data. The "teensy_serialmon" programs also watch for USB disconnect and quickly close the port, which helps tremendously if you're running a pre-10 version of Windows (remember, I'm totally in the dark on what software you're really using while writing this message) due to bugs in Microsoft's USBSER.SYS (fixed in Windows 10) and on Linux where the kernel will assign a different name if the device reappears and the old one is still in use (not a bug, but a feature with the Arduino serial monitor doesn't handle well with JSSC keeping the port open).

I know this doesn't answer all your questions, but hopefully it helps.

Many details depend on which OS and version you have, and what settings you use in the Tools menu, and on some systems whether non-Arduino software is still using the port while Teensy reboots. Might be able to help more with a clearer picture of which software you use and what you're really doing with it during the moments when Teensy reboots.
 
Hello Paul,

Thank you for helping.

It depends on what you've selected in the Tools > Ports menu.

I am using the Teensy port (the one without (serial) postfix).

The Tools > USB Type menu also comes into play if you select a non-Serial type like MIDI. In those cases, HID protocol is used to emulate serial and no serial device is used at all. Sounds like you're not using those. (but really, I can't even tell if you're using Mac, Windows or Linux...)

I am on Windows 10/Arduino 1.8.5/Teensyduino 1.42

If you select something under "Teensy" in the Ports menu, then "teensy_serialmon" is run and Java talks to it using stdin/stdout (anonymous pipes on Windows). How teensy_serialmon works is slightly different on each platform, but essentially it just opens the port using the native platform APIs (eg, WIN32 CreateFile on Windows) and native platform functions to sending & receiving data. The "teensy_serialmon" programs also watch for USB disconnect and quickly close the port, which helps tremendously if you're running a pre-10 version of Windows (remember, I'm totally in the dark on what software you're really using while writing this message) due to bugs in Microsoft's USBSER.SYS (fixed in Windows 10) and on Linux where the kernel will assign a different name if the device reappears and the old one is still in use (not a bug, but a feature with the Arduino serial monitor doesn't handle well with JSSC keeping the port open).

I know this doesn't answer all your questions, but hopefully it helps.

Many details depend on which OS and version you have, and what settings you use in the Tools menu, and on some systems whether non-Arduino software is still using the port while Teensy reboots. Might be able to help more with a clearer picture of which software you use and what you're really doing with it during the moments when Teensy reboots.

Actually I try to always close the port before rebooting the Teensy because anyway if the port is still open in Max it won't open in the Arduino IDE.

I guess one should adapt the teensy_serialmon code and transform it into a serial communication object for Max. The regular Max serial object is quite old, not reputated to be really efficient and the code is not open, so I have no idea of what it is based on. However there's an object dedicated to HID control in Max. Do you think it could help if I'd use this instead of serial?
 
Status
Not open for further replies.
Back
Top