how to send packet over UDP socket to controller

3 visualizaciones (últimos 30 días)
Lalji goti
Lalji goti el 16 de Dic. de 2013
Comentada: Walter Roberson el 16 de En. de 2014
Hello,
i want to send packet which contain following data
header=0x1234(uint16); <---this is hex number
command=2(uint16)
num_samples=1(uint32);
can anyone help how can i create packet
what i am doing is
my pc, ipA = '192.168.1.10'; portA = 49153;
ATI F/T sensor, ipB = '192.168.1.2'; portB = 49152;
udpA = udp(ipB,portB,'LocalPort',portA);
fopen(udpA);
request=zeros(1,3)%created array
header = '0x1234';
command= 2;
num_samples = 1;
a = char(header)
b=command;
c=num_samples;
request(1,1)=int16(a)
request(1,2)=int16(b)
request(1,3)=int32(c)
fwrite(udpA, request)
when i send this packet robot should start to send data to my pc
but i am not getting any data when i run fread(udpA) command.
here i had attached my C code file same functionality i would like to build in matlab

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Dic. de 2013
Editada: Walter Roberson el 16 de En. de 2014
a = hex2dec(header);
request = [ typecast(int16([a, b]), 'uint8'), typecast(int32(c), 'uint8') ];
It is uncommon for commands or headers or counts to be signed integers. You should re-check whether they are really int16() and int32() or are instead uint16() and uint32()
  11 comentarios
Lalji goti
Lalji goti el 16 de En. de 2014
Editada: Lalji goti el 16 de En. de 2014
Hello Walter Roberson,
how can i run two program parallel in matlab. means my one program getting position data continuously from robot. anotther program sending command in between first program is running..
data listening program
while 1
while ~(iStream.available)
end
readS(iStream);
end
command sending program
while 1
userInput = input('Server: ', 's');
oStream.sendS(userInput);
end
how can i run this both infinite loop program parallel in matlab i want some commands to controller while datal listening infinite loop is runnig...
Plz Help me out
Walter Roberson
Walter Roberson el 16 de En. de 2014
This has been answered in your Question that you created about it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Call Java from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by