using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Threading; namespace _87k_do_poweron_safe { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { cmbSlot.SelectedIndex = 3; } int iSlot; int iTotalCh; uint lDO_Value; private void GetTextValue() { iSlot = Convert.ToInt32(cmbSlot.Text); //Get slot lDO_Value = Convert.ToUInt32(txtValue.Text, 16); //Get DO Value iTotalCh = Convert.ToInt32(txtChannels.Text); //Get Total Channels } private void btnWrite_Click(object sender, EventArgs e) { GetTextValue(); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.WriteDO(hPort, iSlot, iTotalCh, lDO_Value); //Write DO value 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_Click(object sender, EventArgs e) //Clear DO { GetTextValue(); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.WriteDO(hPort, iSlot, iTotalCh, 0); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); txtValue.Text = "0"; } private void btnRead_Click(object sender, EventArgs e) { GetTextValue(); uint data = 0; IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.ReadDO(hPort, iSlot, iTotalCh, ref data); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); txtRead.Text = "ReadDO(HEX): " + data.ToString("x"); } private void btnWritePower_Click(object sender, EventArgs e) { GetTextValue(); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.WriteModulePowerOnValueDO(hPort, iSlot, iTotalCh, lDO_Value); 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 btnRefreshWDT_Click(object sender, EventArgs e) { GetTextValue(); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.RefreshModuleWDT(hPort, iSlot); 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 btnWriteSafe_Click(object sender, EventArgs e) { GetTextValue(); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.WriteModuleSafeValueDO(hPort, iSlot, iTotalCh, lDO_Value); 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 btnRestWDT_Click(object sender, EventArgs e) { GetTextValue(); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.ResetModuleWDT(hPort, iSlot); 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 btnCfgWDT_Click(object sender, EventArgs e) { GetTextValue(); int WTDTimeout = 0; WTDTimeout = Convert.ToInt32(txtbWTDTimeout.Text); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.SetModuleWDTConfig(hPort, iSlot, 1, WTDTimeout, 0); //87k module without WTDOverwrite 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 btnReadPower_Click(object sender, EventArgs e) { GetTextValue(); uint lValue = 0; IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.ReadModulePowerOnValueDO(hPort, iSlot, iTotalCh, ref lValue); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); txtRead.Text = "Read PowerOn ValueDO(HEX): " + lValue.ToString("x"); } private void btnReadSafe_Click(object sender, EventArgs e) { GetTextValue(); uint lValue = 0; IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.ReadModuleSafeValueDO(hPort, iSlot, iTotalCh, ref lValue); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); txtRead.Text = "Read Safe ValueDO(HEX): " + lValue.ToString("x"); } private void btnGetWDT_Click(object sender, EventArgs e) { GetTextValue(); int WTDOverwrite = 0; int WTDTimeout = 0; short ebStatus = 0; IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.GetModuleWDTConfig(hPort, iSlot, ref ebStatus, ref WTDTimeout, ref WTDOverwrite); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); txtbWTDTimeout.Text = WTDTimeout.ToString(); } private void button7_Click(object sender, EventArgs e) { GetTextValue(); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.WriteDO_MF(hPort, iSlot, iTotalCh, lDO_Value); //Write DO value 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 button5_Click(object sender, EventArgs e) { GetTextValue(); uint data = 0; IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.ReadDO_MF(hPort, iSlot, iTotalCh, ref data); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); txtRead.Text = "ReadDO(HEX): " + data.ToString("x"); } private void button6_Click(object sender, EventArgs e) { GetTextValue(); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.WriteDO_MF(hPort, iSlot, iTotalCh, 0); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); txtValue.Text = "0"; } private void button2_Click(object sender, EventArgs e) { GetTextValue(); uint lValue = 0; IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.ReadModulePowerOnValueDO_MF(hPort, iSlot, iTotalCh, ref lValue); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); txtRead.Text = "Read PowerOn ValueDO(HEX): " + lValue.ToString("x"); } private void button3_Click(object sender, EventArgs e) { GetTextValue(); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.WriteModulePowerOnValueDO_MF(hPort, iSlot, iTotalCh, lDO_Value); 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 button1_Click(object sender, EventArgs e) { GetTextValue(); uint lValue = 0; IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.ReadModuleSafeValueDO_MF(hPort, iSlot, iTotalCh, ref lValue); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); txtRead.Text = "Read Safe ValueDO(HEX): " + lValue.ToString("x"); } private void button4_Click(object sender, EventArgs e) { GetTextValue(); IntPtr hPort = PACNET.UART.Open(""); bool iRet = PACNET.PAC_IO.WriteModuleSafeValueDO_MF(hPort, iSlot, iTotalCh, lDO_Value); if (!iRet) { uint ec = PACNET.ErrHandling.GetLastError(); MessageBox.Show(((PACNET.ErrCode)ec).ToString() + "\nError Code: 0x" + ec.ToString("X")); } PACNET.UART.Close(hPort); } } }