Skip to content

Is anyone even monitoring this anymore? #18

Description

@RobertMiller-KR2

Im trying to use this to communicate with a iQ-F plc FX5UC. I cannot seem to get it to return any informaiton from the PLC. It states it connects ok but then all the values returned are BAD 255. I am using the sample code but have commented out all the Tests except Test 2 and set it to only read M0-M15

`import mc from 'mcprotocol';
var conn = new mc;
var doneReading = false;
var doneWriting = false;

var variables = {
TEST2: 'M0,16', // 16 bits Starting at M0 (M0-M15)

};

conn.initiateConnection({port: 1250, host: '192.168.3.250', ascii: false}, connected);

function connected(err) {
if (typeof(err) !== "undefined") {
// We have an error. Maybe the PLC is not reachable.
console.log(err);
process.exit();
}
conn.setTranslationCB(function(tag) {return variables[tag];}); // This sets the "translation" to allow us to work with object names defined in our app not in the module
conn.addItems(['TEST2']);

conn.readAllItems(valuesReady);	

}

function valuesReady(anythingBad, values) {
if (anythingBad) { console.log("SOMETHING WENT WRONG READING VALUES!!!!"); }
console.log(values);
doneReading = true;
if (doneWriting) { process.exit(); }
}

function valuesWritten(anythingBad) {
if (anythingBad) { console.log("SOMETHING WENT WRONG WRITING VALUES!!!!"); }
console.log("Done writing.");
doneWriting = true;
if (doneReading) { process.exit(); }
}`

The responce I get [525821,69071600] Initiate Called - Connecting to PLC with address and parameters:
mcprotocol.js:1234
[525821,69847000] { port: 1250, host: '192.168.3.250', ascii: false }
mcprotocol.js:1234
[525821,70405800] Connection cleanup is happening
mcprotocol.js:1234
[525821,71757800 192.168.3.250] Attempting to connect to host...
mcprotocol.js:1234
[525821,75067000 192.168.3.250] TCP Connection Established to 192.168.3.250 on port 1250
mcprotocol.js:1234
[525821,75850400] Translation OK
mcprotocol.js:1234
[525821,76619900 192.168.3.250] Adding TEST2
mcprotocol.js:1234
[525825,580196400 192.168.3.250] READ TIMEOUT on sequence number 2
mcprotocol.js:1234
SOMETHING WENT WRONG READING VALUES!!!!
MCprotocol.js:26
{TEST2: 'BAD 255'}

Activity

  1. plcpeople commented on Dec 26, 2025

    @plcpeople
    Owner

    Can you please post the configuration of this port in GxWorks? This looks like it should work, although I do not have an FX5U PLC to test with.

  2. RobertMiller-KR2 commented on Dec 28, 2025

    @RobertMiller-KR2
    Author

    I was able to get a bit farther after adjusting some of the settings in the file (im using it in Fuxa) I'm also using a FX5UC. I have enabled 3E frames and set the ports in GXWorks3 (image below) I can now successfully read values at a sub 500ms rate! However when I try to write anything I get an error.
    Image
    Image

    MCProfocol.js file attached

    mcprotocol.js

  3. RobertMiller-KR2 commented on Dec 28, 2025

    @RobertMiller-KR2
    Author

    In order to remove any outside issues, I tested the code directly without Fuxa. You can see I simply edited it just a bit for the test items.

    `var mc = require('mcprotocol');
    var conn = new mc;
    var doneReading = false;
    var doneWriting = false;

    var variables = { TEST1: 'D0,5' , TEST2: 'D0,1' // Read 5 words starting at D0 Write 1 Word At D0

    }; // See setTranslationCB below for more examples

    conn.initiateConnection({port: 1240, host: '192.168.3.250', ascii: false}, connected);

    function connected(err) {
    if (typeof(err) !== "undefined") {
    // We have an error. Maybe the PLC is not reachable.
    console.log(err);
    process.exit();
    }
    conn.setTranslationCB(function(tag) {return variables[tag];}); // This sets the "translation" to allow us to work with object names defined in our app not in the module
    conn.addItems(['TEST1','TEST2']);
    conn.writeItems('TEST2', [ 666 ], valuesWritten); // You can write a single array item too.
    conn.readAllItems(valuesReady);
    }

    function valuesReady(anythingBad, values) {
    if (anythingBad) { console.log("SOMETHING WENT WRONG READING VALUES!!!!"); }
    console.log(values);
    doneReading = true;
    if (doneWriting) { process.exit(); }
    }

    function valuesWritten(anythingBad) {
    if (anythingBad) { console.log("SOMETHING WENT WRONG WRITING VALUES!!!!"); }
    console.log("Done writing.");
    doneWriting = true;
    if (doneReading) { process.exit(); }
    }`

    I edited the mcprotocol.js with the following changes
    self.isAscii = 0;
    self.frame = '3E';

    The image is the response...

    Image
  4. RobertMiller-KR2 commented on Dec 29, 2025

    @RobertMiller-KR2
    Author

    One more bit of info, writing to a device actually works, it seems the error is only in the response.

  5. RobertMiller-KR2 commented on Dec 29, 2025

    @RobertMiller-KR2
    Author

    Success! Kind of, temporarily until I understand the code a bit more (im not great with Java at all) I changed the line 1356 to writeResponse = theData.readUInt8(1); it was (9) The response I am getting from the PLC is only 2 bytes,

    I am writing M100 and Toggling it so if its a 1 i write 0 if its a zero I write 1. Using Wireshark IT appears to send the following ( The data portion obviously changes if its a 1 or 0)
    02ff0a0064000000204d010000

    The response from that is
    8200

    I need to take more time and understand what command / subcommands you are using to request the data to know why it is responding this way. I'm guessing my temporary "Fix" may be ignoring any errors as it was reading and writing the values to the plc but was only having an issue with the response when writing.

    I will keep you updated as I am also going to try to implement W registers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions