using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Text; using System.Windows.Forms; namespace _7k_do { public partial class Form1 : Form { IntPtr hPort; public Form1() { InitializeComponent(); cmbComPort.SelectedIndex = 0; } private void btnOpenCom_Click(object sender, EventArgs e) { //Open com port hPort = PACNET.UART.Open("COM" + cmbComPort.Text + "," + txtBaudRate.Text); if (hPort == (IntPtr)(-1)) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } else { btnCloseCom.Enabled = true; btnOpenCom.Enabled = false; } } private void btnCloseCom_Click(object sender, EventArgs e) { //Close com port PACNET.UART.Close(hPort); btnOpenCom.Enabled = true; btnCloseCom.Enabled = false; } private void btnWriteDO_Click(object sender, EventArgs e) { bool iRet; //Write DO data iRet = PACNET.PAC_IO.WriteDO(hPort, PACNET.PAC_IO.PAC_REMOTE_IO(Convert.ToInt16(txtAddress.Text)), Convert.ToInt16(txtChannel.Text), Convert.ToUInt32(txtWriteData.Text,16)); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } } private void button1_Click(object sender, EventArgs e) { bool iRet; //Write DO data iRet = PACNET.PAC_IO.WriteDO_MF(hPort, PACNET.PAC_IO.PAC_REMOTE_IO(Convert.ToInt16(txtAddress.Text)), Convert.ToInt16(txtChannel.Text), Convert.ToUInt32(txtWriteData.Text, 16)); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } } } }