Network Protocol and Listening Port Number with Unity3D and Matlab - matlab

I can stream motion capture data live from Xsens MVN Studio into Unity3D and animate a character with it in real-time, because the Unity3D character listens to port number 9763 of the same machine and receives the motion data from there, which means Xsens MVN Studio sends the motion data to that port. In the attachment, please see the attached image localhost:9763
Where does this port number come from? I mean who decides the port number? I could configure this live streaming between Unity3D and Xsens MVN Studio, because Xsens people provide a manual for the Unity3D plug-in, so that is how I knew about it...
My other question is that: Now, I would like to do the exact same thing with Matlab; i.e. get Unity3D to stream data live into Matlab and get back whatever Matlab produces, etc... I have found a simple Matlab script online that apparently does this with a remote website:
t = tcpip('www.EXAMPLE_WEBSITE.com', 80);
set(t, 'InputBufferSize', 30000);
fopen(t);
fprintf(t, 'GET /');
pause(1)
while (get(t, 'BytesAvailable') > 0)
t.BytesAvailable
DataReceived = fscanf(t)
end
fclose(t);
delete(t);
clear t
The code comment says: I should substitute www.EXAMPLE_WEBSITE.com with an actual website or any remote application with which I wish to communicate. But firstly, what is the www replacement for the Matlab application on the same machine (localhost??) and secondly, how do I find out which port number Matlab can send data to and Unity can listen to?
I would appreciate it if someone please help me understand these concepts...

I think they decide port number. You can choose port (Ps: Only one app can use same port at the same time.)
I think Matlab needs to behave like server. So unity request calculation result from Matlab. Matlab listens requests and gives response. I don't know how you can do in Matlab but you can request calculation result from Unity3D to Matlab server with using WWW class.

Related

How to find out how to communicate with a network device

i have a question to a network specialist.
So I have a network device, its a Sky Q receiver.
I found a nodejs plugin which sends Buffers to the device to communicate with it.
To be clear I am able to send remote commands just like using the remote control.
For example he sends a Buffer containing:
var commandBytes = [4,1,0,0,0,0,Math.floor(224 + button / 16),button % 16]
where button is a command for example 0 is power.
So my question is, this guy found out how to communicate with this receiver.
Is there a general way how to find out how you can communicate and send commands to a network device?
I tried sniffing everything I can with Wireshark when i start a socket connection to the device I receive a buffer.
Probably my question can't be answered that easy but I wanted to give it a try.
The main point, why im asking stack overflow-community about this is, I have do not a starting point how to ask google this question.
Thank you very much,

Siemens S7-1200 PLC LED DI/DO History

Is there a way to review the Digital Input/Digital Output LED light history of a Siemens S7-1200 PLC?
If so, is it through the web portal or through Simatic and can someone point me in the direction of where to find such information?
Thanks - will save me a site visit if possible in any way.
There is no built in DI/DQ history for the S7-1200.
However, if you have some form of TCP/IP connection, this can be done quite easily.
When you call outputs in your main program, use a tag based calling system. Reference that tag, and have the tag's output be:
The required DQ
A TCP/IP message saying that this tag has risen or fallen.
For inputs, just send a message on the rise and fall of each input
It is likely easiest to hold this DI/DQ history on the server that is hosting this TCP/IP connection rather than the PLC itself.

Interprocess communication with Matlab on Windows

I'm building a game in Unity3D that integrates with some code in Matlab. I'm looking for 1-way communication channel from Unity3D to Matlab on one computer.
The message is a short string.
The frequency of these messages is very low.
Example:
I start my game in Unity3D.
At the start, Unity3D send out 'message1' to Matlab
30 seconds later Unity3D sends out 'message2' to Matlab
30 seconds later Unity3D sends out 'message3' to Matlab
I know my programming knowledge is not advanced enough to do this by my own. I've been doing a ton of research and need advice on what to focus my efforts on. I don't need any sort of authentication protocol because I'm just using one computer.
Based on my description above what IPC do you think I should use and why? I need a direction on where to focus my work on because I am not very advanced.
DLL to share memory between two processes
TCP sockets
UDP sockets (what's the difference with TCP socket in my case?)
(I can't use named pipes because Unity3D does not support it.)
What you want to use is MATLAB engine API. see :
http://www.mathworks.com/help/matlab/calling-matlab-engine-from-c-c-and-fortran-programs.html?refresh=true
And there is a very nice detailed demo posted here :
http://www.umiacs.umd.edu/~jsp/Downloads/MatlabEngine/MatlabEngine.pdf
I've tested it and it worked !

How to connect to NAO robot using sockets?

I'm playing with Aldebaran's NAO humanoid robot Simulator and choregraph.
I have a software in java that I would like to use to control the robot by activating its behaviors, and I believe sockets would do the trick.
My question is: is there a way to open a socket connection from within choregraph+naoSim, so I can get sensor readings and send commands to the robot?
Or any other way to connect to choregraph+naoSim to achieve the same effect?
thanks in advance!
K
I'm planning to use python websocket package to accomplish this. As far as I see the server can be written on anything. The client part - NAO - should initiate connection to the server send something, possibly wait for a reply and then carry on. So the sending functionality can be implemented using Python and coded in one of the NAO action boxes. You could even create a separate box that will take a request as a parameter and output a reply from the server. A small neat box that talk to the server.

Interface between a DSP/Microcontroller and a PC application

I'm using a DSP to control a sensorless brushless DC motor, The DSP is on a board which has a parallel port and a jtag connection (it's an eZdspTMS320F2812). What would be the best way to communicate between a PC application and the DSP as it was running? Ideally I'd like to have a GUI program with buttons like start, stop, accelerate, decelerate... but I've never done anything like that before. Which ports and method would be easiest to use?
Thanks
You can also use simple RS232 communications. I use always because it`s cheap and easy to implement.
The RS232 transceivers are very cheap (like MAX232 from Maxim-IC), and easy to use. Also they come in many packages like DIP or SOIC for example and can be found almost every electronic shop.
You can use any USART from your microcontroller to link with MAX232. Then, using a PC serial-usb converter (or if your PC does have a serial port it`s easier), you can use serial port programming from any programming language to develop your desktop application.
After that, all you have to do is create a protocol to exchange data between your PC programm and your DSP (some simple commands to start, stop and change motor direction for example).
Good luck in your project.
The parallel port is probably the easiest route. Depending on what OS and programming language you are using you should be able to find example code or libraries to support bi-directional communication via the parallel port. Since you have a small set of commands that you might want to send to the DSP board then you can probably just send a single character to the board for each command, e.g. 'R' = start, 'S' = stop, etc.