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 { // One and only Device: UInt32 Status = 0; Int32 NumCards = 0; // We will only handle one card public Int32 CardNum = 0; // new dirver uses card number public UInt32 Channels = 8; // num channels on the card bool RunFlag; public bool TimerEnabled = false; public UInt32[] value = new UInt32[] { 0, 0, 0 }; // 3 values used for read write public int i = 0; // just for demo purposes its incremented every loop never reset or wraps public struct TCardData { public bool IsValid; public bool IsSelected; public UInt32 DeviceID; public UInt32 Base; // This the result of findcards and the base address of the card }; public TCardData CardData; // only set up for one card here // 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 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) //Driver Call this is an absolute address no relative address function { 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"); } textBoxStatus.Text = "This sample outputs a walking bit on Port A of the selected group. It then reads back the value from Port A. This should be identical to the output value due to on-chip readback. It also displays the Input from Port B."; // This will get all the card info: // Note; We only need to confirm the index of the card which should be 0 with no address offset needed 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 this has a 55ms min resolution: myTimer.Interval = 1000; // sec } private void Form1_Load(object sender, EventArgs e) { } private void FindCardsWDM() { bool found = false; char[] AddStr = new char[256]; // Vars for QueryCardInfo() : UInt32 DeviceID, Base; UInt32 NameSize = 256; UInt16[] Name = new UInt16[256]; String strname; // Init: RunFlag = true; // 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"; textBoxStatus.Text = "No cards were found!"; textBoxStatus.Text += "This may mean the card is not installed. "; textBoxStatus.Text += "Check Device Manager for a card and its status"; textBoxStatus.Text += "You may consider rebooting your system."; RunFlag = false; } else { // Loop through the cards and validate and store card data: for (CardNum = 0; CardNum != NumCards; CardNum++) { // This geta all the card info were only going to use DeviceID: Status = AIOWDM.QueryCardInfo(CardNum, out DeviceID, out Base, out NameSize, out strname); CardData.DeviceID = DeviceID; CardData.Base = Base; // Populate display with card found set channels flags: switch (DeviceID) { case 0x0F00: labelCardName.Text = "PCI-IIRO-8 Digital Input/Relay Output Card"; CardData.IsValid = true; Channels = 8; found = true; break; case 0x0F08: labelCardName.Text = "PCI-IIRO-16 Digital Input/Relay Output Card"; CardData.IsValid = true; Channels = 16; found = true; break; case 0x0DC8: labelCardName.Text = "PCI-IDIO-16 Solid-State Input/Output Card"; CardData.IsValid = true; Channels = 16; found = true; break; case 0x0F02: labelCardName.Text = "PCIe-IIRO-8 Digital Input/Relay Output Card"; CardData.IsValid = true; Channels = 8; found = true; break; case 0x0F09: labelCardName.Text = "PCIe-IIRO-16 Digital Input/Relay Output Card"; CardData.IsValid = true; Channels = 16; found = true; break; default: break; } }// end loop on validate present card(s) }//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."; textBoxStatus.Text = "No valid card was found!"; textBoxStatus.Text += "This may mean the card is not installed. "; textBoxStatus.Text += "Check Device Manager for a card and its status"; textBoxStatus.Text += "You may consider rebooting your system."; RunFlag = false; } //comboBoxPort.SelectedIndex = 0; if (RunFlag) { // This is the result: CardData.IsSelected = true; } } private void TimerEventProcessor(Object myObject, EventArgs myEventArgs) { // This is the method that runs when the timer event is raised: myTimer.Stop(); UpdateGUIState(); myTimer.Enabled = true; } private void UpdateGUIState() { // This is the walking bit for the board and display: // We use 8 or 16 bits but pass a 16 bit value in case we get an AA55 error returned: int Status; int j; char[] msg = new char[] { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' }; StringBuilder s2 = new StringBuilder(); StringBuilder s3 = new StringBuilder(); StringBuilder s4 = new StringBuilder(); value[0] = (UInt32)(1 << i++); UInt32 Offset = 0; // For this card there is no base address offset // Driver Calls: Status = AIOWDM.RelOutPortB(CardNum - 1, Offset, (Byte)value[0]); //write a byte value[1] = AIOWDM.RelInPortB(CardNum - 1, Offset); //read a byte into ushort value[2] = AIOWDM.RelInPortB(CardNum - 1, Offset + 1); // read a byte into ushort if( Channels > 8) { Status = AIOWDM.RelOutPortB(CardNum - 1, Offset + 4, (Byte)(value[0] >> 8)); // Driver Calls //write a byte value[1] = value[1] + (UInt32)(AIOWDM.RelInPortB(CardNum - 1, Offset + 4) << 8); //read a byte into byte value[2] = value[2] + (UInt32)(AIOWDM.RelInPortB(CardNum - 1, Offset + 4 + 1) << 8); // read a byte into byte } //i++; i %= (int)Channels; for (j=0; j