using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace _87K_dio { public partial class Form1 : Form { bool iRet; int intSlot = 0; public Form1() { InitializeComponent(); cmbSlot.SelectedIndex = 1; } private void btnWriteDO_Click(object sender, EventArgs e) { IntPtr hPort; //Open default com port , default com port is com 1 hPort = PACNET.UART.Open(""); //Get slot data intSlot = Convert.ToInt16(cmbSlot.Text); //Write data iRet = PACNET.PAC_IO.WriteDO(hPort, intSlot, Convert.ToInt16(txtDOChannel.Text), Convert.ToUInt32(txtDOValue.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); } private void btnClearDO_Click(object sender, EventArgs e) { IntPtr hPort; hPort = PACNET.UART.Open(""); intSlot = Convert.ToInt16(cmbSlot.Text); //Set DO data be '0' to clear iRet = PACNET.PAC_IO.WriteDO(hPort, intSlot, Convert.ToInt16(txtDOChannel.Text), 0); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } else txtDOValue.Text = "0"; PACNET.UART.Close(hPort); } private void btnReadDI_Click(object sender, EventArgs e) { IntPtr hPort; uint IDIValue = 0; uint IDOValue = 0; //Get slot data intSlot = Convert.ToInt32(cmbSlot.Text); //Open default com port , default com port is com 1 hPort = PACNET.UART.Open(""); //Read data iRet = PACNET.PAC_IO.ReadDIO(hPort, intSlot, Convert.ToInt16(txtDIChannel.Text), Convert.ToInt16(txtDOChannel.Text), ref IDIValue, ref IDOValue); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } else txtDIValue.Text = Convert.ToString(IDIValue, 16); PACNET.UART.Close(hPort); } private void btnReadDI_MF_Click(object sender, EventArgs e) { IntPtr hPort; uint IDIValue = 0; uint IDOValue = 0; //Get slot data intSlot = Convert.ToInt32(cmbSlot.Text); //Open default com port , default com port is com 1 hPort = PACNET.UART.Open(""); //Read data iRet = PACNET.PAC_IO.ReadDIO_MF(hPort, intSlot, Convert.ToInt16(txtDIChannel.Text), Convert.ToInt16(txtDOChannel.Text), ref IDIValue, ref IDOValue); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } else txtDIValue.Text = Convert.ToString(IDIValue, 16); PACNET.UART.Close(hPort); } private void btnWriteDO_MF_Click(object sender, EventArgs e) { //87k module must use com port to send data IntPtr hPort = PACNET.UART.Open(""); //Get int state Slot data intSlot = Convert.ToInt32(cmbSlot.Text); //use pac_WriteDO write do data bool iRet = PACNET.PAC_IO.WriteDO_MF(hPort, intSlot, Convert.ToInt32(txtDOChannel.Text), Convert.ToUInt32(txtDOValue.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); } private void btnClear_DOMF_Click(object sender, EventArgs e) { //87k module must use com port to send data IntPtr hPort = PACNET.UART.Open(""); //Get int state Slot data intSlot = Convert.ToInt32(cmbSlot.Text); bool iRet = PACNET.PAC_IO.WriteDO_MF(hPort, intSlot, Convert.ToInt16(txtDOChannel.Text), 0); PACNET.UART.Close(hPort); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } txtDOValue.Text = "0"; } } }