Jump to content
OMRON Forums

Receiving high frequency UDP packets


AlexM

Recommended Posts

I am working on a background program that needs to receive and process packets that are being sent at 1000Hz.

I am currently using recvfrom() to read the packets from the socket, but it appears to be too slow to keep up with the rate I am receiving data.

I have tried taking out all processing of the data so I am only calling recvfrom() and timing it using GetCPUClock(), which seems to be taking up to around 8ms for that function alone.

 

Are there any other methods of receiving UDP packets from a socket that would be able to cope with 1000Hz?

 

Cheers,

Alex

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

 

if you want fixed frequency for sending and receiving packets, then you should not use background program.

Please refer to Power PMAC User Manual, Writing C Functions and Programs in Power PMAC.

we have several different task levels you can choose: User-Written Phase routine, Servo routine, or Real-Time interrupt C PLC Routine.

These routines are running at user-defined frequencies.

Link to comment
Share on other sites

Hi Jay, thanks for the reply.

 

Unfortunately I don't think any of those task levels are appropriate for what I need to do. I am the packets via UDP and as far as I am aware socket programming is not available in User-written Phase/Servo routines, and not recommended in RTI PLC routines.

 

Also, the specific problem I asked about in this thread is that the function I am using to read the packet from the socket is taking 8ms to execute, so if I used it in an RTI routine which has 0.5ms available to complete it would stall everything.

 

I also don't need a fixed frequency as I am not sending packets out, only receiving them from a source that sends them at 1000Hz. I just need to be able to process them as quickly as possible.

Link to comment
Share on other sites

You could also make a thread in a "background program" that that is scheduled to run at 2 kHz. Check out this document for details:

 

http://forums.deltatau.com/filedepot/download.php?f=Power%20PMAC/Application%20Notes/Library%20for%20Custom%20Threading/Manually%20Scheduling%20Threads%20in%20Power%20PMAC.pdf [FILE REMOVED]

 

Under Library for Custom Threading on FileDepot.

 

Dump the packets you receive into a queue and process them in another thread (background is OK) to save computation time.

Link to comment
Share on other sites

Alex: This is definitely possible; a while back we wrote an Ethernet server that ran with <500us (+/- jitter) between packets. It was written as a background C application.

 

We used an architecture based on select() to poll for sockets that are active. Once a socket received data it was added to the set via select() and then we used recvfrom() to read the data and return a response. Some optimization may be required to ensure that parsing the packet doesn't take too long depending on what you are doing.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...