-
Notifications
You must be signed in to change notification settings - Fork 174
Home
Welcome to the serial-port-json-server wiki!
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"}
As another example, if you send multiple commands in one statement with an ID, SPJS will translate your command as follows:
sendjson {"P":"COM22","Data":[{"D": "G0 X1\nG0 X0\n", "Id":"123"}]}
You will get back a queued response. Notice the command is split into two and the second ID is modified to reflect this was a 2 part command. The first ID is not changed so if you are pivoting off of it in your UI you will still get back a correct ID.
{"Cmd":"Queued","QCnt":2,"P":"COM22","Data":[{"D":"G0 X1\n","Id":"123","Buf":"Buf"},{"D":"G0 X0\n","Id":"123-part-2-2","Buf":"Buf"}]}
When the commands are written to the serial device you get:
{"Cmd":"Write","QCnt":1,"Id":"123","Buf":"Buf","P":"COM22"}
{"Cmd":"Write","QCnt":0,"Id":"123-part-2-2","Buf":"Buf","P":"COM22"}
When the commands are completed, meaning we got an acknowledgement by the serial device you get:
{"Cmd":"Complete","Id":"123","P":"COM22","BufSize":6}
{"Cmd":"Complete","Id":"123-part-2-2","P":"COM22","BufSize":0}