using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace _8K_di { public partial class Form1 : Form { const int ORIGIN_X = 20; const int ORIGIN_Y = 20; const int LABEL_WIDTH = 50; const int LABEL_HEIGHT = 20; const int GAP_LABEL_CIRCLE = 5; const int DIAMETER = LABEL_WIDTH; const int GAP_HORIZONTAL = 5; const int GAP_VERTICAL = 10; Label[] lbChName = new Label[32]; uint diValue; public Form1() { InitializeComponent(); for (int i = 0; i < 32; i++) { lbChName[i] = new Label(); lbChName[i].Size = new Size(LABEL_WIDTH, LABEL_HEIGHT); lbChName[i].Location = new Point( ORIGIN_X + (DIAMETER + GAP_HORIZONTAL) * (i % 8), ORIGIN_Y + (LABEL_HEIGHT + GAP_LABEL_CIRCLE + DIAMETER + GAP_VERTICAL) * (i / 8) ); lbChName[i].Text = "CH_" + i.ToString(); this.panel1.Controls.Add(lbChName[i]); } } private void Form1_Load(object sender, EventArgs e) { cbbSlot.SelectedIndex = 0; cbbChannel.SelectedIndex = 0; } private void cbbChannel_SelectedIndexChanged(object sender, EventArgs e) { int total_ch = int.Parse(cbbChannel.Items[cbbChannel.SelectedIndex].ToString()); for (int i = 0; i < 32; i++) { if (i < total_ch) lbChName[i].Visible = true; else lbChName[i].Visible = false; } panel1.Refresh(); } private void button1_Click(object sender, EventArgs e) { int slot = cbbSlot.SelectedIndex + 1; int total_ch = int.Parse(cbbChannel.Items[cbbChannel.SelectedIndex].ToString()); diValue = 0; //Read 8K di value PACNET.PAC_IO.ReadDI((IntPtr)null, slot, total_ch, ref diValue); textBox1.Text = diValue.ToString(); panel1.Refresh(); } private void panel1_Paint(object sender, PaintEventArgs e) { int total_ch = int.Parse(cbbChannel.Items[cbbChannel.SelectedIndex].ToString()); Brush bs; Pen p = new Pen(Color.Black); Brush black = new SolidBrush(Color.Black); Brush red = new SolidBrush(Color.Red); bs = black; for (int i = 0; i < total_ch; i++) { if (PACNET.PAC_IO.GetBit(int.Parse(diValue.ToString()), i)) bs = red; else bs = black; e.Graphics.FillEllipse( bs, ORIGIN_X + (DIAMETER + GAP_HORIZONTAL) * (i % 8), ORIGIN_Y + LABEL_HEIGHT + GAP_LABEL_CIRCLE + (LABEL_HEIGHT + GAP_LABEL_CIRCLE + DIAMETER + GAP_VERTICAL) * (i / 8), DIAMETER, DIAMETER ); } } } }