ports/c701port.js
function(ip, options) {
    var modbus = this;
    this.ip = ip;
    this.openFlag = false;

    // options
    if (typeof(options) === "undefined") options = {};
    this.port = options.port || C701_PORT; // C701 port

    // create a socket
    this._client = dgram.createSocket("udp4");

    // wait for answer
    this._client.on("message", function(data) {
        var buffer = null;

        // check expected length
        if (modbus.length < 6) return;

        // check message length
        if (data.length < (116 + 5)) return;

        // check the C701 packet magic
        if (data.readUInt16LE(2) !== 602) return;

        // check for modbus valid answer
        // get the serial data from the C701 packet
        buffer = data.slice(data.length - modbus._length);

        modbusSerialDebug({ action: "receive c701 upd port", data: data, buffer: buffer });
        modbusSerialDebug(JSON.stringify({ action: "receive c701 upd port strings", data: data, buffer: buffer }));

        // check the serial data
        if (_checkData(modbus, buffer)) {
            modbusSerialDebug({ action: "emit data serial rtu buffered port", buffer: buffer });
            modbusSerialDebug(JSON.stringify({ action: "emit data serial rtu buffered port strings", buffer: buffer }));

            modbus.emit("data", buffer);
        } else {
            // check for modbus exception
            // get the serial data from the C701 packet
            buffer = data.slice(data.length - 5);

            // check the serial data
            if (_checkData(modbus, buffer)) {
                modbusSerialDebug({ action: "emit data serial rtu buffered port", buffer: buffer });
                modbusSerialDebug(JSON.stringify({
                    action: "emit data serial rtu buffered port strings",
                    buffer: buffer
                }));

                modbus.emit("data", buffer);
            }
        }
    });

    this._client.on("listening", function() {
        modbus.openFlag = true;
    });

    this._client.on("close", function() {
        modbus.openFlag = false;
    });

    /**
     * Check if port is open.
     *
     * @returns {boolean}
     */
    Object.defineProperty(this, "isOpen", {
        enumerable: true,
        get: function() {
            return this.openFlag;
        }
    });

    EventEmitter.call(this);
}
function(ip, options) {
    var modbus = this;
    this.ip = ip;
    this.openFlag = false;

    // options
    if (typeof(options) === "undefined") options = {};
    this.port = options.port || C701_PORT; // C701 port

    // create a socket
    this._client = dgram.createSocket("udp4");

    // wait for answer
    this._client.on("message", function(data) {
        var buffer = null;

        // check expected length
        if (modbus.length < 6) return;

        // check message length
        if (data.length < (116 + 5)) return;

        // check the C701 packet magic
        if (data.readUInt16LE(2) !== 602) return;

        // check for modbus valid answer
        // get the serial data from the C701 packet
        buffer = data.slice(data.length - modbus._length);

        modbusSerialDebug({ action: "receive c701 upd port", data: data, buffer: buffer });
        modbusSerialDebug(JSON.stringify({ action: "receive c701 upd port strings", data: data, buffer: buffer }));

        // check the serial data
        if (_checkData(modbus, buffer)) {
            modbusSerialDebug({ action: "emit data serial rtu buffered port", buffer: buffer });
            modbusSerialDebug(JSON.stringify({ action: "emit data serial rtu buffered port strings", buffer: buffer }));

            modbus.emit("data", buffer);
        } else {
            // check for modbus exception
            // get the serial data from the C701 packet
            buffer = data.slice(data.length - 5);

            // check the serial data
            if (_checkData(modbus, buffer)) {
                modbusSerialDebug({ action: "emit data serial rtu buffered port", buffer: buffer });
                modbusSerialDebug(JSON.stringify({
                    action: "emit data serial rtu buffered port strings",
                    buffer: buffer
                }));

                modbus.emit("data", buffer);
            }
        }
    });

    this._client.on("listening", function() {
        modbus.openFlag = true;
    });

    this._client.on("close", function() {
        modbus.openFlag = false;
    });

    /**
     * Check if port is open.
     *
     * @returns {boolean}
     */
    Object.defineProperty(this, "isOpen", {
        enumerable: true,
        get: function() {
            return this.openFlag;
        }
    });

    EventEmitter.call(this);
}
function ( ip , options ) { var modbus = this ; this . ip = ip ; this . openFlag = false ; // options if ( typeof ( options ) === "undefined" ) options = { } ; this . port = options . port || C701_PORT ; // C701 port // create a socket this . _client = dgram . createSocket ( "udp4" ) ; // wait for answer this . _client . on ( "message" , function ( data ) { var buffer = null ; // check expected length if ( modbus . length < 6 ) return ; // check message length if ( data . length < ( 116 + 5 ) ) return ; // check the C701 packet magic if ( data . readUInt16LE ( 2 ) !== 602 ) return ; // check for modbus valid answer // get the serial data from the C701 packet buffer = data . slice ( data . length - modbus . _length ) ; modbusSerialDebug ( { action : "receive c701 upd port" , data : data , buffer : buffer } ) ; modbusSerialDebug ( JSON . stringify ( { action : "receive c701 upd port strings" , data : data , buffer : buffer } ) ) ; // check the serial data if ( _checkData ( modbus , buffer ) ) { modbusSerialDebug ( { action : "emit data serial rtu buffered port" , buffer : buffer } ) ; modbusSerialDebug ( JSON . stringify ( { action : "emit data serial rtu buffered port strings" , buffer : buffer } ) ) ; modbus . emit ( "data" , buffer ) ; } else { // check for modbus exception // get the serial data from the C701 packet buffer = data . slice ( data . length - 5 ) ; // check the serial data if ( _checkData ( modbus , buffer ) ) { modbusSerialDebug ( { action : "emit data serial rtu buffered port" , buffer : buffer } ) ; modbusSerialDebug ( JSON . stringify ( { action : "emit data serial rtu buffered port strings" , buffer : buffer } ) ) ; modbus . emit ( "data" , buffer ) ; } } } ) ; this . _client . on ( "listening" , function ( ) { modbus . openFlag = true ; } ) ; this . _client . on ( "close" , function ( ) { modbus . openFlag = false ; } ) ; /**
     * Check if port is open.
     *
     * @returns {boolean}
     */ Object . defineProperty ( this , "isOpen" , { enumerable : true , get : function ( ) { return this . openFlag ; } } ) ; EventEmitter . call ( this ) ; }
Simulate a modbus-RTU port using C701 UDP-to-Serial bridge.

@param ip
@param options
@constructor
Simulate a modbus - RTU port using C701 UDP - to - Serial bridge .