Universal Robots Forum

Socket Communication with Matlab

Hi there,
I try to implement to read data streams from the UR controller using the socket interface and port 30003. To do this I’m using Matlab. If I want to read the actual position in X for example I read Byte 444-451, like described in the Client_Interface_V3.5.xls and convert it to a floating point number. But the value makes no sense. Here is my example code:

socketClientRTC= tcpip(TCPclient, 30003, ‘NetworkRole’, ‘client’);
data= socketClientRTC.fread;
dataCartPosX= [uint8(data(444)) uint8(data(445)) …
uint8(data(446)) uint8(data(447)) …
uint8(data(448)) uint8(data(449)) …
uint8(data(450)) uint8(data(451))];
floatPosX= typecast(dataCartPosX, ‘double’);

Thanks in advance,

Hi Chris,

I don’t have Matlab to test your code but could it potentially be a byte order issue? Try swapbytes?


Thanks for the answer.
Yes I tried this also, but it doesnt work.

Ok, does any of the rest of the message make sense? Like the message size or the time? Does the value change at all when you change the TCP X position? I do the same thing with the Python struct library and it seems to work.

Yes, it changes, but the values make no sense.