I have some doubts using recv after looking at the console widget:
How do I identify the port every time data is sent. Because the subscription will read from all the ports and I have to filter it, right?
How does the subscription work? I tried recvline with a copy of onRecvline and it worked well but I can’t see anything like this for recv? There is consoleSubscribeToLowLevelSerial() but it uses to parameters, this and a function that processes the data.
I can’t use recvline because I need to process data frames that are sent over the serial connection encapsulated with the SLIP protocol.
You should use /ws/recv A signal published when the websocket receives data from the serial port server. The serial port, i.e. COM21, the websocket identifier, and data are sent.
That’s all in the documents for Pubsub under the Serial Port JSON Server widget. In contrast, here’s the description for recvline.
/recvline We publish this signal in tandem with /ws/recv but we only publish this signal per newline. That way your widget can consume per line data which is typically the way you want it. We recommend you subscribe to this channel instead of /ws/recv to have less work to do of looking for newlines. When in setSingleSelectMode() we will only send you data for the port that is selected (in green in UI). You will not get this signal for secondary ports that are open. For secondary ports, you need to subscribe to /ws/recv and do lower level parsing.
I don’t recall what other widget uses /ws/recv. Most widgets use /recvline because it’s way easier to use since events come in line by line. Since you need character by character, you need /ws/recv.
Thank for your answer! Sorry if I didn’t express myself well. I already had understood that I need to use /ws/recv.
I just wasn’t sure about filtering the data by port and if I have to subscribe to the signal the same way as I would do it with recvline (subscribing and writing a “onRecv” method).
You definitely have to subscribe and thus create an onRecv function. You will have to filter on the serial port name because /ws/recv sends you data for all open serial ports.