/// <summary> /// 进入 Measure 步骤 /// </summary> protected override void internalEnterMeasureStep() { //nlogger.Error("wghou enter measure step."); base.internalEnterMeasureStep(); // 确保打开了串口,确保清空串口中的数据 try { sPort.Open(); sPort.DiscardInBuffer(); } catch { } switch (sampleMode) { case InstSampleMode.AutoSample_Fmt0: case InstSampleMode.AutoSample_Fmt1: currentCmd = SBE37Cmd.Start; CmdExecuted = true; bool rlt = sendCMD("Start"); if (rlt == false) { nlogger.Error("error in sendCmd with internalEnterMeasureStep"); OnErrorOccur(Err_sr.Error); } break; case InstSampleMode.PolledSample_Fmt10: // 此处为前一个指令 currentCmd = SBE37Cmd.Tsr; CmdExecuted = true; sendCMD("OutputFormat=1"); _tickTimerInst.Start(); break; case InstSampleMode.PolledSample_Fmt0: currentCmd = SBE37Cmd.Ts; CmdExecuted = true; sendCMD("OutputFormat=1"); _tickTimerInst.Start(); break; case InstSampleMode.PolledSample_Fmt1: currentCmd = SBE37Cmd.Tsr; CmdExecuted = true; sendCMD("OutputFormat=1"); _tickTimerInst.Start(); break; default: break; } }
/// <summary> /// 执行 Measure 步骤 /// </summary> protected override void internalMeasureStep() { //nlogger.Error("wghou internal measure step."); if (sampleMode == InstSampleMode.AutoSample_Fmt0 || sampleMode == InstSampleMode.AutoSample_Fmt1) { } else if (sampleMode == InstSampleMode.PolledSample_Fmt0) { currentCmd = SBE37Cmd.Tsr; sendSampleCmd(currentCmd); } else if (sampleMode == InstSampleMode.PolledSample_Fmt1) { currentCmd = SBE37Cmd.Ts; sendSampleCmd(currentCmd); } else if (sampleMode == InstSampleMode.PolledSample_Fmt10) { // 上一个指令未成功返回结果 // todo: if (CmdExecuted == false) { nlogger.Error("error in sendCmd with internalMeasureStep"); OnErrorOccur(Err_sr.Error); CmdExecuted = true; return; } // 判断前一个指令 if (currentCmd == SBE37Cmd.Ts) { currentCmd = SBE37Cmd.Tsr; sendSampleCmd(currentCmd); } // 判断前一个指令 else if (currentCmd == SBE37Cmd.Tsr) { currentCmd = SBE37Cmd.Ts; sendSampleCmd(currentCmd); } else { nlogger.Error("code error"); OnErrorOccur(Err_sr.Error); } } }
/// <summary> /// 进入 Store 步骤 /// </summary> protected override void internalEnterStoreStep() { if (sampleMode == InstSampleMode.AutoSample_Fmt0 || sampleMode == InstSampleMode.AutoSample_Fmt1) { currentCmd = SBE37Cmd.Stop; CmdExecuted = false; bool rlt = sendCMD("stop"); if (rlt == false) { nlogger.Error("error in sendCmd with internalEnterStoreStep"); OnErrorOccur(Err_sr.Error); } } else { _tickTimerInst.Stop(); } }
/// <summary> /// 配置当前的仪器 /// </summary> /// <param name="mode"></param> /// <returns></returns> public bool SetupSBE37(InstSampleMode mode = InstSampleMode.PolledSample_Fmt10) { Enable = true; _tickTimerInst.Interval = sampleIntervalSec * 500; //nlogger.Error("wghou sampleIntervalSec: " + sampleIntervalSec.ToString()); //_tickTimerInst.Interval = 10000; // 读取 calibration coefficients //currentCmd = SBE37Cmd.GetCC; //CmdExecuted = false; //sendCMD("GetCC"); //while (!CmdExecuted) { System.Threading.Thread.Sleep(10); } //bool rlt1 = calibCCoeff.ResolveXml2Value(CalibCoeffXml); //if (rlt1 == false) //{ // nlogger.Error("error when read and resolve configuration data from xml string"); // return false; //} // 设置返回标志位 //CmdExecuted = false; //bool rlt2 = sendCMD("OutputExecutedTag=N"); //System.Threading.Thread.Sleep(10); //if(rlt2 == false) //{ // nlogger.Error("Error in setup instDevice 1."); // return false; //} // 写入一些设置信息 bool rlt3 = true; switch (mode) { // 暂时还不用这种方法 case InstSampleMode.AutoSample_Fmt0: rlt3 &= sendCMD("SAMPLEMODE=2"); System.Threading.Thread.Sleep(10); rlt3 &= sendCMD("SAMPLEINTERVAL=4"); System.Threading.Thread.Sleep(10); rlt3 &= sendCMD("OUTPUTFORMAT=0"); System.Threading.Thread.Sleep(10); rlt3 &= sendCMD("AUTORUN=N"); System.Threading.Thread.Sleep(10); outputFormat = SBE37OutputFormat.Format_0; break; // 暂时还不用这种方法 case InstSampleMode.AutoSample_Fmt1: rlt3 &= sendCMD("SAMPLEMODE=2"); System.Threading.Thread.Sleep(10); rlt3 &= sendCMD("SAMPLEINTERVAL=4"); System.Threading.Thread.Sleep(10); rlt3 &= sendCMD("OUTPUTFORMAT=1"); System.Threading.Thread.Sleep(10); rlt3 &= sendCMD("AUTORUN=N"); System.Threading.Thread.Sleep(10); outputFormat = SBE37OutputFormat.Format_1; break; // 暂时还不用这种方法 case InstSampleMode.PolledSample_Fmt0: rlt3 &= sendCMD("SAMPLEMODE=1"); System.Threading.Thread.Sleep(10); rlt3 &= sendCMD("AUTORUN=N"); System.Threading.Thread.Sleep(10); rlt3 &= sendCMD("OUTPUTFORMAT=0"); System.Threading.Thread.Sleep(10); outputFormat = SBE37OutputFormat.Format_0; break; // 暂时还不用这种方法 case InstSampleMode.PolledSample_Fmt1: rlt3 &= sendCMD("SAMPLEMODE=1"); System.Threading.Thread.Sleep(10); rlt3 &= sendCMD("AUTORUN=N"); System.Threading.Thread.Sleep(10); rlt3 &= sendCMD("OUTPUTFORMAT=1"); System.Threading.Thread.Sleep(10); outputFormat = SBE37OutputFormat.Format_1; break; // case InstSampleMode.PolledSample_Fmt10: //rlt3 &= sendCMD("SAMPLEMODE=1"); //System.Threading.Thread.Sleep(10); //rlt3 &= sendCMD("AUTORUN=N"); //System.Threading.Thread.Sleep(10); currentCmd = SBE37Cmd.WakeUp; CmdExecuted = false; rlt3 &= sendCMD("OUTPUTFORMAT=1"); int ii = 0; while (!CmdExecuted && ii < 20) { System.Threading.Thread.Sleep(50); ii++; } currentCmd = SBE37Cmd.Cfg; CmdExecuted = false; rlt3 &= sendCMD("OUTPUTFORMAT=1"); ii = 0; while (!CmdExecuted && ii < 30) { System.Threading.Thread.Sleep(50); ii++; } outputFormat = SBE37OutputFormat.Format_1; break; default: break; } if (rlt3 == false) { nlogger.Error("Error in setup instDevice 2."); return(false); } sampleMode = mode; // todo: 这里的 while 感觉不是很好 // 读取 configuration data currentCmd = SBE37Cmd.GetCD; CmdExecuted = false; bool rlt4 = sendCMD("GetCD"); int i = 0; while (!CmdExecuted && i < 200) { System.Threading.Thread.Sleep(50); i++; } if (i > 199) { nlogger.Error("timeout when read configuration data from xml string"); return(false); } rlt4 &= configData.ResolveXml2Value(ConfigDataXml); if (rlt4 == false) { nlogger.Error("error when read and resolve configuration data from xml string"); return(false); } //bool rlt5 = true; //UseExecutedFlag = useOptFlg; //if (UseExecutedFlag == true ) { // CmdExecuted = false; // rlt5 = sendCMD("OutputExecutedTag=Y"); // if(rlt5 == false) // { // return false; // } // while (!CmdExecuted) { System.Threading.Thread.Sleep(10); } //} return(true); }
/// <summary> /// 依据指令,发送对应的指令字符串 /// </summary> /// <param name="cmd"></param> /// <returns></returns> private bool sendSampleCmd(SBE37Cmd cmd) { bool rlt = true; CmdExecuted = false; if (userDefinedCmdEnable == true) { if (cmd == SBE37Cmd.Ts) { rlt &= sendCMD(userDefinedCmd["TS1"]); System.Threading.Thread.Sleep(200); rlt &= sendCMD(userDefinedCmd["TS2"]); } else if (cmd == SBE37Cmd.Tsr) { rlt &= sendCMD(userDefinedCmd["TSR1"]); System.Threading.Thread.Sleep(200); rlt &= sendCMD(userDefinedCmd["TSR2"]); } } else { switch (Info.InstType) { case TypeInst.SBE37SM: if (cmd == SBE37Cmd.Ts) { rlt &= sendCMD("OutputFormat=1"); System.Threading.Thread.Sleep(200); rlt &= sendCMD("ts"); } else if (cmd == SBE37Cmd.Tsr) { rlt &= sendCMD("OutputFormat=0"); System.Threading.Thread.Sleep(200); rlt &= sendCMD("ts"); } break; case TypeInst.SBE37SMP: if (cmd == SBE37Cmd.Ts) { rlt &= sendCMD("ts"); } else if (cmd == SBE37Cmd.Tsr) { rlt &= sendCMD("tsr"); } break; case TypeInst.SBE37SI: case TypeInst.SBE37SIP: case TypeInst.SBE37SMPODO: if (cmd == SBE37Cmd.Ts) { rlt &= sendCMD("ts"); } else if (cmd == SBE37Cmd.Tsr) { rlt &= sendCMD("tsr"); } break; default: nlogger.Error("code error xxison"); break; } } if (rlt == false) { nlogger.Error("error in sendCmd with internalMeasureStep"); OnErrorOccur(Err_sr.Error); } return(rlt); }