Home>
Send value from Simulink to Node.js side by UDP communication

Currently, I would like to convert 4 values ​​(Vx, Vy, Vz, ωz) from simulink to byte type with Matlab (PC1) and send the values ​​to Node.js side by UDP communication. The environment on the server side (simulink side) is in place, but there are unclear points about the program on the Node.js side (receiver side), and data is not received (UDP communication is not possible).
How can I rewrite the program on the receiving side (Node.js side) to send the data? I would appreciate it if you could tell me.


Data cannot be sent from the simulink side (PC1) to the Node.js side (PC2).
I don't know how to write the program on the receiving side (Node.js).
Corresponding source code
var PORT = 33333;// Same as the port on the simulink (PC1) side
var HOST = '192.168.11.61';// IPv4 address on the simulink (PC1) side
var dgram = require ('dgram');
var server = dgram.createSocket ('udp4');// Socket for UDP communication
// Below, I don't know how to rewrite the program //
server.on ('listening', function () {
  var address = server.address ();
 console.log ('UDP Server listening on' + address.address +':' + address.port);//
});
server.on ('message', function (message, remote) {
 console.log (remote.address +':' + remote.port +'-' + message);
});
server.bind (PORT, HOST);
What I tried

Confirmation of PORT and IPv4 addresses.
Improvements to the receiving program.

Supplementary information (FW/tool version, etc.)

-PC1 and PC2 are both notebook PCs. (PC1 will be done in the same way on desktop PCs in the future)
(PC1: Windows10 PC2: DELL)
・ Matlab: R2018b
・ Language: Node.js

  • Answer # 1

    I think you're probably asking after seeing this,
    Please look again.

    UDP communication with Node.js --Re: note

    Since it is necessary to make a launch port for UDP as well as for sending,
    server.bind (PORT, HOST);To specify.

    At this time, the code of the question text is your machine127.0.0.1Please specify the IP address of.
    Why can I specify another person's IP address?
    127.0.0.1I don't know how to use it other than.

    Assuming that the lower right environment is Node.js from the system requirements diagram
    I think that this kind of information will be entered in the first line.

    var PORT = 35000;// Same as the port on the simulink (PC1) side
    var HOST = '12 7.0.0.1';