beautypg.com

Sensor acquisition, Getsensordata, 3 sensor acquisition – Sensoray 118 User Manual

Page 24: 1 getsensordata

background image

Sensoray Model 118 Smart A/D™ Instruction Manual

22

Commands: Sensor Acquisition

6.3 Sensor Acquisition

6.3.1 GetSensorData

Returns the most recently acquired sensor data from a
channel. The returned 16-bit integer value is scaled as a
function of the declared channel sensor type.

Regardless of sensor type, the returned value is always
represented in 16-bit two’s complement integer form.
The returned value must be multiplied by an appropriate
scalar to convert it to floating point engineering units.
Refer to Table 9 on page 36 for a list of sensor scalars.

Driver

// Read sensor data from specified channel in appropriate engineering units.

// Scalar converts integer sensor data to engineering units.

DOUBLE GetSensorData( USHORT BasePort, UCHAR Channel, DOUBLE Scalar )

{

SendByte( BasePort, Channel ); // request sensor data

return Scalar * (DOUBLE) ReadWord( BasePort ); // return scaled data

}

Example

// Read voltage at Channel 6, which is configured for 5V, 200uV/bit range.

DOUBLE Chan6volts = GetSensorData( MyBasePort, 6, SCALAR_VOLTS_5 );

Example

// Read temperature (in degrees C) at channel 4, which is configured for

// a type K thermocouple.

DOUBLE Chan4temp = GetSensorData( MyBasePort, 4, SCALAR_TC_K );

Command: (Chan)

Response:

(DataMSB),(DataLSB)

This manual is related to the following products: