Exemple #1
0
        //send to instrument by visacom
        private string send_to_instrument(string fullcmd,string address,string cmd, IMessage ioDmm,int delay = 0)
        {
            WriteTraceText(fullcmd);
            //IVisaSession basesession = null;
            //IMessage talksession = null;

            string strRd = "";
            string instrumentAddress = address;
            //lock
            //this.WriteTraceText("\n");
            lock (_lock_Instrument)
            {

                    ioDmm.Clear();
                    ioDmm.WriteString(cmd);

                    if (delay != 0 && delay > 500)
                        Thread.Sleep(delay);
                    else
                        Thread.Sleep(500);
                    if (cmd.Contains("?"))
                    {
                        for (int i = 0; i < 5; i++)
                        {

                            try
                            {

                                strRd = ioDmm.ReadString(4069);
                                break;
                            }
                            catch (Exception exp)
                            {
                                ioDmm.Clear();
                                if (i != 9)
                                {
                                    Thread.Sleep(200);
                                    continue;

                                }
                                else
                                {
                                    WriteErrorText("write/read to instrumen by visacom error: " + exp.Message);
                                    throw new Exception(exp.Message);
                                }

                            }

                        }

                    }

            }
            strRd = strRd.TrimEnd('\n');
            return strRd;
        }