首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有dm-script非模态对话框的连续相机采集

带有dm-script非模态对话框的连续相机采集
EN

Stack Overflow用户
提问于 2018-06-21 11:28:51
回答 2查看 112关注 0票数 1

我想让DM脚本不断获取相机图像,如视图模式。在我的计划中,当按下位于UIframe对话框的“开始”按钮时,就会开始连续获取相机;同时也会显示一个无模式对话框。当按下位于对话框中的OK按钮时,就会停止连续的触觉。对于这种脚本,我认为需要一个后台线程。然而,对于这样的背景运行,我还没有足够的知识。

如果你能分享一些智慧,我们会很感激的。先谢谢你。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-21 17:07:33

连续相机获取实际上与脚本中的后台线程无关,而是需要将硬件设置为连续读取模式。到目前为止,官方脚本API不支持此功能。

然而,有一个扩展的、面向对象的脚本API,它能更深入地控制摄像机.您需要在面向对象的DM脚本编写风格中具有通用性,才能使用它,并且需要与Gatan联系,以便可能访问此脚本API,因为它不受官方支持。

为此,您可能需要使用Gatan主页上的支援-申请表格。(页面底部的按钮)

票数 1
EN

Stack Overflow用户

发布于 2018-06-22 08:51:15

听听卡基古萨对我另一个答案的评论.

如果您想要伪连续地运行一个缓慢的摄像机捕获,即在一个单独的线程上执行重复的单个读取,那么您可能需要使用如下结构:

代码语言:javascript
复制
class CMyBackgroundAction
{
    number isRunning
    CMyBackgroundAction(object self) { isRunning = 0; }     // Initialisation in constructor

    // methods to access flag from outside the object
    void StopRunning(object self) { isRunning  = 0; }
    number GetIsRunning(object self) { return isRunning; }

    // The stuff that should run in the background until the flag is set
    void RunUntilBreak(object self)
    {
        Result("\n\n StartRunning")
        isRunning = 1
        while (isRunning)
        {
            Result( "\n New line..." )
            sleep(0.5)
            Result( "....done" )
        }
        Result("\n\n FINISHED")
    }
}

class CmyDLG : UIframe
{
    object backGroundRunObj

    void OnStartStop( object self )
    {
        if ( !backGroundRunObj.GetIsRunning() )
        {
            // Nothing running in the background yet.
            backGroundRunObj.StartThread( "RunUntilBreak" )
            self.LookUpElement("StartStopButton").DLGTitle("Stop")
        }
        else
        {
            // It exists, so it is running. Just set the break-flag
            backgroundRunObj.StopRunning();
            self.LookUpElement("StartStopButton").DLGTitle("Start")
        }
    }

    TagGroup BuildDLG( object self )
    {
        TagGroup dlg, dlgitems
        dlg = DLGCreateDialog("StartStop",dlgItems)
        dlgItems.DLGAddElement( DLGCreatePushButton( "Start", "OnStartStop" ).DLGIdentifier("StartStopButton" ) )
        return dlg
    }
    Object Init(object self)
    {
        backGroundRunObj = Alloc(CMyBackgroundAction)
        self.super.Init( self.BuildDLG() )
        return self
    }
}

Alloc(CmyDLG).Init().Display("Test")

当然还有几个其他的构造,其中有一个对话框来管理一个单独的线程。这只是一个例子。

如果要启动/停止某项任务,执行时间非常定期,但需要主线程-另一个选项是从对话框中注册/取消注册定期任务。下面是一个示例:

代码语言:javascript
复制
class CMyBackgroundAction
{
    // The stuff that should run periodically
    void RunUntilBreak(object self)
    {
        Result("\n Doing action @" + GetTime(1) )
    }
}

class CmyDLG : UIframe
{
    object backGroundRunObj
    number taskID

    void OnStartStop( object self )
    {
        if ( 0 == taskID )
        {
            // Start by registering the task ( every 0.5 sec)
            taskID = AddMainThreadPeriodicTask(backGroundRunObj,"RunUntilBreak",0.5)
            Result("\n STARTED ")
            self.LookUpElement("StartStopButton").DLGTitle("Stop")
        }
        else
        {
            // Stop by removing the task
            RemoveMainThreadTask( taskID )
            Result("\n STOPPED ")
            taskID = 0
            self.LookUpElement("StartStopButton").DLGTitle("Start")
        }
    }

    TagGroup BuildDLG( object self )
    {
        TagGroup dlg, dlgitems
        dlg = DLGCreateDialog("StartStop",dlgItems)
        dlgItems.DLGAddElement( DLGCreatePushButton( "Start", "OnStartStop" ).DLGIdentifier("StartStopButton" ) )
        return dlg
    }
    Object Init(object self)
    {
        backGroundRunObj = Alloc(CMyBackgroundAction)
        taskID = 0
        return self.super.Init( self.BuildDLG() )
    }
}

Alloc(CmyDLG).Init().Display("Test")
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50967468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档