If you notice I already do this in SPJS. I made changes to 1.6 to gear up for this larger change. You see a queue and a write json response today. The write is sent after the line is buffered. If the serial port writer() thread is paused, the write only comes back after the that pause goes away.
Here’s the wiki write up.
Proposed changes for upcoming release.
Have SPJS support a “sendjson” command so multiple lines or serial port data can be sent in at once, but each line can have an ID attached to it so SPJS can send that ID back once the serial port device has executed the command, as well as still allowing buffered and non-buffered send commands.
If you send in a command like this today to SPJS:
send COM22 G91 G0 Z1 F200\nG90\n
You get back: {“Cmd”:“Queued”,“QCnt”:2,“Type”:[“Buf”,“Buf”],“D”:[“G91 G0 Z1 F200\n”,“G90\n”],“Port”:“COM22”}
Then when each line is executed you get back: {“Cmd”:“Write”,“QCnt”:1,“D”:“G91 G0 Z1 F200\n”,“Port”:“COM22”} {“Cmd”:“Write”,“QCnt”:0,“D”:“G90\n”,“Port”:“COM22”}
As seen above, SPJS is already keeping track of each line and sending a final response when the line is executed. However, it is hard to line up which line is which in a UI. To solve this an ID will be allowed to be passed in per command. This would mean that commands can’t just be sent in as one long string with a newline delimiter. Instead each line should be sent in as a structured object.
It is proposed to send in the line above as:
sendjson { “P”: “COM22”, “Data”: [ { “D”: “G91 G0 Z1 F200\n”, “Id”: “222” }, { “D:” “G90\n”, “Id”: “223” } ] }
Then when SPJS buffers those lines, it will send back:
{“Cmd”:“Queued”,“QCnt”:2,“Data”: [ { “D”: “G91 G0 Z1 F200\n”, “Id”: “222”, “Buf”: true }, { “D”: “G90\n”, “Id”: “223”, “Buf”: true } ],“P”:“COM22”}
Then when SPJS sees those lines executed from the serial device, it will send back:{“Cmd”: “Write”, “QCnt”:1, “D”: “G91 G0 Z1 F200\n”, “Id”: “222”, “P” :“COM22”} {“Cmd”: “Write”, “QCnt”:0, “D”: “G90\n”, “Id”: “223”, “P”: “COM22”}