using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace _87k_do_poweron_safe { public partial class Form1 : Form { public Form1() { InitializeComponent(); } 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 Form1_Load(object sender, EventArgs e) { cmbSlot.SelectedIndex = 3; } private void btnClear_Click(object sender, EventArgs e) { 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 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 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 btnResetWDT_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 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 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 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 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 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 btnWrite_MF_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 btnRead_MF_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 btnClear_MF_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 btnReadPower_MF_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 btnWritePower_MF_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 btnReadSafe_MF_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 btnWriteSafe_MF_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); } } }