Tuesday 24 September 2019

Command queing for ASCII based protocol over TCP socket

Hi,I'm trying to write some configuration software for a device. The device is configured via a serial interface with an ascii based protocol. Command messages are simple strings ending in a carraige return. When a valid command message is received, the device responds with "OK".To interface with the device I've got an RS232 to IP converter, which my node.js app connects to with a TCP socket.I've been able to succesfully send commands with socket.write(command), and parsing the output of the device to get a variable "deviceoutput" with value "OK" works ok as well.The issue I'm having is that I want to send multiple commands to my node.js app, queue them, send the first one but wait to send the next until the "OK" message from the device has been returned.Creating the queue seems simple enough by doing:function Queue() {this.data = [];}Queue.prototype.add = function(record) {this.data.unshift(record);};Queue.prototype.remove = function() {this.data.pop();};Queue.prototype.first = function() {return this.data[0];};Queue.prototype.last = function() {return this.data[this.data.length - 1];};Queue.prototype.size = function() {return this.data.length;};const commandQueue = new Queue();​Has anybody tried something similar in the past?

Submitted September 25, 2019 at 12:54AM by D0tfile

No comments:

Post a Comment