示例#1
0
        /// <summary>
        /// 抓取相机的图像,输出Halcon格式
        /// </summary>
        public override ImageAll GrabImageHal()
        {
            g_MtGrabImage.WaitOne();
            ImageAll imageAll = new ImageAll();

            try
            {
                if (!BlOpen)//如果相机打开失败
                {
                    return(null);
                }
#if (SDK)
                try
                {
                    SetTrriggerMode();//设置软触发
                    g_ManagedCameraBase.RetrieveBuffer(g_RawImage);
                }
                catch (Exception ex)
                {
                    Log.L_I.WriteError(NameClass, ex);
                    try
                    {
                        if (g_BaseParCamera.BlUsingTrigger)                       //使用软触发
                        {
                            g_ManagedCameraBase.WriteRegister(0x62C, 0x80000000); //发送软触发指令
                        }
                        g_ManagedCameraBase.RetrieveBuffer(g_RawImage);
                    }
                    catch
                    {
                        if (g_BaseParCamera.BlUsingTrigger)                       //使用软触发
                        {
                            g_ManagedCameraBase.WriteRegister(0x62C, 0x80000000); //发送软触发指令
                        }
                        g_ManagedCameraBase.RetrieveBuffer(g_RawImage);
                    }
                }

                //将图像转换为Halcon格式
                imageAll.Ho_Image     = ConvertHobject();
                imageAll.BitmapSource = null;

                PathDirectory p = new PathDirectory();
                imageAll.Time = p.GetShortTimeName();
#endif
                return(imageAll);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(null);
            }
            finally
            {
                g_MtGrabImage.ReleaseMutex();
            }
        }
示例#2
0
        public void ConstructPathDirectoryWithNullFileSystem()
        {
            // Execute
            var directory = new PathDirectory<string>(a_pathTree: null, a_path: "\\");

            // Assert
            Assert.AreEqual("\\", directory.Path);
            Assert.IsNotNull(directory.FileSystem);
        }
示例#3
0
        public void GetChildFilesWithNullSearchPattern()
        {
            // Setup
            var fileSystem = new PathTree <string>();
            var directory  = new PathDirectory <string>(fileSystem, @"x:\mydirectory");

            // Execute
            directory.Files(a_pattern: null);
        }
示例#4
0
        public void ConstructPathDirectoryWithNullFileSystem()
        {
            // Execute
            var directory = new PathDirectory <string>(a_pathTree: null, a_path: "\\");

            // Assert
            Assert.AreEqual("\\", directory.Path);
            Assert.IsNotNull(directory.FileSystem);
        }
示例#5
0
        public void GetDirectoryByNameWithNull()
        {
            // Setup
            var fileSystem = new PathTree <string>();
            var directory  = new PathDirectory <string>(fileSystem, @"x:\mydirectory");

            // Execute
            directory.File(a_name: null);
        }
示例#6
0
        public void DeleteNotExistingDirectory()
        {
            // Setup
            var fileSystem = new PathTree <string>();
            var directory  = new PathDirectory <string>(fileSystem, "\\this\\is\\a\\directory");

            // Execute
            directory.Delete();
        }
示例#7
0
        /// <summary>
        /// 抓取相机的图像,输出所有的格式
        /// </summary>
        public override ImageAll GrabImageAll()
        {
            ImageAll imageAll = new ImageAll();

            try
            {
                if (!BlOpen ||
                    g_BaseParCamera.BlUsingTrigger)   //外触发模式不进行All抓取
                {
                    return(null);
                }
#if (SDK)
                if (g_Camera != null && g_Camera.IsOpen)
                {
                    if (g_BaseParCamera.BlUsingTrigger &&
                        g_Camera.StreamGrabber.IsGrabbing)
                    {
                        g_Camera.ExecuteSoftwareTrigger();
                        g_AutoResetEvent.WaitOne(500);
                    }
                    else
                    {
                        try
                        {
                            g_Camera.StreamGrabber.Start();
                            g_GrabResult = g_Camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
                        }
                        catch (Exception ex)
                        {
                            Log.L_I.WriteError(NameClass, ex); //The stream grabber is already grabbing.说明取图太快,或者两个线程取图冲突
                        }
                    }
                }

                using (g_GrabResult)
                {
                    if (g_GrabResult != null && g_GrabResult.GrabSucceeded)
                    {
                        imageAll.Ho_Image     = ConvertHobject(g_GrabResult);
                        imageAll.BitmapSource = ConvertImageBitmap(g_GrabResult);

                        PathDirectory p = new PathDirectory();
                        imageAll.TimeShort = p.GetShortTimeName();//图像抓取短时间
                        imageAll.Time      = p.GetTimeName();
                    }
                }

                g_Camera.StreamGrabber.Stop();
#endif
                return(imageAll);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(null);
            }
        }
示例#8
0
        public void CopyInOnNotExistingDirectory()
        {
            // Setup
            var fileSystem = new PathTree <string>();
            var directory  = new PathDirectory <string>(@"\directory");
            var file       = fileSystem.CreateFile(@"\file1.dat", "Value");

            // Execute
            directory.CopyIn(file);
        }
示例#9
0
        public void CopyInOnNotExistingDirectory()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(@"\directory");
            var file = fileSystem.CreateFile(@"\file1.dat", "Value");

            // Execute
            directory.CopyIn(file);
        }
示例#10
0
        public void ConstructPathDirectory()
        {
            // Setup
            var fileSystem = new PathTree<string>();

            // Execute
            var directory = new PathDirectory<string>(fileSystem, "\\");

            // Assert
            Assert.AreEqual("\\", directory.Path);
            Assert.AreSame(fileSystem, directory.FileSystem);
        }
示例#11
0
        public void GetExistsWithNonexistingFile()
        {
            // Setup
            var fileSystem = new PathTree <string>();
            var directory  = new PathDirectory <string>(fileSystem, "\\directory\\does\\not\\exist");

            // Execute
            var result = directory.Exists;

            // Assert
            Assert.IsFalse(result);
        }
示例#12
0
        public void GetName()
        {
            // Setup
            var fileSystem = new PathTree <string>();
            var directory  = new PathDirectory <string>(fileSystem, "\\this\\is\\a\\directory");

            // Execute
            var result = directory.Name;

            // Assert
            Assert.AreEqual("directory", result);
        }
示例#13
0
        public void GetDirectoryPathForNotExistingChild()
        {
            // Setup
            var fileSystem = new PathTree <string>();
            var directory  = new PathDirectory <string>(fileSystem, @"x:\mydirectory");

            // Execute
            var result = directory.DirectoryPath("Directory4");

            // Assert
            Assert.AreEqual(@"x:\mydirectory\Directory4", result);
        }
示例#14
0
        public void GetIsEmptyOnNotExistingDirectory()
        {
            // Setup
            var fileSystem = new PathTree <string>();
            var directory  = new PathDirectory <string>(fileSystem, "\\directory\\does\\not\\exist");

            // Execute
            var result = directory.IsEmpty;

            // Assert
            Assert.IsFalse(result);
        }
示例#15
0
        public void CreateDirectory()
        {
            // Setup
            var fileSystem = new PathTree <string>();
            var directory  = new PathDirectory <string>(fileSystem, "\\this\\is\\a\\directory");

            // Execute
            directory.Create();

            // Assert
            Assert.IsTrue(directory.Exists);
        }
示例#16
0
        public void ConstructPathDirectory()
        {
            // Setup
            var fileSystem = new PathTree <string>();

            // Execute
            var directory = new PathDirectory <string>(fileSystem, "\\");

            // Assert
            Assert.AreEqual("\\", directory.Path);
            Assert.AreSame(fileSystem, directory.FileSystem);
        }
示例#17
0
        public void GetParent()
        {
            // Setup
            var fileSystem = new PathTree <string>();
            var directory  = new PathDirectory <string>(fileSystem, "\\this\\is\\a\\directory");

            // Execute
            var result = directory.Parent;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("a", result.Name);
        }
示例#18
0
        public void GetExistsOnExistingFile()
        {
            // Setup
            var path       = "\\directory\\does\\exist";
            var fileSystem = new PathTree <string>();

            fileSystem.CreateDirectory(path);
            var directory = new PathDirectory <string>(fileSystem, path);

            // Execute
            var result = directory.Exists;

            // Assert
            Assert.IsTrue(result);
        }
示例#19
0
        public void GetChildDirectories()
        {
            // Setup
            var fileSystem = new PathTree <string>();

            fileSystem.CreateDirectory(@"x:\mydirectory\directory1");
            fileSystem.CreateDirectory(@"x:\mydirectory\directory2\child");
            fileSystem.CreateFile(@"x:\mydirectory\directory3\file.rgb", "Value");
            var directory = new PathDirectory <string>(fileSystem, @"x:\mydirectory");

            // Execute
            var result = directory.Directories();

            // Assert
            Assert.AreEqual(3, result.Count());
        }
示例#20
0
        public void GetChildFilesBySearchPattern()
        {
            // Setup
            var fileSystem = new PathTree <string>();

            fileSystem.CreateFile(@"x:\mydirectory\file1.dat", "Value");
            fileSystem.CreateFile(@"x:\mydirectory\file2.dat", "Value");
            fileSystem.CreateFile(@"x:\mydirectory\file3.css", "Value");
            fileSystem.CreateFile(@"x:\mydirectory\otherdirectory\file4.dat", "Value");
            var directory = new PathDirectory <string>(fileSystem, @"x:\mydirectory");

            // Execute
            var filePaths = directory.Files("*.css");

            // Assert
            Assert.AreEqual(1, filePaths.Count());
        }
示例#21
0
        public void GetNotExistingChildDirectoryByName()
        {
            // Setup
            var fileSystem = new PathTree <string>();

            fileSystem.CreateDirectory(@"x:\mydirectory\directory1");
            fileSystem.CreateDirectory(@"x:\mydirectory\directory2\child");
            fileSystem.CreateFile(@"x:\mydirectory\directory3\file.rgb", "Value");
            var directory = new PathDirectory <string>(fileSystem, @"x:\mydirectory");

            // Execute
            var result = directory.Directory("Directory4");

            // Assert
            Assert.AreEqual("Directory4", result.Name);
            Assert.IsFalse(result.Exists);
        }
示例#22
0
        public void CustomTest_I()
        {
            var fileSystem = new PathTree <string>();

            fileSystem.CreateDirectory(@"\Root\Directory");
            fileSystem.CreateDirectory(@"\Root\Directory\Sub1");
            fileSystem.CreateDirectory(@"\Root\Directory\Sub2");
            fileSystem.CreateDirectory(@"\Root\Directory\Sub3");
            fileSystem.CreateFile(@"\Root\Directory\File1.hsf", "Value");
            fileSystem.CreateFile(@"\Root\Directory\File2.hsf", "Value");
            fileSystem.CreateFile(@"\Root\Directory\File3.hsf", "Value");

            var directory = new PathDirectory <string>(fileSystem, @"\");

            var result = directory.Directory(@"Root\Directory\Sub1").Exists;

            Assert.IsTrue(result);
        }
示例#23
0
        public void GetFilePathByName()
        {
            // Setup
            var created      = DateTime.UtcNow;
            var lastModified = DateTime.UtcNow;
            var fileSystem   = new PathTree <string>();

            fileSystem.CreateFile(@"x:\mydirectory\file1.dat", "Value1");
            fileSystem.CreateFile(@"x:\mydirectory\file2.dat", "Value2");
            fileSystem.CreateFile(@"x:\mydirectory\file3.dat", "Value3");
            fileSystem.CreateFile(@"x:\mydirectory\otherdirectory\file4.dat", "Value4");
            var directory = new PathDirectory <string>(fileSystem, @"x:\mydirectory");

            // Execute
            var result = directory.FilePath("File1.dat");

            // Assert
            Assert.AreEqual(@"x:\mydirectory\File1.dat", result);
        }
示例#24
0
        public void GetChildDirectories()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            fileSystem.CreateDirectory(@"x:\mydirectory\directory1");
            fileSystem.CreateDirectory(@"x:\mydirectory\directory2\child");
            fileSystem.CreateFile(@"x:\mydirectory\directory3\file.rgb", "Value");
            var directory = new PathDirectory<string>(fileSystem, @"x:\mydirectory");

            // Execute
            var result = directory.Directories();

            // Assert
            Assert.AreEqual(3, result.Count());
        }
示例#25
0
        public void GetChildDirectoryByNameWithNull()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(fileSystem, @"x:\mydirectory");

            // Execute
            var result = directory.Directory(a_name: null);
        }
示例#26
0
        public void GetFilePathByName()
        {
            // Setup
            var created = DateTime.UtcNow;
            var lastModified = DateTime.UtcNow;
            var fileSystem = new PathTree<string>();
            fileSystem.CreateFile(@"x:\mydirectory\file1.dat", "Value1");
            fileSystem.CreateFile(@"x:\mydirectory\file2.dat", "Value2");
            fileSystem.CreateFile(@"x:\mydirectory\file3.dat", "Value3");
            fileSystem.CreateFile(@"x:\mydirectory\otherdirectory\file4.dat", "Value4");
            var directory = new PathDirectory<string>(fileSystem, @"x:\mydirectory");

            // Execute
            var result = directory.FilePath("File1.dat");

            // Assert
            Assert.AreEqual(@"x:\mydirectory\File1.dat", result);
        }
示例#27
0
        public void GetChildFilesBySearchPattern()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            fileSystem.CreateFile(@"x:\mydirectory\file1.dat", "Value");
            fileSystem.CreateFile(@"x:\mydirectory\file2.dat", "Value");
            fileSystem.CreateFile(@"x:\mydirectory\file3.css", "Value");
            fileSystem.CreateFile(@"x:\mydirectory\otherdirectory\file4.dat", "Value");
            var directory = new PathDirectory<string>(fileSystem, @"x:\mydirectory");

            // Execute
            var filePaths = directory.Files("*.css");

            // Assert
            Assert.AreEqual(1, filePaths.Count());
        }
示例#28
0
        public void GetIsEmptyOnNotExistingDirectory()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(fileSystem, "\\directory\\does\\not\\exist");

            // Execute
            var result = directory.IsEmpty;

            // Assert
            Assert.IsFalse(result);
        }
示例#29
0
        public void GetChildFilesWithNullSearchPattern()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(fileSystem, @"x:\mydirectory");

            // Execute
            directory.Files(a_pattern: null);
        }
示例#30
0
        public void GetExistsOnExistingFile()
        {
            // Setup
            var path = "\\directory\\does\\exist";
            var fileSystem = new PathTree<string>();
            fileSystem.CreateDirectory(path);
            var directory = new PathDirectory<string>(fileSystem, path);

            // Execute
            var result = directory.Exists;

            // Assert
            Assert.IsTrue(result);
        }
示例#31
0
        public void GetDirectoryPathForNotExistingChild()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(fileSystem, @"x:\mydirectory");

            // Execute
            var result = directory.DirectoryPath("Directory4");

            // Assert
            Assert.AreEqual(@"x:\mydirectory\Directory4", result);
        }
示例#32
0
        public void GetFileByNameWithNull()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(fileSystem, @"x:\mydirectory");

            // Execute
            directory.File(a_name: null);
        }
示例#33
0
        public void GetName()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(fileSystem, "\\this\\is\\a\\directory");

            // Execute
            var result = directory.Name;

            // Assert
            Assert.AreEqual("directory", result);
        }
示例#34
0
        public void GetNotExistingChildDirectoryByName()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            fileSystem.CreateDirectory(@"x:\mydirectory\directory1");
            fileSystem.CreateDirectory(@"x:\mydirectory\directory2\child");
            fileSystem.CreateFile(@"x:\mydirectory\directory3\file.rgb", "Value");
            var directory = new PathDirectory<string>(fileSystem, @"x:\mydirectory");

            // Execute
            var result = directory.Directory("Directory4");

            // Assert
            Assert.AreEqual("Directory4", result.Name);
            Assert.IsFalse(result.Exists);
        }
示例#35
0
        /// <summary>
        /// 抓取相机的图像,输出Halcon格式
        /// </summary>
        public override ImageAll GrabImageHal()
        {
            ImageAll imageAll = new ImageAll();

            try
            {
                if (!BlOpen)
                {
                    return(null);
                }
#if (SDK)
                //★★★ 确保相机当前是采集状态 && 确保相机可以接收软件触发指令
                if (g_Camera != null && g_Camera.IsOpen)
                {
                    if (g_BaseParCamera.BlUsingTrigger)//使用软触发
                    {
                        if (ImageAll_Q.Count > 0)
                        {
                            ImageAll im = ImageAll_Q.Peek();
                            ImageAll_Q.Dequeue();      //出站
                            if (ImageAll_Q.Count > 20) //认为溢出
                            {
                                ImageAll_Q.Clear();
                                Log.L_I.WriteError(NameClass, "图像外触发溢出");
                            }
                            return(im);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        try
                        {
                            g_Camera.StreamGrabber.Start();
                            g_GrabResult = g_Camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
                        }
                        catch (Exception ex)
                        {
                            Log.L_I.WriteError(NameClass, ex);
                        }
                    }
                }

                using (g_GrabResult)
                {
                    if (g_GrabResult != null && g_GrabResult.GrabSucceeded)
                    {
                        imageAll.Ho_Image     = ConvertHobject(g_GrabResult);
                        imageAll.BitmapSource = null;

                        PathDirectory p = new PathDirectory();
                        imageAll.Time      = p.GetTimeName();
                        imageAll.TimeShort = p.GetShortTimeName();
                    }
                }
                g_Camera.StreamGrabber.Stop();
#endif
                return(imageAll);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(null);
            }
        }
示例#36
0
        public void DeleteDirectory()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(fileSystem, "\\this\\is\\a\\directory");
            directory.Create();

            // Execute
            directory.Delete();

            // Assert
            Assert.IsFalse(directory.Exists);
        }
示例#37
0
        public void DeleteNotExistingDirectory()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(fileSystem, "\\this\\is\\a\\directory");

            // Execute
            directory.Delete();
        }
示例#38
0
        public void GetParent()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(fileSystem, "\\this\\is\\a\\directory");

            // Execute
            var result = directory.Parent;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("a", result.Name);
        }
示例#39
0
        public void CustomTest_I()
        {
            var fileSystem = new PathTree<string>();
            fileSystem.CreateDirectory(@"\Root\Directory");
            fileSystem.CreateDirectory(@"\Root\Directory\Sub1");
            fileSystem.CreateDirectory(@"\Root\Directory\Sub2");
            fileSystem.CreateDirectory(@"\Root\Directory\Sub3");
            fileSystem.CreateFile(@"\Root\Directory\File1.hsf", "Value");
            fileSystem.CreateFile(@"\Root\Directory\File2.hsf", "Value");
            fileSystem.CreateFile(@"\Root\Directory\File3.hsf", "Value");

            var directory = new PathDirectory<string>(fileSystem, @"\");

            var result = directory.Directory(@"Root\Directory\Sub1").Exists;

            Assert.IsTrue(result);
        }
示例#40
0
        public void GetExistsWithNonexistingFile()
        {
            // Setup
            var fileSystem = new PathTree<string>();
            var directory = new PathDirectory<string>(fileSystem, "\\directory\\does\\not\\exist");

            // Execute
            var result = directory.Exists;

            // Assert
            Assert.IsFalse(result);
        }