using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using AIOWDMNet; // the namespace exposes the AIOWDM Class interface namespace DIO { public partial class Form1 : Form { UInt32 Status = 0; // Data used to discover cards in the system: const UInt32 MAX_CARDS = 10; public Int32 NumCards = 0; // This is the basic data that we will be using to interface with the card: public Int32 CardNum = 0; // The index of the one card we will be using 0 public UInt32 Offset = 0; // This the offset that will be used based on the base address of the card public bool RunFlag = false; public int i = 0; // This will hold the data for the card installed in the system: public struct TCardData { public bool IsValid; public bool IsSelected; public UInt32 DeviceID; public UInt32 Base; // This a result of findcards and the base address of the card }; public TCardData CardData; // only one struct // WDG sample specific : UInt32 State; UInt32 Loop; // Interval Timer fou GUI update: // (Note: A Windows Forms timer designed for single threaded environments not a System Timer 55 ms min res) static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer(); public Form1() { InitializeComponent(); // Initialize default values: // Ping the driver AIOWDM.SYS: // This takes an absolute sddress not relative offset // This is the one place we actual might use all 16 bits returned for an error code AA55 // otherwise we only use an 8 bit byte of data per read and write: if (AIOWDM.InPortB(0x61) == 0xAA55) { MessageBox.Show(" AIOWDM.SYS not detected.\n Please copy AIOWDM.SYS into [Windows]/system32/drivers and re-run this sample.\n Ensure that a board is installed properly.", "Warning"); } // This will get all the card info: FindCardsWDM(); // Add the event and the event handler for the method that will // process the timer event to the timer: myTimer.Tick += new EventHandler(TimerEventProcessor); // Set the timer interval in miliseconds and start 55ms min resolution: myTimer.Interval = 60; } private void Form1_Load(object sender, EventArgs e) { } private void FindCardsWDM() { bool found = false; // Local Vars for QueryCardInfo(): UInt32 DeviceID, Base; UInt32 NameSize = 256; UInt16[] Name = new UInt16[256]; String strname; // Set CardData to 0 as needed: CardData.IsValid = false; CardData.IsSelected = false; CardData.DeviceID = 0; CardData.Base = 0; // Get the total number of cards installed: NumCards = AIOWDM.GetNumCards(); if (NumCards == 0) // no cards present { labelCardName.Text = "No Card Found"; RunFlag = false; } else { // Validate and store card data: Status = AIOWDM.QueryCardInfo(CardNum, out DeviceID, out Base, out NameSize, out strname); // Populate list box with addresse offsets found set flags: switch (DeviceID) { case 0x22C0: labelCardName.Text = "PCI-WDG-CSM Watchdog Card"; CardData.IsValid = true; CardData.DeviceID = DeviceID; CardData.Base = Base; found = true; break; default: break; }// end switch }//end else card present // If card(s) are present but no valid cards were found: if ((NumCards != 0) && (found == false) ) { labelCardName.Text = "No Valid Card Found."; RunFlag = false; } if (RunFlag) { // This is the result setting the active address offset to be used: Offset = 0; //default to first valid base offset (Port 0) CardData.IsSelected = true; } } private void TimerEventProcessor(Object myObject, EventArgs myEventArgs) { // This is the method that runs when the timer event is raised: UpdateState(); } private void UpdateState() { // This is a test sample: ushort readback; readback = AIOWDM.RelInPortB(CardNum, Offset + 4); lblBase4.Text = readback.ToString("X"); if( (readback & 1) == 1) checkBox1.Checked = true; if ((readback & 2) == 2) checkBox2.Checked = true; if ((readback & 4) == 4) checkBox3.Checked = true; if ((readback & 8) == 8) checkBox4.Checked = true; if ((readback & 16) == 16) checkBox5.Checked = true; if ((readback & 32) == 32) checkBox6.Checked = true; if ((readback & 64) == 64) checkBox7.Checked = true; if ((readback & 128) == 128) checkBox8.Checked = true; readback = AIOWDM.RelInPortB(CardNum, Offset + 5); lblBase5.Text = readback.ToString("X"); double dTemp = (readback * (11.0 / 15.0) ) + 7.0; // Temperature is simply ((BASE+5) * 11/15) + 7 lblTemperature.Text = dTemp.ToString("F"); } private void btnExit_Click(object sender, EventArgs e) { // Right now this is only called on button click not window close ALtF4 etc: // Kill the timer: myTimer.Stop(); myTimer.Enabled = false; myTimer.Dispose(); // Close the form and Application: this.Close(); } private void btnTest_Click(object sender, EventArgs e) { if (myTimer.Enabled) { State = Loop = 0; myTimer.Enabled = false; myTimer.Stop(); btnTest.Text = "Test"; } else { State = Loop = 0; myTimer.Enabled = true; btnTest.Text = "Abort"; } } } }