LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 08-18-2012, 09:00 PM   #1
ngomalj
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Rep: Reputation: Disabled
Question Real time c program application in Debian


Hi,

I am new in linux and i have created a C code for a Phasor Measurement Unit to measure the voltage and current signals from matlab in a windows pc. The communication im using between the windows and Linux PC's is UDP. I am having difficulty creating a real time C program application in Linux Debian in order to read the signals from the windows PC, can any one help me with information regarding creating a real time C program in debian.

Your assistance is highly appreciated.

Jack
 
Old 08-18-2012, 11:09 PM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
as you are not describing what;s going on in details, the best I can say is: man 2 SCHED_SETSCHEDULER
 
Old 10-23-2012, 05:00 AM   #3
ngomalj
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
I am simulating a real time power systen in matlab simulink on a Windows PC (PC1) and my goal is to measure the voltage signals from the busses of the power system. So far i have simulated my power system in real time using Maatlab and used the matlab UDP (Packet Send) communucation protocol to send the voltage signals to the other windows PC (PC2) with matlab. in PC2 i have used the UDP Packet receive communication protocol to receive the voltage signals and i was able to get the original sent signal.

Now i want to send the voltage signals from PC1 to PC3 where my PC3 has Debian Linux installed. I need to create a C program in Linux to be able to receive the voltage signals from PC1 to PC3 in order to use them as input data to my PMU. The PMU is created using C Programming to calculate the Phasors of the voltage signals data to be received from PC1.

NB! the signals should be received in real time, so the C program to receive the voltage signals data should be running in real time.

Please any advice will be highly appretiated!

Kind Regards!

Jack
 
Old 10-23-2012, 11:48 AM   #4
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,423

Rep: Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158
Nothing about that requirement is really "real time" in the conventional sense of that term. What you have is a program that needs to be able to open a UDP connection and send-and-receive data through it.

Often, this sort of programming is done using a "select() loop." You can actually find a lot of information on that subject right here on this site.

A fairly detailed example can be found here: http://www.gamedev.net/topic/310343-...-echo-example/.

Here's another: http://www.linuxhowtos.org/C_C++/socket.htm

One trick with regard to UDP is that it's a one-way protocol with no guarantee that packets will be received at all, or received in any particular order. It is "unreliable and message-oriented" whereas TCP is "reliable and stream-oriented." (The word "reliable" has a specific technical meaning in this context.)

Sometimes, high-volume applications (as a phasor handler might be) are multi-threaded so that the select()-loop thread might be running at slightly elevated priority (which is okay, since it's asleep nearly all the time, but needs to respond quickly when awakened). More CPU-intensive work can then be handled by the normal-priority thread, knowing that the listener thread will always wake up timely to handle a packet going in or out.
 
Old 10-25-2012, 08:54 AM   #5
ngomalj
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks! for your suggestions sundialsvcs, i have implemented the UDP server C program on the linux RTAI computer and i was able to read the correct data sent by the windows pc via Simulink UDP send streem block.

Now my challenge is making the UDP server program be able to read the signal data from the windows pc at specified times, eg be able to receive the signal data every 2us. I do not know much about RTAI real time programming, if you know any tutorials i can look at that are related to creating real time tasks or threads.
 
Old 10-29-2012, 07:04 AM   #6
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,622
Blog Entries: 29

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by ngomalj View Post
if you know any tutorials i can look at that are related to creating real time tasks or threads.
Have you looked in Xenomai?
 
Old 11-20-2012, 11:28 AM   #7
ngomalj
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks! for your suggestions Anisha Kaul i have implemented the rtnet RTAI simpleserver.c example and i am able to receive the data via rteth0. But there is still a delay of 1 second when i recieve the data. What i need is to be able to receive the signal data every 100us. I have also noticed that the recvfrom and rt_dev_receive from are the ones causing the 1 second delay. can anyone help me on achieving my goal of receiving data every 100u seconds.

i.e this data to be received is the samples of a dscrete sin wave which has 50 Hz frequency from the Simulink model, i need to receive 200 samples per cycle 50 Hz. Is this possible via rtnet RTAI or is there other options i can use?
 
Old 11-21-2012, 12:05 PM   #8
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,622
Blog Entries: 29

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Just for your info - Xenomai and RTAI have their dedicated mailing lists.
Xenomai's mailing list is much more active than RTAI's.

You need to produce a reproducible example, give all your system info, and
then post the question there and cross your fingers!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Real time network checking on application ? Kraiser10 Linux - Software 3 04-18-2010 10:36 AM
real time application khodeir Programming 10 12-02-2009 10:38 AM
real-time application quantt Programming 6 09-15-2009 04:58 PM
Help with deciding Linux capability for Real-Time application anantvemuri Linux - Kernel 3 03-04-2007 02:44 PM
LXer: Developing a real-time Linux data acquisition application LXer Syndicated Linux News 0 08-22-2006 12:54 AM


All times are GMT -5. The time now is 09:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration