Writes one or more analog outputs.
- Parameters
-
[in] | handle | Valid handle returned by SM_Open(). |
[in] | start | Starting output (zero-indexed). |
[in] | number | Quantity of analog outputs to write. |
[in] | analogValues | Desired output values as floating point values (voltages). |
[in] | ranges | Array of analog output ranges. |
[in] | byteValues | Desired output values as 16-bit byte values. |
- Return values
-
>=0 | Number of bytes successfully written. |
-1 | Invalid SeaMAX handle. |
-2 | Either 'byteValues' or 'analogValues' must be null. Supply either one, but not both. |
-3 | If an array of doubles is supplied, a similar array of analog output ranges must also be supplied. |
-4 | One or more of the analog output channel ranges was an invalid range. |
-5 | Connection is not established. Check the provided Connection object state. |
-6 | Read error waiting for response. Unknown Modbus exception. |
-7 | Illegal Modbus Function (Modbus Exception 0x01). |
-8 | Illegal Data Address (Modbus Exception 0x02). |
-9 | Illegal Data Value (Modbus Exception 0x03). |
-10 | Modbus CRC was invalid. Possible communications problem. |
Writes one or more analog output values. This function may be called one of two ways: either as with an array of floating point voltage values (with corresponding ranges), or with an array of 16-bit byte values.
- Note
- This function will either take an array of doubles (and it's corresponding ranges), or an array of bytes - but not both.
Double Array - Output Voltages
If an array of doubles is supplied, the array must contain at least one double for each analog output to be written. Each floating point value corresponds to the desired voltage output for each channel. Along with an array of floating point values, an array of analog output channel ranges must also be supplied - which map directly to the target analog outputs.
For instance, if two analog outputs are to be written the values 2.56 V and 5.64 V consecutively starting at output 3, the following arrays and values would need to be supplied:
analogValues[0] = 2.56
analogValues[1] = 5.64
ranges[0] = Analog Output 3's Range
ranges[1] = Analog Output 4's Range
The analog output ranges can be found by calling the SM_GetAnalogHardwareInfo() function.
Byte Array - 16-bit Byte Values
If an array of bytes is supplied, the array must contain at least two bytes for every analog output to be written. The byte array should be filled with two-byte values to be written directly to the analog I/O device's registers. The byte order is such that the high-byte is always first. For instance, if two analog outputs are to be written at input 4 with the values 0x0F73 and 0x011A, the byte array should contain:
byteValues[0] = 0x0F
byteValues[1] = 0x73
byteValues[2] = 0x01
byteValues[3] = 0x1A
Referenced by SM_WriteHoldingRegisters().