Exemplo n.º 1
0
        /// <summary>
        /// 设置单台仪器命令
        /// </summary>
        /// <param name="obj"></param>
        private void SetSingleDevice(Object obj)
        {
            MutipleThreadSendCmd model = obj as MutipleThreadSendCmd;

            if (model.GetDevice().IsOnTesting == false)
            {
                model.MTREvent.SetOne();
                return;
            }
            try
            {
                Dictionary <string, string> origin = new Dictionary <string, string>();
                string        send       = GetDeviceSCPI();
                List <string> channelset = model.GetDevice().GetChannelSCPI();
                Debug.WriteLine("初始化仪器,关闭所有通道");
                string channelInit = ":CHANnel1:DISPlay OFF;:CHANnel2:DISPlay OFF;:CHANnel3:DISPlay OFF;:CHANnel4:DISPlay OFF;" + "\n";

                model.GetDevice().deviceVisa.WriteBytes(Encoding.Default.GetBytes(channelInit), Encoding.Default.GetBytes(channelInit).Length);
                Thread.Sleep(50);
                if (channelset.Count == 0)
                {
                    model.MTREvent.SetOne();
                    return;
                }
                Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + " " + model.GetDevice().IP);
                foreach (string cmd in channelset)
                {
                    send += cmd;
                }
                send += Global.CGlobalCmd.STR_CMD_SET_TRIGGERMODE + Instance.TriggerMode + ";";
                send  = send.Remove(send.Length - 1, 1);
                List <string> cmdSend = send.Split(';').ToList();
                send += "\n";
                Debug.WriteLine(DateTime.Now.ToString() + " 开始配置仪器:" + model.GetDevice().IP);
                model.GetDevice().deviceVisa.WriteBytes(Encoding.Default.GetBytes(send), Encoding.Default.GetBytes(send).Length);
                Debug.WriteLine(send);
                Thread.Sleep(50);
                Debug.WriteLine(DateTime.Now.ToString() + " 配置仪器完成:" + model.GetDevice().IP);
                model.MTREvent.SetOne();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(model.GetDevice().IP + " 配置异常:" + ex.Message);
                model.MTREvent.SetOne();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 ///  根据通道配置表,开始设置仪器
 /// </summary>
 public void SetDevices()
 {
     Debug.WriteLine(DateTime.Now.ToString() + " 开始配置");
     using (var countdown = new MutipleThreadResetEvent(Instance.Devices.Count))
     {
         for (int k = 0; k < Instance.Devices.Count; k++)
         {
             var model = new MutipleThreadSendCmd();
             model.SetDevice(Instance.Devices[k]);
             model.MTREvent = countdown;
             //开启N个线程,传递MutipleThreadResetEvent对象给子线程
             ThreadPool.QueueUserWorkItem(SetSingleDevice, model);
         }
         //等待所有线程执行完毕
         countdown.WaitAll();
     }
     Debug.WriteLine(DateTime.Now.ToString() + " ");
 }