Miniu
8 October 2019 11:46
1
Hi,
I use Node Red to communicate with a Universal Robots robot. I connect to it via TCP / IP.
From the robot, I receive a stream of buffer, according to the manufacturer, with a frequency of 10 Hz.
Unfortunately, when using this connection, it turned out that some of the information did not reach NodeRed at all.
I did the test: I wrote a program with the same functionality but outside Node Red in JS and easily received all the information.
Dear developers. can you help me or show me where the problem is?
Below "recipe" of the message from robot:
Below my code:
Iread byte 4 from the signal I received, unfortunately I have never received a message with the number 25 .
If you need additional information, screenshots etc. let me know.
Thank you very much in advance,
Regards,
Michał
I'd start with sending data/payload (unmodified) to a debug node to see if data is broken up or missing something before trying to figure out if the function code or node-red environment is the problem.
Just to put your mind at ease a little, I use TCP for receiving ASCII data (no real difference) from a legacy system, but the data has a well defined start and end mark to work from.
What instructs your TCP node that it's a finished piece of data? Are you sure data is not split differently to how you expect? (Debug node is your friend here as explained in first node)
1 Like
Miniu
28 October 2019 09:35
4
Hi @Steve-Mcl ,
I have checked all of things you mentioned and unfortunetly I have no solution to my problem. I have never received message that I should have.
Now I am thinking how to make my own tcp input node basing on my Javascript code.
Could anybody help with that?
My code in JS.
var net = require('net');
var client = net.connect(30001, '10.35.135.240', function() {
console.log('connected to server!');
});
client.on('data', function(data) {
if(data instanceof Buffer){
var buf1msglen = data.slice(0,4);
var buf2msgtype = data.slice(4,5);
var msglen = buf1msglen = buf1msglen.readUInt32BE(0);
var msgtype = buf2msgtype.readUInt8(0);
//console.log ('Message length: ' + msglen);
//console.log ('Message type: ' + msgtype);
if(msgtype === 20){
//console.log ('found messagetype 20 ___--');
var buf3robotmsgtype = data.slice(14,15);
var robotmsgtype = buf3robotmsgtype.readUInt8(0);
console.log('Robot message type: ' + robotmsgtype);
if(robotmsgtype===9){
buf4requestType=data.slice(19,20);
var requestType=buf4requestType.readUInt8(0);
buf5textMessage=data.slice(20,msglen);
var textMessage=buf5textMessage.toString();
console.log('Request type: ' + requestType);
console.log('Text type: ' + textMessage);
}
}
}
});
client.on('end', function() {
console.log('disconnected from server');
})