using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; namespace _87K_ai { public partial class Form1 : Form { Label[] lbArr = new Label[10]; TextBox[] tbArr = new TextBox[10]; public Form1() { InitializeComponent(); for (int i = 0; i < 10; i++) { lbArr[i] = new Label(); tbArr[i] = new TextBox(); this.Controls.Add(lbArr[i]); this.Controls.Add(tbArr[i]); } } private void Form1_Load(object sender, EventArgs e) { cbbSlot.SelectedIndex = 0; cbbChannel.SelectedIndex = 0; radioButton1.Checked = true; //float, engineering format int total_ch = int.Parse(cbbChannel.Items[cbbChannel.SelectedIndex].ToString()); addItems2cbbSingleCh(total_ch); cbbSingleCh.SelectedIndex = 0; printTextBoxs(total_ch); } private void addItems2cbbSingleCh(int total_ch) { cbbSingleCh.Items.Clear(); for (int i = 0; i < total_ch; i++) { cbbSingleCh.Items.Add(i); } } private void printTextBoxs(int channel) { int x = 20; int y = 225; for (int i = 0; i < channel; i++) { //label locations: lbArr[i].Location = new Point(x + 120 * (i % 5), y + 40 * (i / 5)); lbArr[i].Size = new Size(50, 20); lbArr[i].Text = "CH_" + i.ToString("00"); lbArr[i].Visible = true; } for (int i = 0; i < channel; i++) { //textbox locations: x = 75; y = 225; tbArr[i].Location = new Point(x + 120 * (i % 5), y + 40 * (i / 5)); tbArr[i].Size = new Size(60, 25); tbArr[i].Text = ""; tbArr[i].Visible = true; } for (int j = channel; j < 10; j++) { lbArr[j].Visible = false; tbArr[j].Visible = false; } } private void button1_Click(object sender, EventArgs e) { int slot = cbbSlot.SelectedIndex + 1; int total_ch = int.Parse(cbbChannel.Items[cbbChannel.SelectedIndex].ToString()); int ch = int.Parse(cbbSingleCh.Items[cbbSingleCh.SelectedIndex].ToString()); float AI_fValue = 0; int AI_hValue = 0; IntPtr h = PACNET.UART.Open(""); if (radioButton1.Checked) { PACNET.PAC_IO.ReadAI(h, slot, ch, total_ch, ref AI_fValue); Thread.Sleep(10); textBox1.Text = AI_fValue.ToString(); } else { PACNET.PAC_IO.ReadAIHex(h, slot, ch, total_ch, ref AI_hValue); Thread.Sleep(10); textBox1.Text = AI_hValue.ToString("X"); } PACNET.UART.Close(h); } private void button2_Click(object sender, EventArgs e) { int slot = cbbSlot.SelectedIndex + 1; int total_ch = int.Parse(cbbChannel.Items[cbbChannel.SelectedIndex].ToString()); float[] AI_fArr = new float[10]; int[] AI_hArr = new int[10]; IntPtr h = PACNET.UART.Open(""); if (radioButton1.Checked) { PACNET.PAC_IO.ReadAIAll(h, slot, AI_fArr); for (int i = 0; i < total_ch; i++) tbArr[i].Text = AI_fArr[i].ToString(); } else { PACNET.PAC_IO.ReadAIAllHex(h, slot, AI_hArr); for (int i = 0; i < total_ch; i++) tbArr[i].Text = AI_hArr[i].ToString("X"); } PACNET.UART.Close(h); } private void cbbChannel_SelectedIndexChanged(object sender, EventArgs e) { int total_ch = int.Parse(cbbChannel.Items[cbbChannel.SelectedIndex].ToString()); printTextBoxs(total_ch); addItems2cbbSingleCh(total_ch); cbbSingleCh.SelectedIndex = 0; } } }