using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace _8k_87k_di { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnDIRead_Click(object sender, EventArgs e) { uint intbufer = 0; bool iRet; //Open default com port , default com port is com 1 IntPtr hPort = PACNET.UART.Open(""); //Get int state Slot data Int32 intSlot = Convert.ToInt32(cmbSlot.Text); //Read data iRet = PACNET.PAC_IO.ReadDI(hPort, intSlot, Convert.ToInt32(txtDIChannel.Text), ref intbufer); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } else { txtDIValue.Text = intbufer.ToString("x"); } PACNET.UART.Close(hPort); //Get int state Slot data intSlot = Convert.ToInt32(cmbSlot2.Text); //8k module have not using com port send data and use pac_ReadDI read data iRet = PACNET.PAC_IO.ReadDI((IntPtr)null, intSlot, Convert.ToInt32(txtDIChannel2.Text), ref intbufer); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } else { txtDIValue2.Text = intbufer.ToString("x"); } } private void btnDIRead_MF_Click(object sender, EventArgs e) { uint intbufer = 0; bool iRet; //Open default com port , default com port is com 1 IntPtr hPort = PACNET.UART.Open(""); //Get int state Slot data Int32 intSlot = Convert.ToInt32(cmbSlot.Text); //Read data iRet = PACNET.PAC_IO.ReadDI_MF(hPort, intSlot, Convert.ToInt32(txtDIChannel.Text), ref intbufer); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } else { txtDIValue.Text = intbufer.ToString("x"); } PACNET.UART.Close(hPort); //Get int state Slot data intSlot = Convert.ToInt32(cmbSlot2.Text); //8k module have not using com port send data and use pac_ReadDI read data iRet = PACNET.PAC_IO.ReadDI((IntPtr)null, intSlot, Convert.ToInt32(txtDIChannel2.Text), ref intbufer); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } else { txtDIValue2.Text = intbufer.ToString("x"); } } } }