Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CtrlxDatalayerV2.js does not support raw bytes returned from Datalayer #88

Open
pionex opened this issue Jan 20, 2025 · 1 comment
Open

Comments

@pionex
Copy link

pionex commented Jan 20, 2025

I have a Fanuc robot connected over ethercat. If I use the SDK to read the data from the robot, it comes in as type RAW and is a raw byte array. The Javascript code used by the node-red modules does not handle this situation. In CtrlxDataLayerV2.js, on line 306, there is a call to res.setEncoding('utf8'). This breaks the ability to receive raw bytes. If this line is removed, then the functionality there will correctly read the raw bytes into a javascript buffer type. It can then be converted to a utf8 string and parsed by the JSON parser. If that fails (and the buffer contains data), then the raw buffer data could be returned in JSON format as a hex string or something similar. Here is the code I have modified as an proposed solution:

    const req = https.request(options, (res) => {
      let data = Buffer.alloc(0);

	  //res.setEncoding('utf8');
      res.on('data', function(chunk) {
        data = Buffer.concat([data, chunk]);
      });

      res.on('end', function() {

        // We expect 200 on success
        if (res.statusCode !== 200) {
          callback(CtrlxProblemError.fromHttpResponse(res, data));
          return;
        }

		let dataString = data.toString('utf8');
		console.debug(data)
		console.debug(dataString)
        // Try to parse the data
        let payload;
        try {
          payload = CtrlxDatalayer._parseData(dataString);
        } catch (err) {
		  
		  let payloadString = data.toString('hex');
		  payload = { data: payloadString };
		  //callback(err, null);
        }

        // No error, return payload data.
        callback(null, payload);
      });
    });
@ZmRZjFuDsDiR4qi5801F
Copy link
Contributor

ZmRZjFuDsDiR4qi5801F commented Jan 23, 2025

Hello,
do you use a ctrlX Core to read the data from the Fanuc robot over PLC? How to you fetch the data from the robot? Please provide some more information's about. This library can only be used to communicate with a ctrlX OS Automation system.

We're going to verify this issue and provide a fix as soon as possible.
Thank you for reporting.

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

No branches or pull requests

2 participants