ports/c701port.js
/**
 * Check if a buffer chunk can be a Modbus answer or modbus exception.
 *
 * @param {UdpPort} modbus
 * @param {Buffer} buf the buffer to check.
 * @return {boolean} if the buffer can be an answer
 * @private
 */
Check if a buffer chunk can be a Modbus answer or modbus exception.
@param {UdpPort} modbus
@param {Buffer} buf the buffer to check.
@return {boolean} if the buffer can be an answer
@private
Check if a buffer chunk can be a Modbus answer or modbus exception . @param { UdpPort } modbus @param { Buffer } buf the buffer to check . @return { boolean } if the buffer can be an answer @private
function _checkData(modbus, buf) {
    if (buf.length !== modbus._length && buf.length !== 5) return false;
    var crcIn = buf.readUInt16LE(buf.length - 2);
    return (buf[0] === modbus._id &&
        (0x7f & buf[1]) === modbus._cmd &&
        crcIn === crc16(buf.slice(0, -2)));
}
function _checkData ( modbus , buf ) { if ( buf . length !== modbus . _length && buf . length !== 5 ) return false ; var crcIn = buf . readUInt16LE ( buf . length - 2 ) ; return ( buf [ 0 ] === modbus . _id && ( 0x7f & buf [ 1 ] ) === modbus . _cmd && crcIn === crc16 ( buf . slice ( 0 , - 2 ) ) ) ; }
Check if a buffer chunk can be a Modbus answer or modbus exception.
Check if a buffer chunk can be a Modbus answer or modbus exception .
// check buffer size // calculate crc16 // check buffer unit-id, command and crc