Analog, Digital I/O and Valve functions

Overview

Functions for reading and writing the analog and digital inputs and outputs of Nemesys devices.

+ Collaboration diagram for Analog, Digital I/O and Valve functions:

Functions

long NemV4ReadAnalogInput (TNemesysV4 *Nemesys, enum eNemV4AnalogInput Input, int16_t *Value_mV)
 Reads the analog input value of the given Input and returns it in Value_mV. More...
 
long NemV4ReadDigitalInput (TNemesysV4 *Nemesys, enum eNemV4DigitalInput Input)
 Reads the state of one single digital input. More...
 
long NemV4ReadDigitalInputs (TNemesysV4 *Nemesys, uint32_t *Inputs)
 Reads all 4 digital inputs from the device and returns the inputs bitmask in Inputs. More...
 
long NemV4SwitchValve (TNemesysV4 *Nemesys, uint8_t ValvePosition)
 Switches a valve connected to the Nemesys I/O connector to a given position. More...
 
long NemV4WriteDigitalOutput (TNemesysV4 *Nemesys, enum eNemV4DigitalOutput Output, uint8_t On)
 Switches one single digital output channel on/off. More...
 
long NemV4WriteDigitalOutputs (TNemesysV4 *Nemesys, uint32_t OutputMask, uint32_t States)
 Switches the given digital outputs on/off. More...
 

Function Documentation

long NemV4ReadAnalogInput ( TNemesysV4 Nemesys,
enum eNemV4AnalogInput  Input,
int16_t *  Value_mV 
)

Reads the analog input value of the given Input and returns it in Value_mV.

Parameters
[in]NemesysDevice pointer
[in]InputInput identifier. Nemesys pumps have two analog input: the external analog input from the I/O interface and the internal force sensor analog input.
[out]Value_mVReturns the value read from Nemesys in mV
Returns
Error code - ERR_NOERR indicates success

Referenced by NemV4ReadForceSensor().

1171 {
1172  uint32_t Value;
1173  long Result;
1174 
1175  Result = CsiDevReadObject(&Nemesys->Device, NemV4_OD_H3160_ANALOG_INPUT,
1176  Input, &Value);
1177  *Value_mV = (int32_t)Value;
1178  return Result;
1179 }
struct CsiDev Device
CSI device object.
Definition: nem4_rs232_api.h:107
long CsiDevReadObject(struct CsiDev *pDev, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint32_t *pRxDWord)
This function reads up to 4 bytes of data from device object dictionary.
Definition: csi_dev.c:157

+ Here is the call graph for this function:

long NemV4ReadDigitalInput ( TNemesysV4 Nemesys,
enum eNemV4DigitalInput  Input 
)

Reads the state of one single digital input.

This is just a convenience function that calls NemV4ReadDigitalInputs internally.

Parameters
NemesysThe Nemesys device to read from.
InputThe input identifiers.
Return values
<0 Error
0Input is off
1Input is on

Referenced by NemV4IsSafetyStopActive().

1232 {
1233  long Result;
1234  uint32_t Inputs;
1235 
1236  Result = NemV4ReadDigitalInputs(Nemesys, &Inputs);
1237  CSI_RETURN_ON_ERROR(Result);
1238 
1239  return (Inputs & Input) ? 1 : 0;
1240 }
long NemV4ReadDigitalInputs(TNemesysV4 *Nemesys, uint32_t *Inputs)
Reads all 4 digital inputs from the device and returns the inputs bitmask in Inputs.
Definition: nem4_rs232_api.c:1221

+ Here is the call graph for this function:

long NemV4ReadDigitalInputs ( TNemesysV4 Nemesys,
uint32_t *  Inputs 
)

Reads all 4 digital inputs from the device and returns the inputs bitmask in Inputs.

Inputs contains the input bitmask for all 4 digital inputs. To test for a certain digital input use the eDigitalInput enum values. The following example shows, how to test if the safety stop input is active.

uint32_t Inputs;
NemV4ReadDigitalInputs(Nemesys, &Inputs);
{
...
}
Parameters
NemesysThe device to read from
InputsInput bit mask. Use the eNemV4DigitalInput enum values to test for a certain input.
Returns
Error code - ERR_NOERR indicates success

Referenced by NemV4ReadDigitalInput().

1222 {
1223  return CsiDevReadObject(&Nemesys->Device, NemV4_OD_H60FD_DIGITAL_INPUTS,
1224  0, Inputs);
1225 }
struct CsiDev Device
CSI device object.
Definition: nem4_rs232_api.h:107
long CsiDevReadObject(struct CsiDev *pDev, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint32_t *pRxDWord)
This function reads up to 4 bytes of data from device object dictionary.
Definition: csi_dev.c:157

+ Here is the call graph for this function:

long NemV4SwitchValve ( TNemesysV4 Nemesys,
uint8_t  ValvePosition 
)

Switches a valve connected to the Nemesys I/O connector to a given position.

The two digital outputs NEM4_DIG_OUT_EXTERNAL_1 and NEM4_DIG_OUT_EXTERNAL_2 are used for valve switching. With these two output it is possible to switch 4 different valve positions (Binary: 00, 01, 10, 11). For different valves, different switching positions are available:

  • 3/2 way CETONI smartvalve: you can switch the two positions 0 and 1 (application, reservoir)
  • 3/4 way CETONI smartvalve: you can switch the positions 0 - closed, 1 - Port 1, 2 - Port 2 and 3 - both ports open. You can also use the enumeration eNemV4ContiflowValvePositions for switching
  • 4/4 way ball valve: you can switch the positions 0 - closed, 1 - Port 1, 2 - Port 2. You can also use the enumeration eNemV4ContiflowValvePositions for switching
Parameters
NemesysThe Nemesys device to control
ValvePositionValve position in the range from 0 - 3
Returns
Error code - ERR_NOERR indicates success
1150 {
1151  uint32_t OutputMask = NEM4_DIG_OUT_EXTERNAL_1 | NEM4_DIG_OUT_EXTERNAL_2;
1152  uint32_t States = 0;
1153  if (ValvePosition & 0x01)
1154  {
1155  States |= NEM4_DIG_OUT_EXTERNAL_1;
1156  }
1157 
1158  if (ValvePosition & 0x02)
1159  {
1160  States |= NEM4_DIG_OUT_EXTERNAL_2;
1161  }
1162 
1163  return NemV4WriteDigitalOutputs(Nemesys, OutputMask, States);
1164 }
long NemV4WriteDigitalOutputs(TNemesysV4 *Nemesys, uint32_t OutputMask, uint32_t States)
Switches the given digital outputs on/off.
Definition: nem4_rs232_api.c:1097
Nemesys I/O interface digital output 1.
Definition: nem4_rs232_api.h:84
Nemesys I/O interface digital output 2.
Definition: nem4_rs232_api.h:85

+ Here is the call graph for this function:

long NemV4WriteDigitalOutput ( TNemesysV4 Nemesys,
enum eNemV4DigitalOutput  Output,
uint8_t  On 
)

Switches one single digital output channel on/off.

If you would like to switch multiple digital outputs at the same time, you should use the NemV4WriteDigitalOutputs() function.

Parameters
NemesysThe device to control
OutputThe digital output channel (see eNemV4DigitalOutput)
On0 = off, 1 = on
Returns
Error code - ERR_NOERR indicates success
See also
NemV4WriteDigitalOutputs()
1139 {
1140  uint32_t OutputMask = Output;
1141  uint32_t OutputStates = On ? Output : ~Output;
1142  return NemV4WriteDigitalOutputs(Nemesys, OutputMask, OutputStates);
1143 }
long NemV4WriteDigitalOutputs(TNemesysV4 *Nemesys, uint32_t OutputMask, uint32_t States)
Switches the given digital outputs on/off.
Definition: nem4_rs232_api.c:1097

+ Here is the call graph for this function:

long NemV4WriteDigitalOutputs ( TNemesysV4 Nemesys,
uint32_t  OutputMask,
uint32_t  States 
)

Switches the given digital outputs on/off.

This functions switches multiple digital outputs at the same time. The OutputMask parameter defines, which outputs to set and the States parameter configures the on/off state of the outputs that will be switched. Use the enum eNemV4DigitalOutput to create the OutputMask and the output states parameter. If you would like to switch only a single digital output, it is easier to use the NemV4WriteDigitalOutput() function.

The following code switches the blue device LED on and off.

The following code switches the I/O interface digital outputs 1 on and the digital output 2 off.

uint32_t States = NEM4_DIG_OUT_EXTERNAL_1;
NemV4WriteDigitalOutputs(Nemesys, OutputMask, States);
Parameters
NemesysThe device to control
OutputMaskDigital output mask configures the digital outputs to switch
StatesThe states (0 = off, 1 = on) of the digital outputs to switch
Returns
Error code - ERR_NOERR indicates success
See also
NemV4WriteDigitalOutput()

Referenced by NemV4SwitchValve(), and NemV4WriteDigitalOutput().

1098 {
1099  long Result;
1100  uint32_t DigOutputs = (Nemesys->DigOutShadowRegister &~ OutputMask) | States;
1101  uint32_t FinalOutputMask;
1102  int32_t AnalogValue_mV;
1103 
1104  // First write the real digital outputs - the read digital outputs
1105  // are in the high word. Therefore we create the output mask that
1106  // ignores the low word
1107  FinalOutputMask = OutputMask & ~0xFFFF;
1108 
1109  // We only need to write the outputs, if we change something changed in
1110  // the high word
1111  if (FinalOutputMask)
1112  {
1113  Result = CsiDevWriteObject(&Nemesys->Device, NemV4_OD_H60FE_DIG_OUT,
1114  1, DigOutputs);
1115  CSI_RETURN_ON_ERROR(Result);
1116  }
1117 
1118  // Now we write the digital outputs that are generated from the analog
1119  // output 1 multiplexer. These channels are mapped into the low word
1120  // of the given States
1121  FinalOutputMask = OutputMask & 0xFFFF;
1122  if (FinalOutputMask)
1123  {
1124  DigOutputs &= 0xF;// the 4 channels are mapped into bit 0 - 3
1125  AnalogValue_mV = (4000 - 500 * DigOutputs);
1126  Result = CsiDevWriteObject(&Nemesys->Device, NemV4_OD_H3182_ANALOG_OUT,
1127  1, AnalogValue_mV);
1128  CSI_RETURN_ON_ERROR(Result);
1129  }
1130 
1131  return ERR_NOERR;
1132 }
struct CsiDev Device
CSI device object.
Definition: nem4_rs232_api.h:107
long CsiDevWriteObject(struct CsiDev *pDev, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint32_t TxDWord)
This function writes up to 4 bytes of data into device object dictionary.
Definition: csi_dev.c:188
uint32_t DigOutShadowRegister
the shadow register helps setting individual digital outputs
Definition: nem4_rs232_api.h:117
#define ERR_NOERR
No error.
Definition: err_codes.h:102

+ Here is the call graph for this function: