Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用命令列表的自动化过程_C#_.net_Multithreading_Winforms_Teechart - Fatal编程技术网

C# 使用命令列表的自动化过程

C# 使用命令列表的自动化过程,c#,.net,multithreading,winforms,teechart,C#,.net,Multithreading,Winforms,Teechart,所以,我正在制作一个程序,旨在完成一些自动化过程。我有一个表单,允许用户构建定制的自动化流程。该自动化过程的结构如下所示: public class AutomationScript { public string FilePath; public List<AutomationEvent> Events; public AutomationScript() { Events =

所以,我正在制作一个程序,旨在完成一些自动化过程。我有一个表单,允许用户构建定制的自动化流程。该自动化过程的结构如下所示:

    public class AutomationScript
    {
        public string FilePath;
        public List<AutomationEvent> Events;

        public AutomationScript()
        {
            Events = new List<AutomationEvent>();
        }
    }

    public class AutomationCommand
    {
        public AutomationCommandType Type;
        public int Parameter;

        public AutomationCommand(AutomationCommandType _type, int _parameter)
        {
            Type = _type;
            Parameter = _parameter;
        }
    }

    public struct AutomationEvent
    {
        public string Name;
        public bool LoopEnabled;
        public List<AutomationCommand> Commands;
    }

    public enum AutomationCommandType
    {
        WaitSecs,
        CollectSample,
        CollectBackGround,
        StopCollection,
        LoopStart,
        LoopEnd,
    }
        private void runAutomationScript()
        {
            while (automationON)
            {
                foreach (AutomationEvent aEvent in fullAutomationScript.Events)
                {
                    int loopStartIndex = 0;
                    int loopEndIndex = 0;
                    foreach (AutomationCommand command in aEvent.Commands)
                    {
                        while (!CommandCompleted) { } //Will stay in loop until the hardware module is finished receiving spectra
                        switch (command.Type)
                        {
                            case AutomationCommandType.CollectBackGround:
                                RequestedBackgroundScans = command.Parameter;
                                spectralCollection.getBackGroundSpectra(RequestedBackgroundScans);
                                CommandCompleted = false;
                                break;
                            case AutomationCommandType.CollectSample:
                                RequestedSampleScans = command.Parameter;
                                spectralCollection.getSampleSpectra(RequestedSampleScans);
                                CommandCompleted = false;
                                break;
                            case AutomationCommandType.WaitSecs:
                                Thread.Sleep(command.Parameter * 1000);
                                break;
                            case AutomationCommandType.StopCollection:
                                automationON = false;
                                break;
                            case AutomationCommandType.LoopStart:
                                loopStartIndex = aEvent.Commands.IndexOf(command);
                                break;
                            case AutomationCommandType.LoopEnd:
                                loopEndIndex = aEvent.Commands.IndexOf(command);
                                //Wehn the loop end is reached it will get the index of the start and end and grab a sublist and iterate over that continuously.
                                int firstCommandIndex = loopStartIndex + 1;
                                List<AutomationCommand> loopedCommands = aEvent.Commands.GetRange(firstCommandIndex, loopEndIndex - firstCommandIndex );
                                break;

                        }
                    }
                }
            }
            OnAutomationFinished(EventArgs.Empty);
        }
公共类自动脚本
{
公共字符串文件路径;
公开活动清单;
公共自动化脚本()
{
事件=新列表();
}
}
公共类自动命令
{
公共自动化命令类型;
公共int参数;
公共自动命令(自动命令类型_类型,int参数)
{
类型=_类型;
参数=_参数;
}
}
公共结构自动事件
{
公共字符串名称;
启用公共bool循环;
公共列表命令;
}
公共枚举自动命令类型
{
服务员,
采集样本,
背景,,
停止收集,
循环启动,
LoopEnd,
}
现在,当用户启动流程以运行线程时,将创建一个线程,并通过命令进行迭代。基本设置如下所示:

    public class AutomationScript
    {
        public string FilePath;
        public List<AutomationEvent> Events;

        public AutomationScript()
        {
            Events = new List<AutomationEvent>();
        }
    }

    public class AutomationCommand
    {
        public AutomationCommandType Type;
        public int Parameter;

        public AutomationCommand(AutomationCommandType _type, int _parameter)
        {
            Type = _type;
            Parameter = _parameter;
        }
    }

    public struct AutomationEvent
    {
        public string Name;
        public bool LoopEnabled;
        public List<AutomationCommand> Commands;
    }

    public enum AutomationCommandType
    {
        WaitSecs,
        CollectSample,
        CollectBackGround,
        StopCollection,
        LoopStart,
        LoopEnd,
    }
        private void runAutomationScript()
        {
            while (automationON)
            {
                foreach (AutomationEvent aEvent in fullAutomationScript.Events)
                {
                    int loopStartIndex = 0;
                    int loopEndIndex = 0;
                    foreach (AutomationCommand command in aEvent.Commands)
                    {
                        while (!CommandCompleted) { } //Will stay in loop until the hardware module is finished receiving spectra
                        switch (command.Type)
                        {
                            case AutomationCommandType.CollectBackGround:
                                RequestedBackgroundScans = command.Parameter;
                                spectralCollection.getBackGroundSpectra(RequestedBackgroundScans);
                                CommandCompleted = false;
                                break;
                            case AutomationCommandType.CollectSample:
                                RequestedSampleScans = command.Parameter;
                                spectralCollection.getSampleSpectra(RequestedSampleScans);
                                CommandCompleted = false;
                                break;
                            case AutomationCommandType.WaitSecs:
                                Thread.Sleep(command.Parameter * 1000);
                                break;
                            case AutomationCommandType.StopCollection:
                                automationON = false;
                                break;
                            case AutomationCommandType.LoopStart:
                                loopStartIndex = aEvent.Commands.IndexOf(command);
                                break;
                            case AutomationCommandType.LoopEnd:
                                loopEndIndex = aEvent.Commands.IndexOf(command);
                                //Wehn the loop end is reached it will get the index of the start and end and grab a sublist and iterate over that continuously.
                                int firstCommandIndex = loopStartIndex + 1;
                                List<AutomationCommand> loopedCommands = aEvent.Commands.GetRange(firstCommandIndex, loopEndIndex - firstCommandIndex );
                                break;

                        }
                    }
                }
            }
            OnAutomationFinished(EventArgs.Empty);
        }
private void runAutomationScript()
{
while(自动开启)
{
foreach(fullAutomationScript.Events中的AutomationEvent aEvent)
{
int loopStartIndex=0;
int loopEndIndex=0;
foreach(aEvent.Commands中的AutomationCommand命令)
{
而(!CommandCompleted){}//将保持循环,直到硬件模块完成接收频谱
开关(命令类型)
{
案例自动命令类型.CollectBackGround:
RequestedBackgroundScans=command.Parameter;
光谱采集。获取背景光谱(请求背景扫描);
CommandCompleted=false;
打破
案例自动命令类型.CollectSample:
RequestedSampleScans=command.Parameter;
spectralCollection.getSampleSpectra(请求的采样罐);
CommandCompleted=false;
打破
案例自动命令类型.WaitSecs:
Thread.Sleep(command.Parameter*1000);
打破
案例自动命令类型.StopCollection:
自动ON=错误;
打破
案例自动命令类型.LoopStart:
loopStartIndex=aEvent.Commands.IndexOf(command);
打破
案例自动命令类型.LoopEnd:
loopEndIndex=aEvent.Commands.IndexOf(命令);
//当循环结束时,它将获得开始和结束的索引,并获取一个子列表并不断迭代。
int firstCommandIndex=loopStartIndex+1;
List loopedCommands=aEvent.Commands.GetRange(firstCommandIndex,loopEndIndex-firstCommandIndex);
打破
}
}
}
}
OnAutomationFinished(EventArgs.Empty);
}

现在,在这一点上,它运行良好。我试图允许用户定义一个循环点,让流程循环通过。如您所见,有一个名为
LoopStart
LoopEnd
自动命令。我试图弄清楚如何在不将代码复制到另一个函数的情况下循环第二个子循环。我正在考虑对这个命令循环进行一些递归定义。任何想法都会有帮助。

之所以使用
命令completed
,是因为光谱采集是由事件完成的。因此,当获取光谱数据的命令启动时,循环必须等到这些事件触发完成。这个问题引起了我的注意,因为它有TeeChart标签。我想知道TeeChart如何适合您的应用程序,以及您是否对其使用有任何疑问。提前谢谢。Teechart很棒。我对它的用法没有任何疑问,只有一个。我正在执行这个自动化过程,对吸收曲线进行量化分析,以测试气体杂质。我将这些结果存储在结果流(队列)中。无论如何,该应用程序是一个MDI光谱采集服务。每个mdi子级都包含一个图表。用户可以查看每摩尔或每组的浓度结果。我试图通过将所有图表系列放在一个位置,并在需要的任何地方绘制图表来简化一切。问题是,当我将一个系列应用于一个chrt时,它会被其他人拿走。如果需要,我希望能够在多个图表上绘制sme系列。事实是,一个系列只能分配给一个图表。至少我是这么认为的。因此,我必须在每个子系统中创建每个快速线的副本,并对主流以及每个子系统中的流进行一致性检查和更新。TeeChart系列将始终为要与图表关联或绘制的系列创建内部x、y和z(如果适用)数组。有一些有效的方法可以连接到另一个系列的数据,使用Series.Clone()方法或Copy函数将数据加载到数据集和系列中,并使用CheckDataSource()验证系列之间的一致性。我还将您的请求添加到bugzilla中,以考虑将其包含在未来的版本中: