/// <summary>
        /// 测试仪器连通情况
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Test_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(Command.Text))
            {
                SetFail("Please input command first.");
                return;
            }
            var instr = ((InstrumentModel)Instruments.SelectedItem);

            //try
            //{

            //    IInstrumentHelper dd = new SteligentPW3256();
            //    dd.Open(instr);

            //    dd.InvokeProc("SetVoltage", 12.0, "0", "1");

            //    dd.InvokeProc("PowerOn", null, null, "1");
            //    Thread.Sleep(500);
            //    var dc = dd.InvokeProc<string>("MeasureVlotage", null, null, "1");

            //    SetSucess(dc);

            //    dd.InvokeProc("PowerOff", null, null, "1");
            //    dd.Close();
            //}
            //catch (Exception exp)
            //{
            //    var aa = "";
            //}


            if (instr.CommReference == null)
            {
                SetFail("Instrument communication type error.");
                return;
            }
            try
            {
                instr.CommReference.Configuration = CommunicationBase.FormatConfiguration(instr.CommnunicationType, instr.Config);
                instr.CommReference.Open();
                var cmd = Command.Text;
                switch ((TerminationCharacter)TerminationChar.SelectedValue)
                {
                case TerminationCharacter.LineFeed:
                    cmd += "\n";
                    break;

                case TerminationCharacter.CarriageReturn:
                    cmd += "\r";
                    break;

                case TerminationCharacter.LF_CR:
                    cmd += "\r\n";
                    break;

                default:
                    break;
                }
                instr.CommReference.SendData(cmd);

                if ((bool)IsReadDataBtn.IsChecked)
                {
                    Thread.Sleep(Convert.ToInt32(Delay.Text));
                    var data = instr.CommReference.ReceiveData <string>();
                    SetSucess((bool)TrimBtn.IsChecked ? data?.Trim() : data);
                }
                else
                {
                    SetSucess("");
                }

                instr.CommReference.Close();
            }
            catch (Exception exp)
            {
                instr.CommReference.Close();
                SetFail(exp.Message.Trim());
            }
        }
Beispiel #2
0
 public InstrumentBase(InstrumentModel instr)
 {
     Instrument = instr.CommReference;
     Instrument.Configuration = CommunicationBase.FormatConfiguration(instr.CommnunicationType, instr.Config);
 }