void EnableEvent(Eth32EventType eventtype, int port, int bit, int id)
This method enables reception of the specified event on this connection to the device. The ETH32 device only sends event notifications to those connections that specifically request them, so this method requests notification for the specified event from the device, as well as internally assigns the event an ID number provided by you.
eventtype - The type of event to enable. This parameter is a Eth32EventType enumerator type, which has the following valid values:
Eth32EventType.Digital - Digital I/O event. This includes port events and bit events.
Eth32EventType.Analog - Analog event based on thresholds defined with the SetAnalogEventDef Method.
Eth32EventType.CounterRollover - Counter rollover event, which occurs when the counter rolls over to zero.
Eth32EventType.CounterThreshold - Counter threshold event, which occurs when the counter passes a threshold defined with the CounterThreshold Property.
Eth32EventType.Heartbeat - Periodic event sent by the device to indicate the TCP/IP connection is still good.
port - For digital events, specifies the port number, for analog events, specifies the bank number, and for either counter event, specifies the counter number.
bit - For digital events, this should be -1 for port events or the bit number (0-7) for bit events. For analog events, this specifies the analog channel number (0-7).
id - You may specify any number to be associated with this event.
The id parameter allows you to assign any arbitrary number to this particular event. The ID you assign is included with the event information whenever this event fires. The idea is that you can identify a particular event with a single comparison rather than needing to inspect several pieces of data such as the event type, port number, and bit number. The ID number is completely arbitrary and multiple events may be given the same ID number if desired. The ID numbers are stored within the API and are not sent to the ETH32 device.
One other minor technicality is that the heartbeat event is permanently enabled on the ETH32 device itself for purposes of connection maintenance. Therefore, for the heartbeat event, this method simply enables the event within the API, meaning that when the event comes in, rather than being discarded it will be added to the event queue. The one small side-effect to this fact is that if you have enabled reception of the heartbeat event and another connection calls the ResetDevice Method, you will continue to receive heartbeat events, whereas all other event types will have been disabled on the device itself. Note that if you call ResetDevice on your own connection, it automatically disables the heartbeat event within the API for your connection, so in that case it is not an issue.
// This example is a very simple, yet complete (that is, compilable) example // of how to utilize events using System; using WinfordEthIO; public class MyExample { public static void MyEth32EventHandler(Object s, EventArgs e) { // This is our event handler function. This function // will be called every time an event notification arrives // from the device. See below in the Main() function for // how this function gets "registered" as the event handler. Eth32 sender; Eth32EventArgs args; sender = s as Eth32; if(sender == null) { // sender wasn't really an Eth32 object - quit return; } args = e as Eth32EventArgs; if(args == null) { // The arguments weren't really Eth32EventArgs - quit return; } System.Windows.Forms.MessageBox.Show("An event has fired. ID: " + args.event_info.id + " Value: " + args.event_info.val); } static void Main() { try { Eth32 dev; dev = new Eth32(); // NOTE: Substitute the IP address or DNS name of your device here. dev.Connect("192.168.1.100"); // Register our event handler function to handle all incoming events dev.HardwareEvent += new EventHandler(MyEth32EventHandler); // If there is a pushbutton connected between Port 0, bit 0 and ground, // then we can provide an internal pullup causing it to float high by // doing: dev.OutputBit(0, 0, 1); // Look for events on Port 0, bit 0. dev.EnableEvent(Eth32EventType.Digital, 0, 0, 100); // Display a MessageBox. This function will not return until the // user clicks OK, so it will keep the application running until then. System.Windows.Forms.MessageBox.Show("When you're finished monitoring events, " + "click OK to end application."); } catch (Eth32Exception e) { // Handle Eth32 errors here System.Windows.Forms.MessageBox.Show("Eth32 exception: " + e.ToString()); } } }