You can access SM2 analog, digital, and text values through the C API that the driver supplies. The file SM2API.H describes the API and the functions reside in the file SM2API.LIB. You can link this library file to your C application to access the API's functions. You can find both files in your Base path. By default, this path is C:\Program Files (x86)\Proficy\iFIX\ or C:\IFIX\, depending where you installed iFIX.
NOTE: You must have the iFIX Integration (EDA) Toolkit installed to use this API.
Example
Suppose you are using the SM2 driver to store data from a legacy system. Using the C API and a number of preconfigured analog blocks, you can extract your data from the legacy system and store it in your process database.
Syntax |
Values read, written, and returned |
UINT16 GetAnalog(UINT16 index, FLOAT *data); |
GetAnalog reads an analog value (32-bit float) to the register indicated by 'index'. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. FE_RANGE is returned if the analog value exceeds the range of a 32-bit float. NOTE: GetAnalog and GetDouble access the same table in the SM2. |
UINT16 SetAnalog(UINT16 index, FLOAT data); |
SetAnalog writes an analog value (32-bit float) to the register indicated by 'index' and causes an exception for the specified register even if the data has not changed. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. NOTE: SetAnalog and SetDouble access the same table in the SM2. |
UINT16 GetDouble(UINT16 index, DOUBLE *data); |
GetDouble reads an analog value (64-bit float) to the register indicated by 'index.' FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. NOTE: GetAnalog and GetDouble access the same table in the SM2. |
UINT16 SetDouble(UINT16 index, DOUBLE data); |
SetDouble writes an analog value (64-bit float) to the register indicated by 'index' and causes an exception for the specified register even if the data has not changed. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. NOTE: SetAnalog and SetDouble access the same table in the SM2. |
UINT16 GetDigital(UINT16 index, UINT16 *data); |
GetDigital reads 16 digital values (all 16 bits in one of the 20,000 digital registers) to the register indicated by 'index'. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. NOTE: The API can only read and write the entire 16 bit digital register at one time. If you want to change 1 bit, you can read the register, modify the desired bit and write the register. However, when you modify a single bit, ensure that only one thread in one application is accessing a digital register at one time. |
UINT16 SetDigital(UINT16 index, UINT16 data); |
SetDigital writes 16 digital values (all 16 bits in one of the 20,000 digital registers) to the register indicated by 'index' and causes an exception for all 16 bits of the specified register even if the data has not changed. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. NOTE: The API can only read and write the entire 16 bit digital register at one time. If you want to change 1 bit, you can read the register, modify the desired bit and write the register. However, when you modify a single bit, ensure that only one thread in one application is accessing a digital register at one time. |
UINT16 SetDigitalEx(UINT index, UINT16 data, UINT16 mask) |
SetDigitalEx writes 16 digital values (all 16 bits in one of the 20,000 digital registers) to the register indicated by 'index' and causes an exception for specific bits selected from a mask. An exception is triggered for the bits set in the mask even if the data has not changed. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. NOTE: The API can only read and write the entire 16 bit digital register at one time. If you want to change 1 bit, you can read the register, modify the desired bit and write the register. However, when you modify a single bit, ensure that only one thread in one application is accessing a digital register at one time. |
UINT16 GetText(UINT16 index, char *data, int size) |
GetText reads the text specified by `data' from text registers starting at the register indicated by `index'. The number of characters to read is indicated by `size'. GetText does not automatically add a null terminator to the text being read. If you require null-terminated strings, make sure your program adds a null terminator after reading text. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. |
UINT16 SetText(UINT16 index, char *data, int size) |
SetText writes the text specified by `data' to text registers starting at the register indicated by `index'. The number of characters to write is indicated by `size'. Exception-based processing is not supported for text values. SetText does not automatically add a null terminator to the text being written. If you require null-terminated strings, make sure your program adds a null terminator prior to writing the text. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. |
UINT16 GetCommError(UINT16 *data); |
GetCommError reads the communication error flag to the S register. The flag is a 1 bit integer value. FE_OK is returned always. |
UINT16 SetCommError(UINT16 data); |
SetCommError writes the communication error flag to the S register. The flag is a 1-bit integer value. You should only pass 0 or 1 to the SetCommError function. Using any other value can have unpredictable results. FE_OK is returned always. |
UINT16 GetAnalogAlarm(UINT16 index, INT16 *alm); |
GetAnalogAlarm reads an alarm status from an analog register indicated by 'index'. To learn more about available alarm statuses, refer to Understanding Alarm Statuses. NOTE: As of iFIX 4.5, only the alarm statuses IA_OK and IA_COMM are supported for use through the SM2 driver. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. |
UINT16 SetAnalogAlarm(UINT16 index, INT16 alm); |
SetAnalogAlarm writes an alarm status to an analog register indicated by 'index' and causes an exception for the specified register even if the data or alarm has not changed. To learn more about available alarm statuses, refer to Understanding Alarm Statuses. NOTE: As of iFIX 4.5, only the alarm statuses IA_OK and IA_COMM are supported for use through the SM2 driver. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. |
UINT16 GetDigitalAlarm(UINT16 index, INT16 *alm); |
GetDigitalAlarm reads an alarm status from a digital register indicated by 'index'. To learn more about available alarm statuses, refer to Understanding Alarm Statuses. NOTE: As of iFIX 4.5, only the alarm statuses IA_OK and IA_COMM are supported for use through the SM2 driver. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. |
UINT16 SetDigitalAlarm(UINT16 index, INT16 alm); |
SetDigitalAlarm writes an alarm status to a digital register indicated by 'index' and causes an exception even if the data or alarm has not changed. The same alarm is associated with all 16 bits in the digital register. To learn more about available alarm statuses, refer to Understanding Alarm Statuses. NOTE: As of iFIX 4.5, only the alarm statuses IA_OK and IA_COMM are supported for use through the SM2 driver. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. |
UINT16 GetTextAlarm(UINT16 index INT16 alm) |
GetTextAlarm reads an alarm status from a text register indicated by `index'. To learn more about available alarm statuses, refer to Understanding Alarm Statuses. NOTE: As of iFIX 4.5, only the alarm statuses IA_OK and IA_COMM are supported for use through the SM2 driver. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. |
UINT16 SetTextAlarm(UINT16 index, INT16 alm) |
SetTextAlarm writes an alarm status to a text register indicated by 'index'. When a block reads data from the SM2 driver, the alarm status of the first byte is returned. The status of additional bytes is ignored. To learn more about available alarm statuses, refer to Understanding Alarm Statuses. NOTE: As of iFIX 4.5, only the alarm statuses IA_OK and IA_COMM are supported for use through the SM2 driver. FE_OK is returned if the operation succeeds. FE_IO_ADDR is returned if the register index is out of range. |