コード例 #1
0
        public SnapshotRetriever(CameraSummary summary, IGXFactory igxFactory)
        {
            this.summary = summary;

            try
            {
                device         = igxFactory.OpenDeviceBySN(summary.Identifier, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                featureControl = device.GetRemoteFeatureControl();
                DahengHelper.AfterOpen(featureControl);

                width   = (int)featureControl.GetIntFeature("Width").GetValue();
                height  = (int)featureControl.GetIntFeature("Height").GetValue();
                isColor = DahengHelper.IsColor(featureControl);

                stream = device.OpenStream(0);
            }
            catch (Exception e)
            {
                LogError(e, "Failed to open device");
            }
        }
コード例 #2
0
 public bool Open()
 {
     if (listGXDeviceInfo.Count > 0 && objDevice == null)
     {
         if (camera_id < listGXDeviceInfo.Count)
         {
             camera_sn            = listGXDeviceInfo[camera_id].GetSN();
             objDevice            = IGXFactory.GetInstance().OpenDeviceBySN(camera_sn, GxIAPINET.GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
             objIGXStream         = objDevice.OpenStream(0);
             objIGXFeatureControl = objDevice.GetRemoteFeatureControl();
             objIGXStream.RegisterCaptureCallback(objDevice, OnFrameCallbackFun);
             objIGXStream.StartGrab();
         }
         else
         {
             Console.WriteLine("相机初始化失败!");
             return(false);
         }
         return(true);
     }
     return(false);
 }
コード例 #3
0
        public int OpenCamera()
        {
            //关闭流
            if (null != m_objIGXStream)
            {
                m_objIGXStream.Close();
                m_objIGXStream = null;
            }

            //关闭设备
            if (null != m_objIGXDevice)
            {
                m_objIGXDevice.Close();
                m_objIGXDevice = null;
            }

            IGXFactory m_objIGXFactory = null;

            m_objIGXFactory = IGXFactory.GetInstance();
            m_objIGXFactory.Init();
            List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>();

            m_objIGXFactory.UpdateDeviceList(200, listGXDeviceInfo);

            foreach (IGXDeviceInfo tempinfo in listGXDeviceInfo)
            {
                if (tempinfo.GetUserID() == this.name)
                {
                    m_objIGXDevice         = ObjIGXFactory.OpenDeviceByUserID(this.Name, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                    m_objIGXFeatureControl = m_objIGXDevice.GetRemoteFeatureControl();
                    m_DeviceOffLine        = m_objIGXDevice.RegisterDeviceOfflineCallback(null, CallOffLineFunction);
                }
            }

            TriggerConfiguration();
            SetExposureTime();

            return(0);
        }
コード例 #4
0
        private static void WriteInt(IGXFeatureControl featureControl, CameraProperty property)
        {
            bool writeable = featureControl.IsWritable(property.Identifier);

            if (!writeable)
            {
                return;
            }

            int value = int.Parse(property.CurrentValue, CultureInfo.InvariantCulture);
            int min   = int.Parse(property.Minimum, CultureInfo.InvariantCulture);
            int step  = int.Parse(property.Step, CultureInfo.InvariantCulture);

            int remainder = (value - min) % step;

            if (remainder != 0)
            {
                value = value - remainder + step;
            }

            featureControl.GetIntFeature(property.Identifier).SetValue(value);
        }
コード例 #5
0
        public override bool DoStartGrab()
        {
            try
            {
                if (m_objIGXDevice == null || m_objIGXStream == null)
                {
                    ////ErrorMessage.Append("还没有打开设备。");
                    return(false);
                }
                IGXFeatureControl sfc = m_objIGXStream.GetFeatureControl();
                if (sfc == null)
                {
                    ////ErrorMessage.Append("获取通道控制器异常。");
                    return(false);
                }
                //设置流层Buffer处理模式为OldestFirst
                sfc.GetEnumFeature("StreamBufferHandlingMode").SetValue("OldestFirst");
                m_objIGXStream.SetAcqusitionBufferNumber(1);
                //开启采集流通道
                m_objIGXStream.StartGrab();

                //发送开采命令
                IGXFeatureControl fc = m_objIGXDevice.GetRemoteFeatureControl();
                if (fc == null)
                {
                    //ErrorMessage.Append("获取设备控制器异常。");
                    return(false);
                }
                //记录当前是否是彩色模式
                try { _IsColorMode = (fc.GetEnumFeature("PixelColorFilter").GetValue() != "None"); }
                catch (Exception ex) { _IsColorMode = false; }
                fc.GetCommandFeature("AcquisitionStart").Execute();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #6
0
        /// <summary>
        /// 打开相机
        /// </summary>
        public override void Open()
        {
            // 如果设备已经打开则关闭,保证相机在初始化出错情况下能再次打开
            if (null != objIGXDevice)
            {
                objIGXDevice.Close();
                objIGXDevice = null;
            }

            //打开设备
            objIGXDevice         = IGXFactory.GetInstance().OpenDeviceBySN(strName, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
            objIGXFeatureControl = objIGXDevice.GetRemoteFeatureControl();

            //打开流
            objIGXStream = objIGXDevice.OpenStream(0);
            objIGXStreamFeatureControl = objIGXStream.GetFeatureControl();

            // 建议用户在打开网络相机之后,根据当前网络环境设置相机的流通道包长值,
            // 以提高网络相机的采集性能,设置方法参考以下代码。
            GX_DEVICE_CLASS_LIST objDeviceClass = objIGXDevice.GetDeviceInfo().GetDeviceClass();

            if (GX_DEVICE_CLASS_LIST.GX_DEVICE_CLASS_GEV == objDeviceClass)
            {
                // 判断设备是否支持流通道数据包功能
                if (true == objIGXFeatureControl.IsImplemented("GevSCPSPacketSize"))
                {
                    // 获取当前网络环境的最优包长值
                    uint nPacketSize = objIGXStream.GetOptimalPacketSize();
                    // 将最优包长值设置为当前设备的流通道包长值
                    objIGXFeatureControl.GetIntFeature("GevSCPSPacketSize").SetValue(nPacketSize);
                }
            }

            //初始化相机参数
            objIGXFeatureControl.GetEnumFeature("AcquisitionMode").SetValue("Continuous"); //设置采集模式连续采集
            objIGXFeatureControl.GetEnumFeature("TriggerSource").SetValue("Software");     //设置触发源软触发
            objIGXFeatureControl.GetEnumFeature("TriggerMode").SetValue("On");             //默认单张
        }
コード例 #7
0
        private static void WriteFloat(IGXFeatureControl featureControl, CameraProperty property)
        {
            if (property.ReadOnly)
            {
                return;
            }

            // Switch OFF the auto flag if needed, to be able to write the main property.
            if (!string.IsNullOrEmpty(property.AutomaticIdentifier))
            {
                if (featureControl.IsImplemented(property.AutomaticIdentifier))
                {
                    string currentAutoValue = featureControl.GetEnumFeature(property.AutomaticIdentifier).GetValue();
                    bool   currentAuto      = currentAutoValue == GetAutoTrue(property.AutomaticIdentifier);
                    if (property.CanBeAutomatic && currentAuto && !property.Automatic && featureControl.IsWritable(property.AutomaticIdentifier))
                    {
                        featureControl.GetEnumFeature(property.AutomaticIdentifier).SetValue(GetAutoFalse(property.AutomaticIdentifier));
                    }
                }
            }

            // At this point the auto flag is off. Write the main property.
            float value = float.Parse(property.CurrentValue, CultureInfo.InvariantCulture);

            if (featureControl.IsWritable(property.Identifier))
            {
                featureControl.GetFloatFeature(property.Identifier).SetValue(value);
            }

            // Finally, switch ON the auto flag if needed.
            if (!string.IsNullOrEmpty(property.AutomaticIdentifier))
            {
                if (featureControl.IsImplemented(property.AutomaticIdentifier) && property.CanBeAutomatic && property.Automatic && featureControl.IsWritable(property.AutomaticIdentifier))
                {
                    featureControl.GetEnumFeature(property.AutomaticIdentifier).SetValue(GetAutoTrue(property.AutomaticIdentifier));
                }
            }
        }
コード例 #8
0
ファイル: CDHCam.cs プロジェクト: harry07ss/DHCam-Zolix-TMA
        public bool __open()
        {
            try
            {
                m_objIGXStream = m_objIGXDevice.OpenStream(0);
                m_objIGXStream.RegisterCaptureCallback(m_objIGXDevice, OnFrameCallbackFun);
                objIGXFeatureControl = m_objIGXDevice.GetRemoteFeatureControl();
                objIGXFeatureControl.GetEnumFeature("AcquisitionMode").SetValue("Continuous");
                objIGXFeatureControl.GetEnumFeature("ExposureAuto").SetValue("Off");
                objIGXFeatureControl.GetFloatFeature("ExposureTime").SetValue(70000.0);
                objIGXFeatureControl.GetIntFeature("GevSCPSPacketSize").SetValue(3000);
                objIGXFeatureControl.GetIntFeature("GevSCPD").SetValue(100);

                isOpen = true;
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                isOpen = false;
                return(false);
            }
        }
コード例 #9
0
        private void __CloseAll()
        {
            try
            {
                // Check whether the device has been stoped acquisition
                if (m_bIsSnap)
                {
                    if (null != m_objIGXFeatureControl)
                    {
                        m_objIGXFeatureControl.GetCommandFeature("AcquisitionStop").Execute();
                        m_objIGXFeatureControl = null;
                    }
                }
            }
            catch (Exception)
            {
            }
            m_bIsSnap = false;

            try
            {
                // Stop stream channel acquisition and close stream
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.StopGrab();
                    m_objIGXStream.Close();
                    m_objIGXStream = null;
                }
            }
            catch (Exception)
            {
            }

            // Close device
            __CloseDevice();
            m_bIsOpen = false;
        }
コード例 #10
0
ファイル: DahengHelper.cs プロジェクト: weblate/Kinovea
        public static double GetResultingFramerate(IGXDevice device)
        {
            if (device == null)
            {
                return(0);
            }

            IGXFeatureControl featureControl = device.GetRemoteFeatureControl();

            if (featureControl == null)
            {
                return(0);
            }

            try
            {
                string identifier  = "CurrentAcquisitionFrameRate";
                bool   implemented = featureControl.IsImplemented(identifier);
                if (!implemented)
                {
                    return(0);
                }

                bool readable = featureControl.IsReadable(identifier);
                if (!readable)
                {
                    return(0);
                }

                return(featureControl.GetFloatFeature(identifier).GetValue());
            }
            catch (Exception e)
            {
                log.ErrorFormat("Error while reading current acquisition framerate. {0}", e.Message);
                return(0);
            }
        }
コード例 #11
0
 /// <summary>
 /// 方法:设置触发信号边缘
 /// [注:用于触发源为硬触发]
 /// </summary>
 /// <param name="dege">边缘信号</param>
 /// <returns></returns>
 public override bool DoSetTriggerActivation(ProCommon.Communal.TriggerLogic edge)
 {
     try
     {
         if (m_objIGXDevice == null)
         {
             ////ErrorMessage.Append("还没有打开设备。");
             return(false);
         }
         IGXFeatureControl fc = m_objIGXDevice.GetRemoteFeatureControl();
         if (fc == null)
         {
             ////ErrorMessage.Append("设置设备异常。");
             return(false);
         }
         string strVal = null;
         if (edge == ProCommon.Communal.TriggerLogic.FallEdge)
         {
             strVal = "FallingEdge";
         }
         else if (edge == ProCommon.Communal.TriggerLogic.RaiseEdge)
         {
             strVal = "RisingEdge";
         }
         else
         {
             ////ErrorMessage.Append("不支持该出发方式。");
             return(false);
         }
         fc.GetEnumFeature("TriggerActivation").SetValue(strVal);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
コード例 #12
0
        /// <summary>
        /// 停止采集关闭设备、关闭流
        /// </summary>
        private void __CloseAll()
        {
            try
            {
                // 如果未停采则先停止采集
                if (m_bIsSnap)
                {
                    if (null != m_objIGXFeatureControl)
                    {
                        m_objIGXFeatureControl.GetCommandFeature("AcquisitionStop").Execute();
                        m_objIGXFeatureControl = null;
                    }
                }
            }
            catch (Exception)
            {
            }
            m_bIsSnap = false;
            try
            {
                //停止流通道和关闭流
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.StopGrab();
                    m_objIGXStream.Close();
                    m_objIGXStream = null;
                }
            }
            catch (Exception)
            {
            }

            //关闭设备
            __CloseDevice();
            m_bIsOpen = false;
        }
コード例 #13
0
        /// <summary>
        /// 停止采集关闭设备、关闭流
        /// </summary>
        public void CloseAll(bool m_bIsSnap)
        {
            try
            {
                //如果未停采则先停止采集
                if (m_bIsSnap)
                {
                    if (null != m_objIGXFeatureControl)
                    {
                        m_objIGXFeatureControl.GetCommandFeature("AcquisitionStop").Execute();
                        m_objIGXFeatureControl = null;
                    }
                }
            }
            catch (Exception)
            {
            }
            try
            {
                //停止流通道、注销采集回调和关闭流
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.StopGrab();
                    //注销采集回调函数
                    m_objIGXStream.UnregisterCaptureCallback();
                    m_objIGXStream.Close();
                    m_objIGXStream = null;
                }
            }
            catch (Exception)
            {
            }

            //关闭设备
            CloseCamera();
        }
コード例 #14
0
        private void Open()
        {
            if (device != null)
            {
                Close();
            }

            bool open = false;

            try
            {
                device         = igxFactory.OpenDeviceBySN(summary.Identifier, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                featureControl = device.GetRemoteFeatureControl();
                DahengHelper.AfterOpen(featureControl);
                open = true;
            }
            catch
            {
                log.DebugFormat("Could not open Daheng device.");
            }

            if (!open)
            {
                return;
            }

            SpecificInfo specific = summary.Specific as SpecificInfo;

            if (specific == null)
            {
                return;
            }

            // Store the camera object into the specific info so that we can retrieve device informations from the configuration dialog.
            specific.Device = device;
            isColor         = DahengHelper.IsColor(featureControl);

            if (firstOpen)
            {
                // Always default to RGB24 for color cameras and Y800 for mono cameras.
                // Raw mode will have to be switched explicitly everytime for now.
                currentStreamFormat = isColor ? DahengStreamFormat.RGB : DahengStreamFormat.Mono;

                // Grab current values.
                Dictionary <string, CameraProperty> cameraProperties = CameraPropertyManager.Read(device);
                specific.CameraProperties = cameraProperties;
                specific.StreamFormat     = currentStreamFormat;
            }
            else
            {
                CameraPropertyManager.WriteCriticalProperties(device, specific.CameraProperties);
                if (specific.StreamFormat != currentStreamFormat)
                {
                    currentStreamFormat = specific.StreamFormat;
                }
            }

            try
            {
                stream = device.OpenStream(0);
            }
            catch
            {
                log.Debug("Could not start Daheng device.");
            }
        }
コード例 #15
0
        /// 拍摄单张
        public void SingleShot(string save_path)
        {
            strSingleShotName = save_path;
            try
            {
                m_objIGXFactory = IGXFactory.GetInstance();
                m_objIGXFactory.Init();

                List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>();

                //关闭流
                __CloseStream();
                // 如果设备已经打开则关闭,保证相机在初始化出错情况下能再次打开
                __CloseDevice();

                m_objIGXFactory.UpdateDeviceList(200, listGXDeviceInfo);

                // 判断当前连接设备个数
                if (listGXDeviceInfo.Count <= 0)
                {
                    MessageBox.Show("未发现设备!");
                    return;
                }

                str_MySN       = listGXDeviceInfo[0].GetSN();
                m_objIGXDevice = m_objIGXFactory.OpenDeviceBySN(str_MySN, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                if (null == m_objIGXDevice)
                {
                    MessageBox.Show(string.Format("未能打开相机{0}设备。", str_MySN));
                    return;
                }

                m_objGxBitmap          = new GxBitmap(m_objIGXDevice);
                m_objIGXFeatureControl = m_objIGXDevice.GetRemoteFeatureControl();
                if (null == m_objIGXFeatureControl)
                {
                    MessageBox.Show(string.Format("未获得相机{0}属性控制。", str_MySN));
                    return;
                }
                m_objIGXStream = m_objIGXDevice.OpenStream(0);
                if (null == m_objIGXStream)
                {
                    MessageBox.Show(string.Format("相机{0}获取流失败。", str_MySN));
                }

                //初始化相机参数
                m_objIGXFeatureControl.GetEnumFeature("AcquisitionMode").SetValue("Continuous");
                m_objIGXFeatureControl.GetEnumFeature("TriggerMode").SetValue("Off");

                //打开流,获得单帧图像
                m_objIGXStream.StartGrab();
                m_objIGXFeatureControl.GetCommandFeature("AcquisitionStart").Execute();
                IImageData singleImageData = m_objIGXStream.GetImage(100);
                m_objIGXFeatureControl.GetCommandFeature("AcquisitionStop").Execute();
                m_objIGXFeatureControl = null;
                m_objIGXStream.StopGrab();
                __CloseStream();
                __CloseDevice();
                m_objIGXFactory.Uninit();
                if (!Directory.Exists(m_strFilePath))
                {
                    Directory.CreateDirectory(m_strFilePath);
                }
                strSingleShotName = m_strFilePath + "\\" + strSingleShotName;
                m_objGxBitmap.SaveBmp(singleImageData, strSingleShotName);
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #16
0
        private static CameraProperty ReadFramerate(IGXFeatureControl featureControl, Dictionary <string, CameraProperty> properties)
        {
            string         identifier = "AcquisitionFrameRate";
            CameraProperty p          = new CameraProperty();

            p.Identifier = identifier;
            p.Supported  = false;
            p.Type       = CameraPropertyType.Float;

            bool isImplemented = featureControl.IsImplemented(identifier);

            if (!isImplemented)
            {
                return(p);
            }

            bool isReadable = featureControl.IsReadable(identifier);

            p.ReadOnly  = false;
            p.Supported = isReadable;
            if (!p.Supported)
            {
                return(p);
            }

            double value = featureControl.GetFloatFeature(identifier).GetValue();
            double min   = featureControl.GetFloatFeature(identifier).GetMin();
            double max   = featureControl.GetFloatFeature(identifier).GetMax();
            double step  = 1;

            min = Math.Max(1.0, min);

            p.CurrentValue = value.ToString(CultureInfo.InvariantCulture);
            p.Minimum      = min.ToString(CultureInfo.InvariantCulture);
            p.Maximum      = max.ToString(CultureInfo.InvariantCulture);
            p.Step         = step.ToString(CultureInfo.InvariantCulture);

            double range = Math.Log10(max) - Math.Log10(min);

            p.Representation = (range >= 4) ? CameraPropertyRepresentation.LogarithmicSlider : CameraPropertyRepresentation.LinearSlider;

            // AcquisitionFrameRateMode=Off: the framerate is automatically set to the max value possible.
            // AcquisitionFrameRateMode=On: use the custom framerate set by the user in AcquisitionFrameRate.

            string autoIdentifier = "AcquisitionFrameRateMode";

            p.AutomaticIdentifier = autoIdentifier;
            p.CanBeAutomatic      = featureControl.IsImplemented(autoIdentifier);
            p.Automatic           = false;
            if (p.CanBeAutomatic && featureControl.IsReadable(autoIdentifier))
            {
                string autoValue = featureControl.GetEnumFeature(autoIdentifier).GetValue();
                p.Automatic = autoValue == GetAutoTrue(autoIdentifier);
            }

            if (properties != null)
            {
                properties.Add(p.Identifier, p);
            }

            return(p);
        }
コード例 #17
0
        private void Snapshot_Click(object sender, EventArgs e)
        {
            try
            {
                //1.Open Device
                // Before using any GxIAPINET methods, the GxIAPINET must be initialized.
                m_objIGXFactory = IGXFactory.GetInstance();
                m_objIGXFactory.Init();

                //open device
                List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>();

                // Close stream
                __CloseStream();

                // If the device is opened then close it to ensure the camera could open again.
                __CloseDevice();

                // Enumerate all camera devices
                m_objIGXFactory.UpdateDeviceList(200, listGXDeviceInfo);

                // Check if found any device
                if (listGXDeviceInfo.Count <= 0)
                {
                    MessageBox.Show("No devices found!");
                    return;
                }

                //Open the first found device
                m_objIGXDevice         = m_objIGXFactory.OpenDeviceBySN(listGXDeviceInfo[0].GetSN(), GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                m_objIGXFeatureControl = m_objIGXDevice.GetRemoteFeatureControl();


                // Open stream
                if (null != m_objIGXDevice)
                {
                    m_objIGXStream = m_objIGXDevice.OpenStream(0);
                }

                // It is recommended that the user set the camera's stream channel packet length value
                // according to the current network environment after turning on
                // the network camera to improve the collection performance of the network camera.
                // For the setting method, refer to the following code.
                GX_DEVICE_CLASS_LIST objDeviceClass = m_objIGXDevice.GetDeviceInfo().GetDeviceClass();
                if (GX_DEVICE_CLASS_LIST.GX_DEVICE_CLASS_GEV == objDeviceClass)
                {
                    // Determine whether the device supports the stream channel packet function.
                    if (true == m_objIGXFeatureControl.IsImplemented("GevSCPSPacketSize"))
                    {
                        // Get the optimal packet length value of the current network environment
                        uint nPacketSize = m_objIGXStream.GetOptimalPacketSize();
                        // Set the optimal packet length value to the stream channel packet length of the current device.
                        m_objIGXFeatureControl.GetIntFeature("GevSCPSPacketSize").SetValue(nPacketSize);
                    }
                }

                __InitDevice();

                m_objGxBitmap = new GxBitmap(m_objIGXDevice, m_pic_ShowImage);



                //2.Start acquisition
                // Start stream channel acquisition
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.StartGrab();
                }

                // Send AcquisitionStart command
                if (null != m_objIGXFeatureControl)
                {
                    m_objIGXFeatureControl.GetCommandFeature("AcquisitionStart").Execute();
                }



                //3.Snapshot
                IImageData objIImageData = null;
                double     dElapsedtime  = 0;
                uint       nTimeout      = 500;


                //Flush image queues to clear out-of-date images
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.FlushQueue();
                }

                //Send TriggerSoftware commands
                if (null != m_objIGXFeatureControl)
                {
                    m_objIGXFeatureControl.GetCommandFeature("TriggerSoftware").Execute();
                }

                //Get image
                if (null != m_objIGXStream)
                {
                    //Start stopwatch
                    m_objStopTime.Start();

                    objIImageData = m_objIGXStream.GetImage(nTimeout);

                    //Stop stopwatch and get the ElapsedTime
                    dElapsedtime = m_objStopTime.Stop();
                }

                m_objGxBitmap.Show(objIImageData);
                string strFileName = @"D:\TestImages\SWS.bmp";
                m_objGxBitmap.SaveBmp(objIImageData, strFileName);


                if (null != objIImageData)
                {
                    // Release resource
                    objIImageData.Destroy();
                }

                //4.Stop acquisition
                // Send AcquisitionStop command
                if (null != m_objIGXFeatureControl)
                {
                    m_objIGXFeatureControl.GetCommandFeature("AcquisitionStop").Execute();
                }

                // Stop stream channel acquisition
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.StopGrab();
                }

                //5.Close device
                // Reset statistical time count
                m_objStatistic.Reset();

                // close stream and device
                __CloseAll();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #18
0
        public bool DoSetOutPut(int lineIdx, bool onOff)
        {
            try
            {
                ////ErrorMessage.Clear();
                IGXFeatureControl fc = GetFeatureControl();
                if (fc == null)
                {
                    return(false);
                }
                string strLine = "";
                if (lineIdx == 0)
                {
                    strLine = "Line0";
                }
                else if (lineIdx == 1)
                {
                    strLine = "Line1";
                }
                else if (lineIdx == 2)
                {
                    strLine = "Line2";
                }
                else if (lineIdx == 3)
                {
                    strLine = "Line3";
                }
                else
                {
                    ////ErrorMessage.Append("触发线序号无效。");
                    return(false);
                }

                int tryTime = 10;
                for (int i = 0; i < tryTime; ++i)
                {//频繁输出会报异常
                    try{ fc.GetEnumFeature("LineSelector").SetValue(strLine); break; }catch (Exception ex) { }
                    System.Threading.Thread.Sleep(10);
                    if (i == (tryTime - 1))
                    {
                        return(false);
                    }
                }

                for (int i = 0; i < tryTime; ++i)
                {//频繁输出会报异常
                    try { fc.GetEnumFeature("LineMode").SetValue("Output"); break; } catch (Exception ex) { }
                    System.Threading.Thread.Sleep(10);
                    if (i == (tryTime - 1))
                    {
                        return(false);
                    }
                }

                //fc.GetBoolFeature("LineStatus").SetValue(onOff);

                for (int i = 0; i < tryTime; ++i)
                {//频繁输出会报异常
                    try { fc.GetBoolFeature("UserOutputValue").SetValue(false); break; } catch (Exception ex) { }
                    System.Threading.Thread.Sleep(10);
                    if (i == (tryTime - 1))
                    {
                        return(false);
                    }
                }

                for (int i = 0; i < tryTime; ++i)
                {//频繁输出会报异常
                    try { fc.GetBoolFeature("LineInverter").SetValue(onOff); break; } catch (Exception ex) { }
                    System.Threading.Thread.Sleep(10);
                    if (i == (tryTime - 1))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }