using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using I8120PM_DotNET; namespace Demo1_CSharp { public partial class Form1 : Form { byte cSlot; public Form1() { InitializeComponent(); ComboBox_Slot.SelectedIndex = 0; cSlot = 0; } private void Form1_Closed(object sender, EventArgs e) { I8120PM.I8120PM_CloseModule(cSlot); } private void Button_GetFirmwareVer_Click(object sender, EventArgs e) { UInt32 Ret; Ret = I8120PM.I8120PM_GetFirmwareVersion(cSlot); MessageBox.Show("The I-8120PM Firmware version is " + Convert.ToString(Ret,16)); } private void Button_MasterID_Click(object sender, EventArgs e) { /* UInt32 MasterID; MasterID = I8124SDK.I8124_GetMasterMACID(cSlot); if (MasterID >= 64) { MessageBox.Show("Get Master ID Error(" + Convert.ToString(MasterID) + ")!"); return; } ComboBox_MasterID.SelectedIndex = Convert.ToInt32(MasterID); */ } private void Button_BaudRate_Click(object sender, EventArgs e) { byte BaudRate; BaudRate = 0; I8120PM.I8120PM_GetBaudRate(cSlot,ref BaudRate); if (BaudRate >= 3) { MessageBox.Show("Get Baud Rate Error(" + Convert.ToString(BaudRate) + ")!"); return; } ComboBox_BaudRate.SelectedIndex = Convert.ToInt32(BaudRate); } private void Button_SetBaudRate_Click(object sender, EventArgs e) { UInt32 BaudRate, Ret; BaudRate = Convert.ToByte(ComboBox_BaudRate.SelectedIndex); Ret = I8120PM.I8120PM_SetBaudRate(cSlot, Convert.ToByte(BaudRate)); if (Ret != 0) MessageBox.Show("Set BaudRate Error(" + Convert.ToString(Ret) + ")!"); else MessageBox.Show("Set BaudRate OK!"); } private void Button_ResetFirmware_Click(object sender, EventArgs e) { I8120PM.I8120PM_ResetFirmware(cSlot); } private void Button_SearchAllSlave_Click(object sender, EventArgs e) { /* UInt32 Ret; Ret = I8124SDK.I8124_SearchAllDevices(cSlot); if(Ret != 0) MessageBox.Show("Search All Slaves Error(" + Convert.ToString(Ret) + ")!"); else MessageBox.Show("Start to search all slave devices!\r\n Please wait for about 30 seconds!"); */ } private void Button_GetAllSlaveInfo_Click(object sender, EventArgs e) { /* UInt32 Ret; UInt16 i, TotalDevices = 0; UInt16[] DeviceInputLen = new UInt16[128]; UInt16[] DeviceOutputLen = new UInt16[128]; byte[] DesMACID = new byte[128]; byte[] Type = new byte[128]; String Str; Ret = I8124SDK.I8124_IsSearchOK(cSlot); if (Ret == 1055) //DNMXS_NowScanning { MessageBox.Show("I-8124 is still searching the slave devices! Please wait!"); return; } else if (Ret != 0) { MessageBox.Show("There is an error!(" + Convert.ToString(Ret) + ")!"); return; } Ret = I8124SDK.I8124_GetSearchedDevices(cSlot, ref TotalDevices, DesMACID, Type, DeviceInputLen, DeviceOutputLen); if (Ret != 0) { MessageBox.Show("There is an error!(" + Convert.ToString(Ret) + ")!"); return; } ListBox_AllSlave.Items.Add("Slave ID , I/O Type , InputLen , OutputLen"); for (i = 0; i < TotalDevices; i++) { switch (Type[i]) { case 0: //ConType_Explicit: ListBox_AllSlave.Items.Add(Convert.ToString(DesMACID[i]) + ", Explicit , 00 , 00"); break; case 1: //ConType_Poll: ListBox_AllSlave.Items.Add(Convert.ToString(DesMACID[i]) + ", Poll , " + Convert.ToString(DeviceInputLen[i]) + Convert.ToString(DeviceOutputLen[i])); break; case 2: //ConType_BitStrobe: ListBox_AllSlave.Items.Add(Convert.ToString(DesMACID[i]) + ", Strobe , " + Convert.ToString(DeviceInputLen[i]) + Convert.ToString(DeviceOutputLen[i])); break; case 3: //ConType_COS: ListBox_AllSlave.Items.Add(Convert.ToString(DesMACID[i]) + ", COS , " + Convert.ToString(DeviceInputLen[i]) + Convert.ToString(DeviceOutputLen[i])); break; case 4: //ConType_Cyclic: ListBox_AllSlave.Items.Add(Convert.ToString(DesMACID[i]) + ", Cyclic , " + Convert.ToString(DeviceInputLen[i]) + Convert.ToString(DeviceOutputLen[i])); break; } } * */ } private void button_Active_Click(object sender, EventArgs e) { cSlot = Convert.ToByte(ComboBox_Slot.SelectedIndex); I8120PM.I8120PM_ActiveModule(cSlot); } private void Button_GetPMID_Click(object sender, EventArgs e) { UInt32 i,Ret; byte PMIDCount; byte[] PMIDArray = new byte[255]; String Str; PMIDCount = 0; Ret = I8120PM.I8120PM_GetPMIDs(cSlot,ref PMIDCount,PMIDArray); if (Ret != 0) { MessageBox.Show("There is an error!(" + Convert.ToString(Ret) + ")!"); return; } TBox_PMID.Text = ""; for (i = 0; i < PMIDCount; i++) { if(i == (PMIDCount-1)) Str = String.Format("{0};",PMIDArray[i]); else Str = String.Format("{0},",PMIDArray[i]); TBox_PMID.Text += Str; } } private void Button_SetPMID_Click(object sender, EventArgs e) { UInt32 i, Ret; byte PMIDCount; byte[] PMIDArray = new byte[255]; String Str; PMIDCount = 6; PMIDArray[0] = 0; PMIDArray[1] = 1; PMIDArray[2] = 2; PMIDArray[3] = 3; PMIDArray[4] = 4; PMIDArray[5] = 5; Ret = I8120PM.I8120PM_SetPMIDs(cSlot, PMIDCount, PMIDArray); if (Ret != 0) { MessageBox.Show("There is an error!(" + Convert.ToString(Ret) + ")!"); } } } }