public static void Import(string type, string line, Station station)
        {
            switch (type)
            {
            case "STATIONTASK":
            {
                var data        = line.Split(' ');
                int i           = 0;
                var id          = int.Parse(data[i++]);
                var name        = data[i++];
                var index       = int.Parse(data[i++]);
                var desc        = data[i++];
                var stationName = data[i++];
                var typeName    = data[i++];

                //create task and bind to station
                if (FrameworkManager.TaskTypes.ContainsKey(typeName))
                {
                    var task = Activator.CreateInstance(FrameworkManager.TaskTypes[typeName], new object[] { id, name, station });
                    //bind to machine
                    station.Machine.Tasks.Add(id, task as StationTask);
                }
            }
            break;

            case "PAUSESIGNAL":
            {
                var data = line.Split(' ');
                if (data.Length == 7)
                {
                    //load pause signal
                    IDiEx di = new DiEx();
                    di.Import(line, station.Machine);
                    di = station.Machine.Find <IDiEx>(di.Name);
                    station.PauseSignals.Add(station.PauseSignals.Count + 1, di);
                }
            }
            break;
            }
        }
Exemple #2
0
        public void ParseContent(StateMachine machine, string line)
        {
            if (Section != "PLATFORM")
            {
                if (line.Length == 0)
                {
                    //read next line
                    return;
                }
            }


            switch (Section)
            {
            case "MOTION":
                new MotionCardWrapper().Import(line, machine);
                break;

            case "DI":
                new DiEx().Import(line, machine);
                break;

            case "ESTOP":
            case "START":
            case "STOP":
            case "RESET":
                DiEx.Import(Section, line, machine);
                break;

            case "DO":
                new DoEx().Import(line, machine);
                break;

            case "LIGHTGREEN":
            case "LIGHTYELLOW":
            case "LIGHTRED":
            case "BUZZER":
                DoEx.Import(Section, line, machine);
                break;

            case "CY":
                new CylinderEx().Import(line, machine);
                break;

            case "VIO":
                new VioEx().Import(line, machine);
                break;

            case "AXIS":
                new AxisEx().Import(line, machine);
                break;

            case "PLATFORM":
                if (string.IsNullOrEmpty(IndentSection))
                {
                    IndentSection = line.Split(' ')[1];
                    PlatformEx.Import(line, machine);
                    _indentIndex = 0;
                }
                else
                {
                    if (line.StartsWith("NULL") || line.StartsWith("null") || line.StartsWith("Null"))
                    {
                        var platform = machine.Platforms.Values.FirstOrDefault(p => p.Name == IndentSection);
                        if (platform != null)
                        {
                            platform.Axis[_indentIndex] = null;
                        }

                        _indentIndex++;
                    }
                    else
                    {
                        IAxisEx axis = new AxisEx();
                        axis.Import(line, machine);
                        axis = machine.Find <IAxisEx>(axis.Name);

                        var platform = machine.Platforms.Values.FirstOrDefault(p => p.Name == IndentSection);
                        if (platform != null)
                        {
                            platform.Axis[_indentIndex] = axis;
                        }

                        _indentIndex++;
                    }
                }

                break;

            case "STATION":
                if (string.IsNullOrEmpty(IndentSection))
                {
                    IndentSection = line.Split(' ')[1];
                    Station.Import("STATION", line, machine);
                }
                else
                {
                    var data = line.Split(' ');
                    if (data.Length == 6)
                    {
                        //import task
                        Station.Import("STATIONTASK", line, machine.Find <Station>(IndentSection));
                    }
                    else if (data.Length == 7)
                    {
                        //import pause signal
                        Station.Import("PAUSESIGNAL", line, machine.Find <Station>(IndentSection));
                    }
                    else
                    {
                        throw new Exception($"{Section} {line} FORMAT ERROR");
                    }
                }

                break;

            default:
                throw new Exception($"Not Support Section - {Section}");
            }
        }