Fpm application example, Fpm driver example, Ontimer() – Echelon i.LON SmartServer 2.0 User Manual
Page 220

206
Appendix A - Programmer’s Reference
For an FPM application, you can also use the Work() routine to start and stop timers, and you can use
it to read data point properties.
For an FPM driver, if a data point value has changed and you want to write data to the RS-232
interface as a result, you must first initialize communication between your FPM and the devices
connected to the RS-232 and RS-485 interfaces. You can initialize communication with the interfaces
using the rs232_ioctl() and rs485_ioctl() methods.
FPM Application Example
The following example demonstrates code you could use in the Work()routine of an FPM
application. In this example, the Changed() method evaluates whether the values of two data points
has changed and performs some algorithm if at least one of the values has changed.
SNVT_count in1;
SNVT_count in2;
void CUFPT_FPM_Application::Work() {
if (Changed(in1) || Changed(in2))
{
// perform some algorithm when value of in1 or in2 changes
}
FPM Driver Example
The following example demonstrates code you could use in the Work()routine of an FPM driver. In
this example, the Changed() method evaluates whether the value of a data point has changed and
initializes and writes to the RS-232 interface if it has.
SNVT_str_asc Line1;
void CUFPT_FPM_Driver::Work()
{
if (Changed(Line1))
{
//Initialize
RS-232
interface
int
nBytesToRead;
rs232_ioctl(RS232_fd,
FIONREAD,
(int)
&nBytesToRead);
// Write to RS-232 interface
rs232_write(RS232_fd,
(Byte *)Line1->ascii,
strlen((char*)Line1->ascii));
}
}
OnTimer()
The OnTimer() routine (or your custom timer handler) in the .cpp file handles timer expiration
events. You use this routine in conjunction with the Start()methods and the START_TIMER()
macros called in the Initialize() routine. When configuring the OnTimer() routine, you can
determine which timer expired using the m_oTimer.Expired() method. See Timer Methods for
more information on using these timer methods.