SetAnalogEventDef Method

void SetAnalogEventDef(int bank, int channel, int lomark, int himark, Eth32AnalogEvtDef defaultval)

Summary

This method defines the event thresholds for a single logical analog channel in the specified analog event bank. The thresholds that are defined determine what analog readings will cause the event to fire. The thresholds allow the event logic on the ETH32 device to assign a current state (high or low) to the event. The event will be considered high if the analog reading is at or above the given hi-mark and will be considered low if at or below the given lo-mark. Whenever the state of the event changes (low to high or high to low), an event notification will be fired. When the analog reading is between the lo-mark and hi-mark, it will retain its previous value. This allows "hysteresis" to be built into the event so that a fluctuating signal will not cause an event to continuously fire. The thresholds are specified in 8-bit resolution, and thus they will be compared with the eight Most Significant Bits of the analog readings to determine when an event should be fired. The given hi-mark must be greater than the lo-mark.

Normally, the "initial state" (high or low) of the analog event definition is determined by the current level of the analog reading at the time the event definition is defined. However, if the current analog reading is between the lo-mark and hi-mark, an initial state cannot be accurately assigned. To deal with this, this method accepts a parameter that defines a default state to be used when the initial state cannot be determined. In all other situations (when the reading at the time of event definition is <= lo-mark or >= hi-mark) this parameter will simply be ignored.

Parameters

  • bank - Specifies the event bank (0 or 1).

  • channel - Specifies the logical channel (0-7).

  • lomark - Low threshold, 8 Most Significant Bits (0-255).

  • himark - High threshold, 8 Most Significant Bits (0-255).

  • defaultval - If the current reading is between lomark and himark, this specifies whether the event should be considered high or low to begin with. Otherwise, this parameter is ignored. This parameter is a Eth32AnalogEvtDef enumerator type, which has the following valid values:

    • Eth32AnalogEvtDef.Low - Consider the channel to be low

    • Eth32AnalogEvtDef.High - Consider the channel to be high

Return Value

This method does not return a value.

Remarks

Please note that defining the thresholds with this method does not enable the current connection to actually receive the event notifications when they occur. These must be enabled using the EnableEvent Method. Also note that the analog event thresholds are common to all connections. Changing the thresholds will affect other connections if they are utilizing that particular event.

Because the ETH32 device has two analog event banks, two events can be defined for each logical analog channel on the board. Applications can utilize both event banks independently to implement a number of different event notification schemes.

Example
Eth32 dev = new Eth32();
int lomark;
int himark;

try
{
	// .... Your code that establishes a connection here

	// .... Your code that sets up your event handler 
	// function goes here (or later)
	
	// Enable the Analog to Digital Converter
	dev.AnalogState=Eth32AnalogState.Enabled;
	
	// Configure logical channel 7 to read the physical channel 7 relative to ground (single-ended)
	// This is the power-on default anyway, but is shown here for completeness:
	dev.AnalogAssignment[7]=Eth32AnalogChannel.SE7;
	
	// Configure the analog voltage reference to be the internal 5V source
	dev.AnalogReference=Eth32AnalogReference.Internal;
	
	
	// Define an event that fires when channel 7 goes above 3.5V or 
	// falls below 3.0V.  Remember that the thresholds must be calculated 
	// knowing the voltage reference (in this case 5V).  They also must be 
	// converted to the 8 Most Significant Bits from 10-bit by dividing by 4.
	// If the current reading happens to be between the low and high threshold,
	// we will default to the event starting out low.
	lomark=(int)(3.0 / 5.0 * 1024 / 4);
	himark=(int)(3.5 / 5.0 * 1024 / 4);
	dev.SetAnalogEventDef(0, 7, lomark, himark, Eth32AnalogEvtDef.Low);

	// Now that an event is defined in bank 0, channel 7, enable receiving
	// events from it.
	// We'll give this event an arbitrary ID of 8000
	dev.EnableEvent(Eth32EventType.Analog, 0, 7, 8000);
	
	// You will now receive events when channel 7 crosses the threshold 
	// to being over 3.5V or crosses to under 3.0V.
}
catch (Eth32Exception e)
{
	// Handle Eth32 errors here
}
        
See Also

EnableEvent Method, GetAnalogEventDef Method, InputAnalog Method