ports/asciiport.js
function _asciiEncodeRequestBuffer(buf) {

    // replace the 2 byte crc16 with a single byte lrc
    buf.writeUInt8(calculateLrc(buf.slice(0, -2)), buf.length - 2);

    // create a new buffer of the correct size
    var bufAscii = Buffer.alloc(buf.length * 2 + 1); // 1 byte start delimit + x2 data as ascii encoded + 2 lrc + 2 end delimit

    // create the ascii payload

    // start with the single start delimiter
    bufAscii.write(":", 0);
    // encode the data, with the new single byte lrc
    bufAscii.write(buf.toString("hex", 0, buf.length - 1).toUpperCase(), 1);
    // end with the two end delimiters
    bufAscii.write("\r", bufAscii.length - 2);
    bufAscii.write("\n", bufAscii.length - 1);

    return bufAscii;
}
function _asciiEncodeRequestBuffer(buf) {

    // replace the 2 byte crc16 with a single byte lrc
    buf.writeUInt8(calculateLrc(buf.slice(0, -2)), buf.length - 2);

    // create a new buffer of the correct size
    var bufAscii = Buffer.alloc(buf.length * 2 + 1); // 1 byte start delimit + x2 data as ascii encoded + 2 lrc + 2 end delimit

    // create the ascii payload

    // start with the single start delimiter
    bufAscii.write(":", 0);
    // encode the data, with the new single byte lrc
    bufAscii.write(buf.toString("hex", 0, buf.length - 1).toUpperCase(), 1);
    // end with the two end delimiters
    bufAscii.write("\r", bufAscii.length - 2);
    bufAscii.write("\n", bufAscii.length - 1);

    return bufAscii;
}
function _asciiEncodeRequestBuffer ( buf ) { // replace the 2 byte crc16 with a single byte lrc buf . writeUInt8 ( calculateLrc ( buf . slice ( 0 , - 2 ) ) , buf . length - 2 ) ; // create a new buffer of the correct size var bufAscii = Buffer . alloc ( buf . length * 2 + 1 ) ; // 1 byte start delimit + x2 data as ascii encoded + 2 lrc + 2 end delimit // create the ascii payload // start with the single start delimiter bufAscii . write ( ":" , 0 ) ; // encode the data, with the new single byte lrc bufAscii . write ( buf . toString ( "hex" , 0 , buf . length - 1 ) . toUpperCase ( ) , 1 ) ; // end with the two end delimiters bufAscii . write ( "\r" , bufAscii . length - 2 ) ; bufAscii . write ( "\n" , bufAscii . length - 1 ) ; return bufAscii ; }
Ascii encode a 'request' buffer and return it. This includes removing
the CRC bytes and replacing them with an LRC.

@param {Buffer} buf the data buffer to encode.
@return {Buffer} the ascii encoded buffer
@private
Ascii encode a request buffer and return it . This includes removing the CRC bytes and replacing them with an LRC .