using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Text; using System.Windows.Forms; namespace _87k_dio_latch { public partial class Form1 : Form { uint DIValue; uint DIHighLatchValue; uint DILowLatchValue; uint DOValue; uint DOHighLatchValue; uint DOLowLatchValue; public Form1() { InitializeComponent(); //Set default value cmbDIChannel.SelectedIndex = 1;//DI total channel default is '8' cmbDOChannel.SelectedIndex = 1;//DO total channel default is '8' cmbSlot.SelectedIndex = 1; //Slot default is '1'; } private void btnReadDIOValue_Click(object sender, EventArgs e) { IntPtr hPort; int intSlot = Convert.ToInt16(cmbSlot.Text); int intDIChannel = Convert.ToInt16(cmbDIChannel.Text); int intDOChannel = Convert.ToInt16(cmbDOChannel.Text); //Open default com port , default com port is com 1 hPort = PACNET.UART.Open(""); DIValue = 0; DOValue = 0; //Read DI and DO data bool iRet = PACNET.PAC_IO.ReadDIO(hPort, intSlot, intDIChannel, intDOChannel, ref DIValue, ref DOValue); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } txtDIValue.Text = DIValue.ToString("X"); txtDOValue.Text = DOValue.ToString("X"); DILowLatchValue = 0; DOLowLatchValue = 0; //Read DI and DO low latch data iRet = PACNET.PAC_IO.ReadDIOLatch(hPort, intSlot, intDIChannel, intDOChannel, 0, ref DILowLatchValue, ref DOLowLatchValue); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } txtDILowValue.Text = DILowLatchValue.ToString("X"); txtDOLowValu.Text = DOLowLatchValue.ToString("X"); DIHighLatchValue = 0; DOHighLatchValue = 0; //Read DI and DO high latch data iRet = PACNET.PAC_IO.ReadDIOLatch(hPort, intSlot, intDIChannel, intDOChannel, 1, ref DIHighLatchValue, ref DOHighLatchValue); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } txtDIHighValue.Text = DIHighLatchValue.ToString("X"); txtDOHighValue.Text = DOHighLatchValue.ToString("X"); PACNET.UART.Close(hPort); } private void btnClear_Click(object sender, EventArgs e) { int intSlot = Convert.ToInt16(cmbSlot.Text); int intChannel = Convert.ToInt16(cmbDOChannel.Text); //Open default com port , default com port is com 1 IntPtr hPort = PACNET.UART.Open(""); //Clear DI and DO latch bool iRet = PACNET.PAC_IO.ClearDIOLatch(hPort, intSlot); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } //Set DO data be '0' to clear txtDILowValue.Text = "0"; txtDIHighValue.Text = "0"; txtDOHighValue.Text = "0"; txtDOLowValu.Text = "0"; PACNET.UART.Close(hPort); } private void btnWriteDo_Click(object sender, EventArgs e) { int intSlot = Convert.ToInt16(cmbSlot.Text); int intChannel = Convert.ToInt16(cmbDOChannel.Text); bool iRet; IntPtr hPort = PACNET.UART.Open(""); iRet=PACNET.PAC_IO.WriteDO(hPort, intSlot, intChannel, Convert.ToUInt32(txtDOWriteValue.Text,16)); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); } } }