Prev: 2009b 'nmake' is not recognized error on a Win7 64 with Visual C++ 9.0
Next: Reducing Gibbs phenomenon
From: Chris Crain on 5 May 2010 11:05 I took this from the daq-sim example in the pnet examples. It seems to work pretty well. It has been modified slightly. Setup Socket: udpsock=pnet('udpsocket',4637); %<---- Bind the socket to receive packets here. pnet(udpsock,'setwritetimeout',1); pnet(udpsock,'setreadtimeout',0); pnet(udpsock,'printf', '33554432'); %<-----Data to sending. pnet(udpsock,'writepacket','192.168.1.22',8); %<--- Actually sends the data. Receive Portion: packnr=0; start_time=clock(); while packnr<16, len=pnet(udpsock,'readpacket'); packnr=packnr+1; if(len > 0) data = pnet(udpsock,'read', 32,'uint16','network'); fprintf('PACK %02d len=%06d id=%d\n',packnr,len,id_list(packnr)); fprintf('PACK size:%d \n',len); end if etime(clock(),start_time) > TIMEOUT, fprintf('TIMEOUT....:-(\n'); break; end end; pnet(udpsock,'close'); if packnr==16, fprintf('All packs received :-)\n'); end Now my issue is trying to decipher the received data:( I think I am using wrong syntax or something. "Ryan " <ryan.kelly(a)mikelinc.com> wrote in message <ftnjet$m7g$1(a)fred.mathworks.com>... > I'm using pnet to send and receive UDP packets. When I send > try to read the socket with the command > > len = pnet(socket,'readpacket') > > It works fine until a message isn't there. At this point the > prompt hangs up because I imagine it continues to read until > it receives something. > > I've tried > to create the socket > socket = pnet('udpsocket',5021) > > and I've tried > > socket = pnet('udpsocket',5021,'setreadtimeout',1); > > neither seemed to help I'm assuming you cant set a timeout > to a socket but only a connection. I'm trying to maintain a > "connectionless" method of data transfer and UDP is a > necassary evil. Any suggests or helpful ideas would be > appreciated. > > Thanks in advance > Ryan
From: Ankit Desai on 5 May 2010 12:12
"Ryan " <ryan.kelly(a)mikelinc.com> wrote in message <ftnjet$m7g$1(a)fred.mathworks.com>... > I'm using pnet to send and receive UDP packets. When I send > try to read the socket with the command > > len = pnet(socket,'readpacket') > > It works fine until a message isn't there. At this point the > prompt hangs up because I imagine it continues to read until > it receives something. > > I've tried > to create the socket > socket = pnet('udpsocket',5021) > > and I've tried > > socket = pnet('udpsocket',5021,'setreadtimeout',1); > > neither seemed to help I'm assuming you cant set a timeout > to a socket but only a connection. I'm trying to maintain a > "connectionless" method of data transfer and UDP is a > necassary evil. Any suggests or helpful ideas would be > appreciated. > > Thanks in advance > Ryan Ryan, You can use the UDP object in Instrument Control Toolbox. With that object, you can set the DatagramReceived or BytesAvailable function callbacks to perform exactly what you are looking for. Hope this helps, -Ankit |