我想让DM脚本不断获取相机图像,如视图模式。在我的计划中,当按下位于UIframe对话框的“开始”按钮时,就会开始连续获取相机;同时也会显示一个无模式对话框。当按下位于对话框中的OK按钮时,就会停止连续的触觉。对于这种脚本,我认为需要一个后台线程。然而,对于这样的背景运行,我还没有足够的知识。
如果你能分享一些智慧,我们会很感激的。先谢谢你。
发布于 2018-06-21 17:07:33
连续相机获取实际上与脚本中的后台线程无关,而是需要将硬件设置为连续读取模式。到目前为止,官方脚本API不支持此功能。
然而,有一个扩展的、面向对象的脚本API,它能更深入地控制摄像机.您需要在面向对象的DM脚本编写风格中具有通用性,才能使用它,并且需要与Gatan联系,以便可能访问此脚本API,因为它不受官方支持。
为此,您可能需要使用Gatan主页上的支援-申请表格。(页面底部的按钮)
发布于 2018-06-22 08:51:15
听听卡基古萨对我另一个答案的评论.
如果您想要伪连续地运行一个缓慢的摄像机捕获,即在一个单独的线程上执行重复的单个读取,那么您可能需要使用如下结构:
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")当然还有几个其他的构造,其中有一个对话框来管理一个单独的线程。这只是一个例子。
如果要启动/停止某项任务,执行时间非常定期,但需要主线程-另一个选项是从对话框中注册/取消注册定期任务。下面是一个示例:
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")https://stackoverflow.com/questions/50967468
复制相似问题