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 pac8088WNet; namespace pac_i8088W_Dotnet { public partial class Form1 : Form { private string[] slotStr = new string[8]; private int slotIndex; public Form1() { slotStr[0] = "Slot 0"; slotStr[1] = "Slot 1"; slotStr[2] = "Slot 2"; slotStr[3] = "Slot 3"; slotStr[4] = "Slot 4"; slotStr[5] = "Slot 5"; slotStr[6] = "Slot 6"; slotStr[7] = "Slot 7"; InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { for (int i = 0; i < 8; i++) { cboSlotIndex.Items.Add(slotStr[i]); } } private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); } private void cboSlotIndex_SelectedIndexChanged(object sender, EventArgs e) { if (pac8088W.Init(cboSlotIndex.SelectedIndex) == 0) { slotIndex = cboSlotIndex.SelectedIndex; txtLibVer.Text = String.Format("{0:X4}", pac8088W.LibVersion()); txtLibDate.Text = pac8088W.LibDate(); txtFirmware.Text =String.Format("{0:X4}", pac8088W.FirmwareVersion(slotIndex)); } else { slotIndex = -1; txtLibVer.Text = "-1"; txtLibDate.Text = "none"; txtFirmware.Text = "-1"; } } private void btnSyncStop_Click(object sender, EventArgs e) { pac8088W.Sync_Stop(slotIndex); } private void btnSyncStart_Click(object sender, EventArgs e) { pac8088W.Sync_Start(slotIndex); } private void UpdateHardwareTriggerState(object sender, EventArgs e) { ComboBox[] stateArr = new ComboBox[] { cboTrigState0, cboTrigState1, cboTrigState2, cboTrigState3, cboTrigState4, cboTrigState5, cboTrigState6, cboTrigState7 }; Int16 index = Int16.Parse(((ComboBox)sender).Tag.ToString()); int state = stateArr[index].SelectedIndex; pac8088W.SetHardwareTrigChannel(slotIndex, index, state); int readbackState = 0; pac8088W.GetHardwareTrigChannel(slotIndex, index, ref readbackState); stateArr[index].SelectedIndex = readbackState; } private void SetPWMDuty(object sender, EventArgs e) { UInt32 deci_hz = 0; UInt16 deci_duty = 0; TextBox[] hzArr = new TextBox[] { txtHz0, txtHz1, txtHz2, txtHz3, txtHz4, txtHz5, txtHz6, txtHz7 }; TextBox[] dutyArr = new TextBox[] { txtDuty0, txtDuty1, txtDuty2, txtDuty3, txtDuty4, txtDuty5, txtDuty6, txtDuty7 }; Int16 index = Int16.Parse(((Button)sender).Tag.ToString()); UInt32 hz = Convert.ToUInt32(hzArr[index].Text); UInt16 duty = Convert.ToUInt16(dutyArr[index].Text); pac8088W.SetPWMDuty(slotIndex, index, hz, duty); pac8088W.GetRealPWMDuty_Deci(slotIndex, index, ref deci_hz, ref deci_duty); hzArr[index].Text = (deci_hz / 10).ToString(); dutyArr[index].Text = (deci_duty / 10).ToString(); } private void SetCoutMode(object sender, EventArgs e) { ComboBox[] modeArr = new ComboBox[] { cboMode0, cboMode1, cboMode2, cboMode3, cboMode4, cboMode5, cboMode6, cboMode7 }; Int16 index = Int16.Parse(((ComboBox)sender).Tag.ToString()); int mode = modeArr[index].SelectedIndex; pac8088W.SetPWMCountMode(slotIndex, index, (byte)mode); } private void SetBurstCount(object sender, EventArgs e) { TextBox[] cntArr = new TextBox[] { txtCnt0, txtCnt1, txtCnt2, txtCnt3, txtCnt4, txtCnt5, txtCnt6, txtCnt7 }; Int16 index = Int16.Parse(((Button)sender).Tag.ToString()); UInt16 burstCnt = Convert.ToUInt16(cntArr[index].Text); pac8088W.SetBurstCount(slotIndex, index, burstCnt); } private void timer1_Tick(object sender, EventArgs e) { Int32 pwmStatus=0; Int32[] pwmBitArr= new Int32[8]; Label[] diArr = new Label[] { lbDI0, lbDI1, lbDI2, lbDI3, lbDI4, lbDI5, lbDI6, lbDI7 }; Label[] pwmArr = new Label[] { pwm0, pwm1, pwm2, pwm3, pwm4, pwm5, pwm6, pwm7 }; UInt16 diVal = 0; Int16[] diBit=new Int16[8] ; if (slotIndex != -1) { pac8088W.GetDI(slotIndex, ref diVal,ref diBit); pac8088W.GetPWMActiveState(slotIndex, ref pwmStatus, pwmBitArr); for (int i = 0; i < 8; i++) { if (pwmBitArr[i] == 1) pwmArr[i].Text = "ON"; else pwmArr[i].Text = "OFF"; } } } private void PWMStart(object sender, EventArgs e) { Int16 index = Int16.Parse(((Button)sender).Tag.ToString()); pac8088W.PWM_Start(slotIndex, index); } private void PWMStop(object sender, EventArgs e) { Int16 index = Int16.Parse(((Button)sender).Tag.ToString()); pac8088W.PWM_Stop(slotIndex, index); } } }