/// <summary> /// 获取信息 /// </summary> /// <returns></returns> public string[] GetDataFromCard(out string sInfo) { sInfo = string.Empty; string[] data = new string[4] { "0.00", "0.00", "0.00", "0.00" }; lock (Defs._object2) { //采集卡获得其它数据 ushort[] chans = new ushort[2]; chans[0] = 0; //电压 chans[1] = 4; //电流 ushort[] ranges = new ushort[2]; ranges[0] = D2KDASK.AD_B_10_V | D2KDASK.AI_DIFF; ranges[1] = D2KDASK.AD_B_10_V | D2KDASK.AI_DIFF; short ret = D2KDASK.D2K_AI_MuxScanSetup(0, 2, chans, ranges); if (ret < 0) { sInfo = "D2K_AI_MuxScanSetup error!"; } ushort[] chan_data = new ushort[2]; double temp; double DriverCur = 0.0; //驱动器电流 double DriverVol = 0.0; //驱动器电压 double MotorCur = 0.0; //电机电流 double MotorVol = 0.0; //电机电压 short err = D2KDASK.D2K_AI_ReadMuxScan(0, chan_data); if (err == 0) { D2KDASK.D2K_AI_VoltScale(0, D2KDASK.AD_B_10_V, (short)chan_data[1], out temp); DriverCur = Math.Round(temp, 3); D2KDASK.D2K_AI_VoltScale(0, D2KDASK.AD_B_10_V, (short)chan_data[0], out temp); //DriverVol = Math.Round(temp * 10, 3); if (FilterNumber < VolFilter.Length) { VolFilter[FilterNumber] = Math.Round(temp * 10, 3); FilterNumber++; } else { for (int i = 0; i < VolFilter.Length - 1; i++) { VolFilter[i] = VolFilter[i + 1]; } VolFilter[VolFilter.Length - 1] = Math.Round(temp * 10, 3); } double sumsum = 0; for (int i = 0; i < FilterNumber; i++) { sumsum = sumsum + VolFilter[i]; } DriverVol = sumsum / FilterNumber; } else { sInfo = "结束"; return(data); } //电机功率 double MotorPow = Math.Round(DriverCur * DriverVol, 3); data[0] = DriverCur.ToString(); data[1] = DriverVol.ToString(); data[2] = MotorVol.ToString(); data[3] = MotorPow.ToString(); } return(data); }
/// <summary> /// 打开或关闭飞轮1电源 /// </summary> /// <returns></returns> public bool OpenElecSource(string state, out string error, string experiment_name, string experiment_memeber, string experiment_product) { bool results = true; error = string.Empty; if (state == "ON") { #region 数据采集卡 Defs.ModifyState("4", '0'); D2KDASK.D2K_DO_WritePort(0, D2KDASK.Channel_P1A, Convert.ToUInt32(Defs.StateVector, 2)); DateTime dt = DateTime.Now; #region 采集卡获得浪涌电流 ushort[] chans = new ushort[1]; chans[0] = 1; ushort[] ranges = new ushort[1]; ushort[] chan_data = new ushort[1]; double temp = 0.0; double[] MotorCur = new double[1000]; //浪涌电流 TimeSpan span; int length_wave = 0; DateTime[] dttime = new DateTime[1000]; ranges[0] = D2KDASK.AD_B_10_V | D2KDASK.AI_DIFF; short ret1 = D2KDASK.D2K_AI_MuxScanSetup(0, 1, chans, ranges); if (ret1 < 0) { error = "Wave current error!"; Defs.ModifyState("4", '1'); D2KDASK.D2K_DO_WritePort(0, D2KDASK.Channel_P1A, Convert.ToUInt32(Defs.StateVector, 2)); return(false); } while (true) { D2KDASK.D2K_AI_ReadMuxScan(0, chan_data); D2KDASK.D2K_AI_VoltScale(0, D2KDASK.AD_B_10_V, (short)chan_data[0], out temp); MotorCur[length_wave] = Math.Round(temp, 3); if (length_wave == 1000) { break; } dttime[length_wave] = DateTime.Now; length_wave = length_wave + 1; span = DateTime.Now - dt; if (span.TotalMilliseconds > 10) { break; } } for (int i = 0; i < length_wave; i++) { WriteDataToDatabaseWave("4", "7", MotorCur[i].ToString(), dttime[i].ToString(), experiment_name, experiment_memeber, experiment_product); } #endregion #endregion #region can线程启动 if (Defs.Can1ReadStatus == false) { Defs.Can1ReadStatus = true; Defs.Thread1.Start(); } if (Defs.Can2ReadStatus == false) { Defs.Can2ReadStatus = true; Defs.Thread2.Start(); } #endregion } else { Defs.ModifyState("4", '1'); D2KDASK.D2K_DO_WritePort(0, D2KDASK.Channel_P1A, Convert.ToUInt32(Defs.StateVector, 2)); Defs.Motor4RSuceess = false; } return(results); }