using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using I87124_CSharp_CE6; namespace Demo1_CSharp { public partial class Form1 : Form { public Form1() { InitializeComponent(); I87124SDK.I87124_ActiveModule(); ComboBox_Slot.SelectedIndex = 0; } private void Form1_Closed(object sender, EventArgs e) { I87124SDK.I87124_CloseModule(); } private void Button_GetFirmwareVer_Click(object sender, EventArgs e) { UInt32 Ret; Ret = I87124SDK.I87124_GetFirmwareVersion(Convert.ToByte(ComboBox_Slot.SelectedIndex)); MessageBox.Show("The I-87124 Firmware version is " + Convert.ToString(Ret,16)); } private void Button_MasterID_Click(object sender, EventArgs e) { UInt32 MasterID; MasterID = I87124SDK.I87124_GetMasterMACID(Convert.ToByte(ComboBox_Slot.SelectedIndex)); if (MasterID >= 64) { MessageBox.Show("Get Master ID Error(" + Convert.ToString(MasterID) + ")!"); return; } ComboBox_MasterID.SelectedIndex = Convert.ToInt32(MasterID); } private void Button_SetMasterID_Click(object sender, EventArgs e) { UInt32 MasterID,Ret; MasterID = Convert.ToByte(ComboBox_MasterID.SelectedIndex); Ret = I87124SDK.I87124_SetMasterMACID(Convert.ToByte(ComboBox_Slot.SelectedIndex), Convert.ToByte(MasterID)); if (Ret != 0) MessageBox.Show("Set Master ID Error(" + Convert.ToString(Ret) + ")!"); else MessageBox.Show("Set Master ID OK!"); } private void Button_BaudRate_Click(object sender, EventArgs e) { UInt32 BaudRate; BaudRate = I87124SDK.I87124_GetBaudRate(Convert.ToByte(ComboBox_Slot.SelectedIndex)); 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 = I87124SDK.I87124_SetBaudRate(Convert.ToByte(ComboBox_Slot.SelectedIndex), 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) { I87124SDK.I87124_ResetFirmware(Convert.ToByte(ComboBox_Slot.SelectedIndex)); } byte DOData1,DOData2 = 0, DOData3 = 0; private void timer1_Tick(object sender, EventArgs e) { ushort IOLen,i; byte[] IOData; ulong Ret; string Str; IOData = new byte[512]; IOLen = 0; Ret = I87124SDK.I87124_ReadInputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 30, 1, ref IOLen, IOData); if (Ret != 0) Str = "Error! : " + Ret.ToString(); else { Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; } Label_30In.Text = Str; Ret = I87124SDK.I87124_GetMasterStatus(Convert.ToByte(ComboBox_Slot.SelectedIndex)); Str = "Master Status : " + Ret.ToString(); Label_Status.Text = Str; } private void button1_Click(object sender, EventArgs e) { I87124SDK.I87124_StartAllDevice(Convert.ToByte(ComboBox_Slot.SelectedIndex)); timer1.Enabled = true; timer2.Enabled = true; timer3.Enabled = true; timer4.Enabled = true; timer5.Enabled = true; timer6.Enabled = true; timer7.Enabled = true; timer8.Enabled = true; } private void timer2_Tick(object sender, EventArgs e) { ushort IOLen, i; byte[] IOData; ulong Ret; string Str; IOData = new byte[512]; IOLen = 0; Ret = I87124SDK.I87124_ReadInputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 32, 1, ref IOLen, IOData); if (Ret != 0) Str = "Error! : " + Ret.ToString(); else { Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; } Label_32In.Text = Str; IOData[0] = DOData2; IOData[1] = DOData2; DOData2 = (byte)((DOData2 + 1) % 0xFF); I87124SDK.I87124_WriteOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 32, 1, 2, IOData); Ret = I87124SDK.I87124_ReadbackOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 32, 1, ref IOLen, IOData); if (Ret != 0) Str = "Error! : " + Ret.ToString(); else { Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; } Label_32Out.Text = Str; } private void timer3_Tick(object sender, EventArgs e) { ushort IOLen, i; byte[] IOData; ulong Ret; string Str; IOData = new byte[512]; IOLen = 0; Ret = I87124SDK.I87124_ReadInputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 53, 1, ref IOLen, IOData); if (Ret != 0) Str = "Error! : " + Ret.ToString(); else { Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; } Label_53In.Text = Str; IOData[0] = DOData3; IOData[1] = DOData3; DOData3 = (byte)((DOData3 + 1) % 0xFF); I87124SDK.I87124_WriteOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 53, 1, 2, IOData); Ret = I87124SDK.I87124_ReadbackOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 53, 1, ref IOLen, IOData); if (Ret != 0) Str = "Error! : " + Ret.ToString(); else { Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; } Label_53Out.Text = Str; } private void timer4_Tick(object sender, EventArgs e) { ushort IOLen, i; byte[] IOData; string Str; ulong Ret; IOData = new byte[512]; IOLen = 0; Ret = I87124SDK.I87124_ReadInputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 31, 1, ref IOLen, IOData); if (Ret != 0) Str = "0"; else { Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; } Label_31In.Text = Str; IOData[0] = DOData1; IOData[1] = DOData1; IOData[2] = DOData1; IOData[3] = DOData1; DOData1 = (byte)((DOData1 + 1) % 0xFF); I87124SDK.I87124_WriteOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 31, 1, 4, IOData); Ret = I87124SDK.I87124_ReadbackOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 31, 1, ref IOLen, IOData); if (Ret != 0) Str = "Error! : " + Ret.ToString(); else { Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; } Label_31Out.Text = Str; } private void timer5_Tick(object sender, EventArgs e) { ushort IOLen, i; byte[] IOData; ulong Ret; string Str; IOData = new byte[512]; IOLen = 0; I87124SDK.I87124_ReadInputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 30, 1, ref IOLen, IOData); Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; Label_30In.Text = Str; Ret = I87124SDK.I87124_GetMasterStatus(Convert.ToByte(ComboBox_Slot.SelectedIndex)); Str = "Master Status : " + Ret.ToString(); Label_Status.Text = Str; } private void timer6_Tick(object sender, EventArgs e) { ushort IOLen, i; byte[] IOData; string Str; IOData = new byte[512]; IOLen = 0; I87124SDK.I87124_ReadInputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 32, 1, ref IOLen, IOData); Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; Label_32In.Text = Str; IOData[0] = DOData2; IOData[1] = DOData2; DOData2 = (byte)((DOData2 + 1) % 0xFF); I87124SDK.I87124_WriteOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 32, 1, 2, IOData); I87124SDK.I87124_ReadbackOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 32, 1, ref IOLen, IOData); Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; Label_32Out.Text = Str; } private void timer7_Tick(object sender, EventArgs e) { ushort IOLen, i; byte[] IOData; string Str; IOData = new byte[512]; IOLen = 0; I87124SDK.I87124_ReadInputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 53, 1, ref IOLen, IOData); Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; Label_53In.Text = Str; IOData[0] = DOData3; IOData[1] = DOData3; DOData3 = (byte)((DOData3 + 1) % 0xFF); I87124SDK.I87124_WriteOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 53, 1, 2, IOData); I87124SDK.I87124_ReadbackOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 53, 1, ref IOLen, IOData); Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; Label_53Out.Text = Str; } private void timer8_Tick(object sender, EventArgs e) { ushort IOLen, i; byte[] IOData; string Str; IOData = new byte[512]; IOLen = 0; I87124SDK.I87124_ReadInputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 31, 1, ref IOLen, IOData); Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; Label_31In.Text = Str; IOData[0] = DOData1; IOData[1] = DOData1; IOData[2] = DOData1; IOData[3] = DOData1; DOData1 = (byte)((DOData1 + 1) % 0xFF); I87124SDK.I87124_WriteOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 31, 1, 4, IOData); I87124SDK.I87124_ReadbackOutputData(Convert.ToByte(ComboBox_Slot.SelectedIndex), 31, 1, ref IOLen, IOData); Str = ""; for (i = 0; i < IOLen; i++) Str += IOData[i].ToString() + ","; Label_31Out.Text = Str; } } }