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; using pac8093WNet; namespace pac_i8093W_Dotnet { public partial class Form1 : Form { private string[] typeStr = new string[3]; private string[] slotStr = new string[8]; private int slotIndex; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { cboMode.SelectedIndex = 0; cboSlotIndex.SelectedIndex = 0; } private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); } private void btnRead_Click(object sender, EventArgs e) { Int32 c_status = 0, ifEnableLatch = 0, latchedStatus=0; TextBox[] valText = new TextBox[] { txtCH00, txtCH01, txtCH02 }; TextBox[] enLatchText = new TextBox[] { txtEn0, txtEn1, txtEn2 }; TextBox[] latchStatusText = new TextBox[] { txtL0, txtL1, txtL2 }; TextBox[] zText = new TextBox[] { txtZ0, txtZ1, txtZ2 }; TextBox[] freqText = new TextBox[] { txtFreq0, txtFreq1, txtFreq2 }; Int32 lVal = 0; float freq = 0; int ch; for (ch = 0; ch < 3; ch++) { pac8093W.ReadEncoder(slotIndex, ch, ref lVal); valText[ch].Text = lVal.ToString(); pac8093W.ReadIndex(slotIndex, ch, ref c_status); zText[ch].Text = c_status.ToString(); pac8093W.GetIndexLatchStatus(slotIndex, ch, ref ifEnableLatch, ref latchedStatus); enLatchText[ch].Text = ifEnableLatch.ToString(); latchStatusText[ch].Text = latchedStatus.ToString(); pac8093W.ReadFreq(slotIndex, ch, ref freq); freqText[ch].Text = freq.ToString(); } } private void btnInit_Click(object sender, EventArgs e) { slotIndex = cboSlotIndex.SelectedIndex; pac8093W.Init(slotIndex); txtLibVer.Text = String.Format("{0:X4}", pac8093W.LibVersion()); txtLibDate.Text = pac8093W.LibDate(); txtFirmware.Text = String.Format("{0:X4}", pac8093W.FirmwareVersion(slotIndex)); GetChannelXOR(); } private void btnSetMode_Click(object sender, EventArgs e) { Int32 mode; mode = (Int16)(cboMode.SelectedIndex); int ch; for (ch = 0; ch < 3; ch++) { pac8093W.SetChannelMode(slotIndex, ch, mode); // for Demo to set all channels as same channel mode pac8093W.ResetEncoder(slotIndex, ch); } } private void btnReset_Click_1(object sender, EventArgs e) { for (int ch = 0; ch < 8; ch++) pac8093W.ResetEncoder(slotIndex, ch); } private void ckXOR0_CheckStateChanged(object sender, EventArgs e) { Int32 xor; if (ckXOR0.Checked == true) xor = 1; else xor = 0; pac8093W.SetXor(slotIndex, 0, xor); GetChannelXOR(); } private void ckXOR1_CheckStateChanged(object sender, EventArgs e) { Int32 xor; if (ckXOR1.Checked == true) xor = 1; else xor = 0; pac8093W.SetXor(slotIndex, 1, xor); GetChannelXOR(); } private void ckXOR2_CheckStateChanged(object sender, EventArgs e) { Int32 xor; if (ckXOR2.Checked == true) xor = 1; else xor = 0; pac8093W.SetXor(slotIndex, 2, xor); GetChannelXOR(); } private void GetChannelXOR() { int ch; CheckBox[] xorBox = new CheckBox[] { ckXOR0, ckXOR1, ckXOR2 }; Int32 xor = 0; for (ch = 0; ch < 3; ch++) { pac8093W.ReadXor(slotIndex, ch, ref xor); if (xor == 0) xorBox[ch].Checked = false; else xorBox[ch].Checked = true; } } private void SetPresetValue(object sender, EventArgs e) { TextBox[] valText = new TextBox[] { txtPreset0, txtPreset1, txtPreset2 }; Int16 index = Int16.Parse(((Button)sender).Tag.ToString()); pac8093W.SetPreset(slotIndex, index, Convert.ToInt32(valText[index].Text)); } private void SetLatchIndex(object sender, EventArgs e) { Int16 index = Int16.Parse(((CheckBox)sender).Tag.ToString()); } } }