Getting [serial] to receive and send through JavaScript

tobiasger's icon

I'm trying to setup [serial] for receiving data from a microcontroller and also sending data to the microcontroller. Since I feel quite confident in JavaScript in general, I figured it would be nice for my workflow to do the main portion of logic and manipulation through that while the Max For Live objects would just be as barebones as possible and bring the necessary data to the JavaScript file.

When it comes to the input, as I understand it, I would first need to setup the serial object with the port and baud rate. I also realized that I need to send an 'open' message as well as bang the serial object in intervals using the metro object, in order to get the output. I can then connect the serial object to the js object and use msg_int() in the JavaScript file in order to parse/interpret the serial data. Please let me know if there is anything I've missed or if it can be done even simpler or smarter.

In order to output data from the JavaScript file to serial, I get a bit stuck. There seems to be a function called outlet() that can send data from the JavaScript file to it's output(?). So far it seems to work, but I'm having a hard time understanding how the output would be prepared properly before it gets sent as a serial message.

I've managed to understand some bits and pieces by using ChatGPT. I feel that the documentation is a bit hard to navigate and get a grip off, especially when it comes to how to utilize the API through JavaScript. I don't know if I'm bad at finding the correct resources, but that's the general feeling. So there is a lot of guessing and ChatGPTing so far.

Would be appreciated if anyone could share any knowledge or resources around how to send and receive serial data properly, preferably including how to handle the input and output in JavaScript.