using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Text; using System.Windows.Forms; namespace _8k_87k_dio { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Int32 intSlot = 0; byte byteSlot; private void btnWriteDO_Click_1(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); //Get byte state Slot data byteSlot = Convert.ToByte(cmbSlot.Text); //use pac_WriteDO write do data bool iRet = PACNET.PAC_IO.WriteDO(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); //Get int state Slot data intSlot = Convert.ToInt32(cmbSlot2.Text); //Get byte state Slot data byteSlot = Convert.ToByte(cmbSlot2.Text); //8k module have not using com port send data and use pac_WriteDO write do data iRet = PACNET.PAC_IO.WriteDO((IntPtr)null, intSlot, Convert.ToInt32(txtDOChannel2.Text), Convert.ToUInt32(txtDOValue2.Text, 16)); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } } private void btnClear_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(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")); } //Get int state Slot data intSlot = Convert.ToInt32(cmbSlot2.Text); //8k module have not using com port send data and Give DO '0' value to clear iRet = PACNET.PAC_IO.WriteDO((IntPtr)null, intSlot, Convert.ToInt16(txtDOChannel2.Text), 0); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } txtDOValue.Text = "0"; txtDOValue2.Text = "0"; } private void btnDIRead_Click(object sender, EventArgs e) { uint intbufer = 0; uint intdo = 0; //87k module must use com port to send data IntPtr hPort = PACNET.UART.Open(""); intSlot = Convert.ToInt32(cmbSlot.Text); //DIO module must use pac_ReadDIO to read di bool iRet = PACNET.PAC_IO.ReadDIO(hPort, intSlot, Convert.ToInt32(txtDIChannel.Text), Convert.ToInt32(txtDOChannel.Text), ref intbufer, ref intdo); 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); intSlot = Convert.ToInt32(cmbSlot2.Text); //8k module have not using com port send or read data,DIO module must use pac_ReadDIO to read di iRet = PACNET.PAC_IO.ReadDIO((IntPtr)null, intSlot, Convert.ToInt32(txtDIChannel2.Text), Convert.ToInt32(txtDOChannel2.Text), ref intbufer, ref intdo); 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 button3_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); //Get byte state Slot data byteSlot = Convert.ToByte(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); //Get int state Slot data intSlot = Convert.ToInt32(cmbSlot2.Text); //Get byte state Slot data byteSlot = Convert.ToByte(cmbSlot2.Text); //8k module have not using com port send data and use pac_WriteDO write do data iRet = PACNET.PAC_IO.WriteDO((IntPtr)null, intSlot, Convert.ToInt32(txtDOChannel2.Text), Convert.ToUInt32(txtDOValue2.Text, 16)); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } } private void button2_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")); } //Get int state Slot data intSlot = Convert.ToInt32(cmbSlot2.Text); //8k module have not using com port send data and Give DO '0' value to clear iRet = PACNET.PAC_IO.WriteDO((IntPtr)null, intSlot, Convert.ToInt16(txtDOChannel2.Text), 0); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } txtDOValue.Text = "0"; txtDOValue2.Text = "0"; } private void button1_Click(object sender, EventArgs e) { uint intbufer = 0; uint intdo = 0; //87k module must use com port to send data IntPtr hPort = PACNET.UART.Open(""); intSlot = Convert.ToInt32(cmbSlot.Text); //DIO module must use pac_ReadDIO to read di bool iRet = PACNET.PAC_IO.ReadDIO_MF(hPort, intSlot, Convert.ToInt32(txtDIChannel.Text), Convert.ToInt32(txtDOChannel.Text), ref intbufer, ref intdo); 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); intSlot = Convert.ToInt32(cmbSlot2.Text); //8k module have not using com port send or read data,DIO module must use pac_ReadDIO to read di iRet = PACNET.PAC_IO.ReadDIO((IntPtr)null, intSlot, Convert.ToInt32(txtDIChannel2.Text), Convert.ToInt32(txtDOChannel2.Text), ref intbufer, ref intdo); 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"); } } } }