You can do this. Just make sure to put nanosleep() in your infinite loop, or you'll watchdog the PPMAC. You should also create a break condition variable so you can stop the program when you want.
You can write your message to a global variable for convenience.
First, assign these globals in your global definitions.pmh file; something like:
global MySerialPortMessage, MyBreakConditionVariable = 0.0;
Then, in your C program, you can make a loop like so:
while(pshm->P[MyBreakConditionVariable] < 1.0) {
//Write out the command to read display on meter...
ret = write(SerialPort, SampleCommand, strlen(SampleCommand));
//If write() does not return the requested number of bytes to write, we have a problem.
//Pass return code on to the calling routine.
if(ret != strlen(SampleCommand))
{
Send(1, "Problem writing to port!"); // Send to PPMAC's Send1 port
return ret;
}
//Read back the string into the "msg" buffer...
ret = ReadSerialLine(msg, EXAMPLE_CODE_RESPONSE_MAX, '\n', SerialPort, 10.000);
if(ret)
{
Send(1, "Did not get a response from port!"); // Send to PPMAC's Send1 port
return ret;
}
pshm->P[MySerialPortMessage] = atof(msg);
MySleepSec(0.1); // sec
}
Where
void MySleepSec(double SleepTimeSeconds)
{
struct timespec Timer;
Timer = Sec2TimeSpec(SleepTimeSeconds);
nanosleep(&Timer,NULL);
}
and
struct timespec Sec2TimeSpec(double TimeSec)
{
struct timespec Timer;
Timer.tv_sec = (long int)TimeSec;
Timer.tv_nsec = (long int)((TimeSec-(double)Timer.tv_sec)*1000000000.0);
return Timer;
}
To break your loop, just write MyBreakConditionVariable=1 from any program or the Terminal window.