private string SetPWMStart() { string returnString; //returnString = mEM9636B.SetIOPinsDirection(EM9636_IO_DIRECTION.OUT, EM9636_IO_SELECTION.IO1_16); //if (!string.IsNullOrEmpty(returnString)) //{ // return returnString; //} returnString = EM9636B.GetInstance().SetPWMParameter((byte)numPWMChannel.Value, (int)numPWMFrequency.Value, (int)numPWMDuty.Value); if (string.IsNullOrEmpty(returnString)) { bool isChannelOne = ((byte)numPWMChannel.Value == 1); bool isChannelTwo = ((byte)numPWMChannel.Value == 2); bool isChannelThree = ((byte)numPWMChannel.Value == 3); //returnString = mEM9636B.SetPWMEnable(isChannelOne, isChannelTwo, isChannelThree); returnString = EM9636B.GetInstance().SetPWMEnable(true, true, true); if (string.IsNullOrEmpty(returnString)) { return(string.Empty); } } return(returnString); }
private string SetDIO() { byte index = (byte)(1 << mDAQIndex); string returnString; byte tempValue; if (mDIOChecks[mDAQIndex].Checked) { tempValue = (byte)(mIO1_8Status | index); } else { tempValue = (byte)(mIO1_8Status & (~index)); } returnString = EM9636B.GetInstance().SetIO1_16(tempValue, 0); if (!string.IsNullOrEmpty(returnString)) { return(returnString); } else { mIO1_8Status = tempValue; return(string.Empty); } }
private void RefreshIODisplay() { byte status = mDIStatus; byte index = 0x01; if (EM9636B.GetInstance().IsConnect) { EM9636B.GetInstance().GetIO1_16(out mIO1_8Status, out mIO9_16Status); status = mIO1_8Status; for (int i = 0; i < 8; i++) { if ((status & index) == index) { mDIOLabels[i].Text = "ON"; mDIOLabels[i].BackColor = Color.Green; if (rdbIOOut.Checked) { mDIOChecks[i].Checked = true; } } else { mDIOLabels[i].Text = "OFF"; mDIOLabels[i].BackColor = Color.Red; if (rdbIOOut.Checked) { mDIOChecks[i].Checked = false; } } index = (byte)(index << 1); } } }
private void RefreshDIDisplay() { byte status = mDIStatus; byte index = 0x01; if (EM9636B.GetInstance().IsConnect) { EM9636B.GetInstance().GetDIO(out mDOStatus, out mDIStatus); status = mDIStatus; for (int i = 0; i < 8; i++) { if ((status & index) == index) { mDILabels[i].Text = "ON"; mDILabels[i].BackColor = Color.Green; } else { mDILabels[i].Text = "OFF"; mDILabels[i].BackColor = Color.Red; } index = (byte)(index << 1); } } }
public static EM9636B GetInstance() { if (null == mSingletonEM9636B) { mSingletonEM9636B = new EM9636B(); } return(mSingletonEM9636B); }
private string SetPWMStop() { string returnString = EM9636B.GetInstance().SetPWMEnable(false, false, false); if (string.IsNullOrEmpty(returnString)) { return(string.Empty); } return(returnString); }
private void mTimer_Elapsed(object sender, EventArgs e) { mTimer.Stop(); try { if (mEvent == DAQEvent.NA) { RefreshDIDisplay(); RefreshIODisplay(); } else { string returnString = string.Empty; if (mEvent == DAQEvent.SetDO) { returnString = SetDO(); } else if (mEvent == DAQEvent.SetDIO) { returnString = SetDIO(); } else if (mEvent == DAQEvent.SetPWMEnable) { returnString = EM9636B.GetInstance().SetPWMEnable(true, true, true); } else if (mEvent == DAQEvent.SetPWMDisable) { returnString = SetPWMStop(); //mEM9636B.SetPWMEnable(false, false, false); } else if (mEvent == DAQEvent.SetPWMValue) { returnString = SetPWMStart(); } else if (mEvent == DAQEvent.SetMotorStart) { returnString = SetMotorStart(); } else if (mEvent == DAQEvent.SetMotorStop) { returnString = SetMotorStop(); } if (!string.IsNullOrEmpty(returnString)) { MessageBox.Show(returnString); } mEvent = DAQEvent.NA; } } catch (System.Exception ex) { System.Console.Out.WriteLine(ex.Message); } mTimer.Start(); }
private string SetMotorStop() { string returnString = EM9636B.GetInstance().SetIO1_16((byte)(mIO1_8Status & (~0x10) & (~0x08)), mIO9_16Status); if (!string.IsNullOrEmpty(returnString)) { return(returnString); } returnString = EM9636B.GetInstance().SetPWMEnable(false, false, false); if (string.IsNullOrEmpty(returnString)) { return(returnString); } return(string.Empty); }
private void btnConnect_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { string returnString = EM9636B.GetInstance().Connect(); if (!string.IsNullOrEmpty(returnString)) { MessageBox.Show(returnString); tabPageDAQ.Text = "数据采集卡-未连接"; grpPWM.Enabled = false; grpOptoDIO.Enabled = false; grpDIO.Enabled = false; grpMotor.Enabled = false; } else { tabPageDAQ.Text = "数据采集卡-已连接"; grpPWM.Enabled = true; grpOptoDIO.Enabled = true; grpDIO.Enabled = true; grpMotor.Enabled = true; RefreshDIOStatus(); RefreshDIDisplay(); RefreshIODisplay(); InitializeDODispaly(); InitializeDIODispaly(); InitializeTimers(); mTimer.Start(); } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } finally { this.Cursor = Cursors.Default; } }
private string SetMotorStart() { string returnString; double rate = (int)numMotorRate.Value / 60.0; returnString = EM9636B.GetInstance().SetIOPinsDirection(EM9636_IO_DIRECTION.OUT, EM9636_IO_SELECTION.IO1_16); if (!string.IsNullOrEmpty(returnString)) { return(returnString); } //方向//锁定 returnString = EM9636B.GetInstance().SetIO1_16((byte)(mIO1_8Status | 0x08 | 0x10), mIO9_16Status); if (!string.IsNullOrEmpty(returnString)) { return(returnString); } //returnString = mEM9636B.SetIOPInsOut(0, (byte)(mIO1_8Status | 0x10), mIO9_16Status); //if (!string.IsNullOrEmpty(returnString)) //{ // return returnString; //} int frequency = (int)((int)numPulseCycle.Value * rate); returnString = EM9636B.GetInstance().SetPWMParameter(1, frequency, 50); if (string.IsNullOrEmpty(returnString)) { bool isChannelOne = ((byte)numPWMChannel.Value == 1); bool isChannelTwo = ((byte)numPWMChannel.Value == 2); bool isChannelThree = ((byte)numPWMChannel.Value == 3); returnString = EM9636B.GetInstance().SetPWMEnable(true, true, true); if (string.IsNullOrEmpty(returnString)) { return(string.Empty); } } return(returnString); }