示例#1
0
 /// <summary>
 ///     协议构造器
 /// </summary>
 /// <param name="tagGeter">如何通过BaseMachine和AddressUnit构造Opc的标签</param>
 /// <param name="machine">调用这个编码器的设备</param>
 /// <param name="seperator">每两个标签之间用什么符号隔开,默认为/</param>
 public AddressFormaterOpc(Func <BaseMachine <TMachineKey, TUnitKey>, AddressUnit <TUnitKey>, string[]> tagGeter,
                           BaseMachine <TMachineKey, TUnitKey> machine,
                           char seperator = '/')
 {
     Machine   = machine;
     TagGeter  = tagGeter;
     Seperator = seperator;
 }
示例#2
0
        public void Init()
        {
            _modbusTcpMachine = new ModbusMachine(ModbusType.Tcp, "192.168.3.10", null, true, 2, 0);

            _modbusRtuMachine = new ModbusMachine(ModbusType.Rtu, "COM3", null, true, 2, 0);

            _modbusAsciiMachine = new ModbusMachine(ModbusType.Ascii, "COM5", null, true, 2, 0);
        }
示例#3
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="tree">The underlying tree.</param>
 /// <param name="location">The machine's in-game location.</param>
 /// <param name="tile">The tree's tile position.</param>
 public TreeMachine(Tree tree, GameLocation location, Vector2 tile)
     : base(tree, location, BaseMachine.GetTileAreaFor(tile))
 {
     this.ItemDrops = new Cached <Stack <int> >(
         getCacheKey: () => $"{Game1.currentSeason},{Game1.dayOfMonth},{tree.hasSeed.Value}",
         fetchNew: () => new Stack <int>()
         );
 }
示例#4
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="mill">The underlying mill.</param>
 /// <param name="location">The location which contains the machine.</param>
 public MillMachine(Mill mill, GameLocation location)
     : base(mill, location, BaseMachine.GetTileAreaFor(mill))
 {
     this.MaxInputStackSize = new Dictionary <int, int>
     {
         [284] = new SObject(284, 1).maximumStackSize() / 3 // beet => 3 sugar (reduce stack to avoid overfilling output)
     };
 }
示例#5
0
        public ModbusTest()
        {
            _modbusTcpMachine = new ModbusMachine(ModbusTransportType.Tcp, LOCAL_ADDR_1, null, true, 2, 0);

            _modbusRtuMachine = new ModbusMachine(ModbusTransportType.Rtu, "COM3", null, true, 2, 0);

            _modbusAsciiMachine = new ModbusMachine(ModbusTransportType.Ascii, "COM5", null, true, 2, 0);
        }
示例#6
0
        public BarnMachine(Barn barn, GameLocation location) : base(barn, location, BaseMachine.GetTileAreaFor(barn))
        {
            if (barn.indoors.Value is AnimalHouse)
            {
                this.AnimalHouse = (AnimalHouse)barn.indoors.Value;
            }

            this.UnprocessedAnimals = new List <FarmAnimal>();
            this.FindUnprocessedAnimals();
        }
示例#7
0
        /// <summary>
        /// Notify that the task received an event that it was waiting for.
        /// </summary>
        /// <param name="machine">Machine</param>
        internal void NotifyTaskReceivedEvent(BaseMachine machine)
        {
            var taskInfo = this.GetTaskFromMachine(machine);

            Output.Debug("<ScheduleDebug> Task {0} of machine {1}({2}) " +
                         "received an event and unblocked.", taskInfo.Id, taskInfo.Machine.GetType(),
                         taskInfo.Machine.Id.MVal);

            taskInfo.IsWaiting = false;
        }
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="town">The town to search.</param>
 /// <param name="tile">The machine's position in its location.</param>
 /// <param name="trashCanIndex">The trash can index.</param>
 /// <param name="reflection">Simplifies access to private game code.</param>
 public TrashCanMachine(Town town, Vector2 tile, int trashCanIndex, IReflectionHelper reflection)
     : base(town, BaseMachine.GetTileAreaFor(tile))
 {
     this.Tile             = tile;
     this.TrashCansChecked = reflection.GetField <IList <bool> >(town, "garbageChecked").GetValue();
     if (trashCanIndex >= 0 && trashCanIndex < this.TrashCansChecked.Count)
     {
         this.TrashCanIndex = trashCanIndex;
     }
 }
示例#9
0
        public static bool SaveMachineState(BaseMachine machine)
        {
            bool bResult = true;

            bResult &= SerializeUtil.
                       SerializableObject(WorksheetNoPath, machine.WorksheetNo);
            bResult &= SerializeUtil.
                       SerializableObject(ProductionInfoPath, machine.ProductionInfo);
            return(bResult);
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="machine"></param>
        public static void RecoveryMachineState(BaseMachine machine)
        {
            machine.WorksheetNo =
                SerializeUtil.DeserializableObject <string>(WorksheetNoPath);

            machine.ProductionInfo = SerializeUtil.
                                     DeserializableObject <MachineProductionInfo>(ProductionInfoPath);
            if (machine.ProductionInfo != null)
            {
                machine.ProductionInfo.InitializeProductionInfo();
            }
        }
示例#11
0
        /// <summary>
        /// Creates a scheduling choice trace step.
        /// </summary>
        /// <param name="index">Index</param>
        /// <param name="scheduledMachine">Scheduled machine</param>
        /// <returns>TraceStep</returns>
        internal static TraceStep CreateSchedulingChoice(int index, BaseMachine scheduledMachine)
        {
            var traceStep = new TraceStep();

            traceStep.Index            = index;
            traceStep.Type             = TraceStepType.SchedulingChoice;
            traceStep.ScheduledMachine = scheduledMachine;

            traceStep.Previous = null;
            traceStep.Next     = null;

            return(traceStep);
        }
示例#12
0
    ///
    /// Create utility class which has menu item function to create an asset file.
    ///
    protected override void CreateAssetCreationScript(BaseMachine m, ScriptPrescription sp)
    {
        sp.className               = machine.WorkSheetName;
        sp.worksheetClassName      = machine.WorkSheetName;
        sp.assetFileCreateFuncName = "Create" + machine.WorkSheetName + "AssetFile";
        sp.template = GetTemplate("AssetFileClass");

        // write a script to the given folder.
        using (var writer = new StreamWriter(TargetPathForAssetFileCreateFunc(machine.WorkSheetName)))
        {
            writer.Write(new NewScriptGenerator(sp).ToString());
            writer.Close();
        }
    }
示例#13
0
 /// <summary>
 /// 创建默认的机台页面
 /// </summary>
 private void InitializeDefaultMachineView()
 {
     // 创建默认的机台页面
     if (!Configuration.MachineMap.ContainsKey(Configuration.DefaultMachine) ||
         (BaseMachine = GetMachineViewByTypeId(Configuration.MachineMap[
                                                   Configuration.DefaultMachine].MachineTypeID)) == null)
     {
         System.Windows.MessageBox.Show("配置文件的默认机台信息有误!",
                                        "错误提示", MessageBoxButton.OK, MessageBoxImage.Error);
         System.Environment.Exit(0);
     }
     BaseMachine.MachineName = Configuration.DefaultMachine;
     pageContainer.Children.Insert(0, BaseMachine); //将机台页面添加到主界面
 }
示例#14
0
        /// <summary>
        /// Returns the task id of the given machine.
        /// </summary>
        /// <param name="machine">Machine</param>
        /// <returns>TaskId</returns>
        protected TaskInfo GetTaskFromMachine(BaseMachine machine)
        {
            TaskInfo taskInfo = null;

            foreach (var task in this.Tasks)
            {
                if (task.Machine.Equals(machine))
                {
                    taskInfo = task;
                    break;
                }
            }

            return(taskInfo);
        }
示例#15
0
        /// <summary>
        /// Notify that a new task has been created for the given machine.
        /// </summary>
        /// <param name="id">TaskId</param>
        /// <param name="machine">Machine</param>
        internal virtual void NotifyNewTaskCreated(int id, BaseMachine machine)
        {
            var taskInfo = new TaskInfo(id, machine);

            Output.Debug("<ScheduleDebug> Created task {0} for machine {1}({2}).",
                         taskInfo.Id, taskInfo.Machine.GetType(), taskInfo.Machine.Id.MVal);

            if (this.Tasks.Count == 0)
            {
                taskInfo.IsActive = true;
            }

            this.Tasks.Add(taskInfo);
            this.TaskMap.Add(id, taskInfo);
        }
示例#16
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="id">TaskId</param>
        /// <param name="machine">Machine</param>
        internal TaskInfo(int id, BaseMachine machine)
        {
            this.Id          = id;
            this.Machine     = machine;
            this.IsEnabled   = true;
            this.IsWaiting   = false;
            this.IsBlocked   = false;
            this.IsActive    = false;
            this.HasStarted  = false;
            this.IsCompleted = false;

            this.BlockingWrappedTasks   = new List <TaskInfo>();
            this.BlockingUnwrappedTasks = new List <Task>();
            this.WaitAll = false;
        }
示例#17
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="id">TaskId</param>
        /// <param name="machine">Machine</param>
        internal TaskInfo(int id, BaseMachine machine)
        {
            this.Id = id;
            this.Machine = machine;
            this.IsEnabled = true;
            this.IsWaiting = false;
            this.IsBlocked = false;
            this.IsActive = false;
            this.HasStarted = false;
            this.IsCompleted = false;

            this.BlockingWrappedTasks = new List<TaskInfo>();
            this.BlockingUnwrappedTasks = new List<Task>();
            this.WaitAll = false;
        }
示例#18
0
        /// <summary>
        /// Determines whether the specified System.Object is equal
        /// to the current System.Object.
        /// </summary>
        /// <param name="obj">Object</param>
        /// <returns>Boolean value</returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            BaseMachine m = obj as BaseMachine;

            if (m == null ||
                this.GetType() != m.GetType())
            {
                return(false);
            }

            return(this.Id.Value == m.Id.Value);
        }
    protected void DrawHeaderSetting(BaseMachine m)
    {
        if (m.HasHeadColumn())
        {
            GUIStyle headerStyle = GUIHelper.MakeHeader();
            GUILayout.Label("Type Settings:", headerStyle);

            const int MEMBER_WIDTH = 100;
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.Label("Member", GUILayout.MinWidth(MEMBER_WIDTH));
            GUILayout.FlexibleSpace();
            string[] names  = { "Type", "Array" };
            int[]    widths = { 55, 40 };
            for (int i = 0; i < names.Length; i++)
            {
                GUILayout.Label(new GUIContent(names[i]), GUILayout.Width(widths[i]));
            }
            GUILayout.EndHorizontal();//EditorStyles.toolbar

            //curretScroll = EditorGUILayout.BeginScrollView(curretScroll, false, false);
            EditorGUILayout.BeginVertical("box");

            //string lastCellName = string.Empty;
            foreach (HeaderColumn header in m.HeaderColumnList)
            {
                GUILayout.BeginHorizontal();

                // member field label
                EditorGUILayout.LabelField(header.name, GUILayout.MinWidth(MEMBER_WIDTH));
                GUILayout.FlexibleSpace();

                // type enum popup
                header.type = (CellType)EditorGUILayout.EnumPopup(header.type, GUILayout.Width(60));
                GUILayout.Space(20);

                // array toggle
                header.isArray = EditorGUILayout.Toggle(header.isArray, GUILayout.Width(20));
                GUILayout.Space(10);
                GUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical(); //box
            //EditorGUILayout.EndScrollView();
        }
    }
示例#20
0
        /// <summary>
        /// </summary>
        /// <param name="machine"></param>
        /// <param name="commonProperties"></param>
        /// <param name="broker"></param>
        /// <exception cref="ArgumentOutOfRangeException">Condition.</exception>
        /// <exception cref="ArgumentNullException">value is <see langword="null"/></exception>
        protected BaseTrain(BaseMachine
                            machine, BaseTrainParametres commonProperties, EventBroker broker)
        {
            CarLength                    = commonProperties.CarLength;
            UnladenWeight                = commonProperties.UnladenWeight;
            NumberCars                   = commonProperties.NumberCars;
            BreakAverage                 = commonProperties.BAverage;
            NetResistencePullFactor      = commonProperties.NetResistencePullFactor;
            AerodynamicDragFactor        = commonProperties.AerodynamicDragFactor;
            NetResistenceCoastingFactor1 = commonProperties.NetResistenceCoastingFactor1;
            NetResistenceCoastingFactor2 = commonProperties.NetResistenceCoastingFactor2;
            NetResistenceCoastingFactor3 = commonProperties.NetResistenceCoastingFactor3;
            TrainEqvivalentSurface       = commonProperties.TrainEqvivalentSurface;
            InertiaRotationFactor        = commonProperties.InertiaRotationFactor;
            OwnNeedsElectricPower        = commonProperties.OwnNeedsElectricPower;

            Machine = machine;
            Broker  = broker;
        }
示例#21
0
    /// <summary>
    /// Create a ScriptableObject editor class and write it down on the specified folder.
    /// </summary>
    protected void CreateScriptableObjectEditorClassScript(BaseMachine machine, ScriptPrescription sp)
    {
        sp.className          = machine.WorkSheetName + "Editor";
        sp.worksheetClassName = machine.WorkSheetName;
        sp.dataClassName      = machine.WorkSheetName + "Data";
        sp.template           = GetTemplate("ScriptableObjectEditorClass");

        // check the directory path exists
        string fullPath   = TargetPathForEditorScript(machine.WorkSheetName);
        string folderPath = Path.GetDirectoryName(fullPath);

        if (!Directory.Exists(folderPath))
        {
            EditorUtility.DisplayDialog(
                "Warning",
                "The folder for editor script files does not exist. Check the path " + folderPath + " exists.",
                "OK"
                );
            return;
        }

        StreamWriter writer = null;

        try
        {
            // write a script to the given folder.
            writer = new StreamWriter(fullPath);
            writer.Write(new NewScriptGenerator(sp).ToString());
        }
        catch (System.Exception e)
        {
            Debug.LogError(e);
        }
        finally
        {
            if (writer != null)
            {
                writer.Close();
                writer.Dispose();
            }
        }
    }
        /// <summary>
        /// Notify that a new task has been created for the given machine.
        /// </summary>
        /// <param name="id">TaskId</param>
        /// <param name="machine">Machine</param>
        internal override void NotifyNewTaskCreated(int id, BaseMachine machine)
        {
            var taskInfo = new TaskInfo(id, machine);

            Output.Debug("<ScheduleDebug> Created task {0} for machine {1}({2}).",
                taskInfo.Id, taskInfo.Machine.GetType(), taskInfo.Machine.Id.MVal);

            if (this.Tasks.Count == 0)
            {
                taskInfo.IsActive = true;
            }

            this.Tasks.Add(taskInfo);
            this.TaskMap.Add(id, taskInfo);

            if (machine is TaskMachine)
            {
                this.WrappedTaskMap.Add((machine as TaskMachine).WrappedTask.Id, taskInfo);
            }
        }
示例#23
0
    /// <summary>
    /// Create a data class which describes the spreadsheet and write it down on the specified folder.
    /// </summary>
    protected void CreateDataClassScript(BaseMachine machine, ScriptPrescription sp)
    {
        // check the directory path exists
        string fullPath   = TargetPathForData(machine.WorkSheetName);
        string folderPath = Path.GetDirectoryName(fullPath);

        if (!Directory.Exists(folderPath))
        {
            EditorUtility.DisplayDialog(
                "Warning",
                "The folder for runtime script files does not exist. Check the path " + folderPath + " exists.",
                "OK"
                );
            return;
        }

        List <MemberFieldData> fieldList = new List <MemberFieldData>();

        //FIXME: replace ValueType to CellType and support Enum type.
        foreach (HeaderColumn header in machine.HeaderColumnList)
        {
            MemberFieldData member = new MemberFieldData();
            member.Name        = header.name;
            member.type        = header.type;
            member.IsArrayType = header.isArray;

            fieldList.Add(member);
        }

        sp.className = machine.WorkSheetName + "Data";
        sp.template  = GetTemplate("DataClass");

        sp.memberFields = fieldList.ToArray();

        // write a script to the given folder.
        using (var writer = new StreamWriter(fullPath))
        {
            writer.Write(new NewScriptGenerator(sp).ToString());
            writer.Close();
        }
    }
示例#24
0
        private void GetMachineEnter()
        {
            machine = new ModbusMachine(ModbusType.Tcp, "192.168.3.12", new List <AddressUnit>()
            {
                new AddressUnit()
                {
                    Id = "1", Area = "MW", Address = 1, CommunicationTag = "Add1", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0
                },
                new AddressUnit()
                {
                    Id = "2", Area = "MW", Address = 2, CommunicationTag = "Add2", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0
                },
                new AddressUnit()
                {
                    Id = "3", Area = "MW", Address = 3, CommunicationTag = "Add3", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0
                },
                new AddressUnit()
                {
                    Id = "4", Area = "MW", Address = 4, CommunicationTag = "Ans", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0
                },
            });
            machine.AddressFormater    = new AddressFormaterNA200H();
            machine.AddressTranslator  = new AddressTranslatorNA200H();
            machine.AddressCombiner    = new AddressCombinerContinus(machine.AddressTranslator);
            machine.AddressCombinerSet = new AddressCombinerContinus(machine.AddressTranslator);
            //machine = new SiemensMachine(SiemensType.Tcp, "192.168.3.11:102", SiemensMachineModel.S7_300, new List<AddressUnit>()
            //{
            //new AddressUnit() {Id = "1", Area = "V", Address = 0, CommunicationTag = "Add1", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
            //new AddressUnit() {Id = "2", Area = "V", Address = 2, CommunicationTag = "Add2", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
            //new AddressUnit() {Id = "3", Area = "V", Address = 4, CommunicationTag = "Add3", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
            //new AddressUnit() {Id = "4", Area = "V", Address = 6, CommunicationTag = "Ans",  DataType = typeof(ushort), Zoom = 1, DecimalPos = 0}
            //});
            //machine.AddressCombiner = new AddressCombinerContinus();
            var result       = machine.GetDatas(MachineGetDataType.CommunicationTag);
            var resultFormat = BaseMachine.MapGetValuesToSetValues(result);

            SetValue(new ushort[4] {
                (ushort)resultFormat["Add1"], (ushort)resultFormat["Add2"], (ushort)resultFormat["Add3"], (ushort)resultFormat["Ans"]
            });
        }
示例#25
0
 public static void readMachine(BaseMachine baseMachine)
 {
     if (ct != null)
     {
         ct = new List <CellType>();
     }
     else
     {
         ct.Clear();
     }
     if (iarr != null)
     {
         iarr = new List <bool>();
     }
     else
     {
         iarr.Clear();
     }
     for (var i = 0; i < baseMachine.ColumnHeaderList.Count; i++)
     {
         ct.Add(baseMachine.ColumnHeaderList[i].type);
         iarr.Add(baseMachine.ColumnHeaderList[i].isArray);
     }
 }
示例#26
0
    /// <summary>
    /// Generate script files with the given templates.
    /// Total four files are generated, two for runtime and others for editor.
    /// </summary>
    protected virtual ScriptPrescription Generate()
    {
        ScriptPrescription sp = new ScriptPrescription();

        if (machine == null)
        {
            machine = target as BaseMachine;
        }

        if (machine.onlyCreateDataClass)
        {
            CreateDataClassScript(sp);
        }
        else
        {
            CreateScriptableObjectClassScript(sp);
            CreateScriptableObjectEditorClassScript(sp);
            CreateDataClassScript(sp);
        }

        AssetDatabase.Refresh();

        return(sp);
    }
示例#27
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="location">The location containing the machine.</param>
 /// <param name="tile">The tile covered by the machine.</param>
 public FeedHopperMachine(GameLocation location, Vector2 tile)
     : base(location, BaseMachine.GetTileAreaFor(tile))
 {
 }
示例#28
0
 /// <summary>Construct an instance.</summary>
 /// <param name="silo">The silo to automate.</param>
 /// <param name="location">The location containing the machine.</param>
 public FeedHopperMachine(Building silo, GameLocation location)
     : base(location, BaseMachine.GetTileAreaFor(silo))
 {
 }
示例#29
0
        /// <summary>
        /// Returns the task id of the given machine.
        /// </summary>
        /// <param name="machine">Machine</param>
        /// <returns>TaskId</returns>
        protected TaskInfo GetTaskFromMachine(BaseMachine machine)
        {
            TaskInfo taskInfo = null;
            foreach (var task in this.Tasks)
            {
                if (task.Machine.Equals(machine))
                {
                    taskInfo = task;
                    break;
                }
            }

            return taskInfo;
        }
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="miniBin">The mini-shipping bin.</param>
 /// <param name="location">The location which contains the machine.</param>
 public MiniShippingBinMachine(Chest miniBin, GameLocation location)
     : base(location, BaseMachine.GetTileAreaFor(miniBin.TileLocation))
 {
     this.MiniBin = new ChestContainer(miniBin, location, miniBin.TileLocation, migrateLegacyOptions: false);
 }
示例#31
0
 /// <summary>
 ///     协议构造器
 /// </summary>
 /// <param name="tagGeter">如何通过BaseMachine和AddressUnit构造Opc的标签</param>
 /// <param name="machine">调用这个编码器的设备</param>
 /// <param name="seperator">每两个标签之间用什么符号隔开,默认为/</param>
 public AddressFormaterOpc(Func <BaseMachine, AddressUnit, string[]> tagGeter, BaseMachine machine,
                           char seperator = '/')
 {
     Machine   = machine;
     TagGeter  = tagGeter;
     Seperator = seperator;
 }
示例#32
0
        public BaseTest()
        {
            _addressUnits = new List <AddressUnit <int> >
            {
                new AddressUnit <int>
                {
                    Id         = 1,
                    Area       = "3X",
                    Address    = 1,
                    SubAddress = 0,
                    DataType   = typeof(bool)
                },
                new AddressUnit <int>
                {
                    Id         = 2,
                    Area       = "3X",
                    Address    = 1,
                    SubAddress = 1,
                    DataType   = typeof(bool)
                },
                new AddressUnit <int>
                {
                    Id         = 3,
                    Area       = "3X",
                    Address    = 1,
                    SubAddress = 2,
                    DataType   = typeof(bool)
                },
                new AddressUnit <int>
                {
                    Id         = 4,
                    Area       = "3X",
                    Address    = 2,
                    SubAddress = 0,
                    DataType   = typeof(byte)
                },
                new AddressUnit <int>
                {
                    Id         = 5,
                    Area       = "3X",
                    Address    = 2,
                    SubAddress = 8,
                    DataType   = typeof(byte)
                },
                new AddressUnit <int>
                {
                    Id         = 6,
                    Area       = "3X",
                    Address    = 3,
                    SubAddress = 0,
                    DataType   = typeof(ushort)
                },
                new AddressUnit <int>
                {
                    Id         = 7,
                    Area       = "3X",
                    Address    = 4,
                    SubAddress = 0,
                    DataType   = typeof(ushort)
                },
                new AddressUnit <int>
                {
                    Id         = 8,
                    Area       = "3X",
                    Address    = 6,
                    SubAddress = 0,
                    DataType   = typeof(ushort)
                },
                new AddressUnit <int>
                {
                    Id         = 9,
                    Area       = "3X",
                    Address    = 9,
                    SubAddress = 0,
                    DataType   = typeof(ushort)
                },
                new AddressUnit <int>
                {
                    Id         = 10,
                    Area       = "3X",
                    Address    = 10,
                    SubAddress = 0,
                    DataType   = typeof(ushort)
                },
                new AddressUnit <int>
                {
                    Id         = 11,
                    Area       = "3X",
                    Address    = 100,
                    SubAddress = 0,
                    DataType   = typeof(ushort)
                },
                new AddressUnit <int>
                {
                    Id         = 12,
                    Area       = "4X",
                    Address    = 1,
                    SubAddress = 0,
                    DataType   = typeof(uint)
                },
                new AddressUnit <int>
                {
                    Id         = 13,
                    Area       = "4X",
                    Address    = 4,
                    SubAddress = 0,
                    DataType   = typeof(ushort)
                },
            };

            _baseMachine = new ModbusMachine <int, int>(ModbusTransportType.Tcp, LOCAL_ADDR_1, _addressUnits, true, 2, 0)
            {
                Id          = 1,
                ProjectName = "Project 1",
                MachineName = "Test 1"
            };
        }
示例#33
0
 public void AddMachine(BaseMachine machine)
 {
     machine.KeepConnect = KeepConnect;
     lock (_machines)
     {
         _machines.Add(machine);
     }
 }
示例#34
0
 public void RemoveMachine(BaseMachine machine)
 {
     lock (_machines)
     {
         _machines.Remove(machine);
     }
 }
示例#35
0
 private async Task RunTask(BaseMachine machine)
 {
     try
     {
         //var ans = machine.GetDatas();
         CancellationTokenSource cts = new CancellationTokenSource();
         cts.CancelAfter(TimeSpan.FromSeconds(_getCycle));
         var ans = await machine.GetDatasAsync().WithCancellation(cts.Token);
         if (!machine.IsConnected)
         {
             MoveMachineToUnlinked(machine.Id);
         }
         else
         {
             MoveMachineToLinked(machine.Id);
         }
         if (ReturnValues != null)
         {
             ReturnValues(new KeyValuePair<int, Dictionary<string,ReturnUnit>>(machine.Id, ans));
         }
     }
     catch (Exception e)
     {
         if (!machine.IsConnected)
         {
             MoveMachineToUnlinked(machine.Id);
         }
         if (ReturnValues != null)
         {
             ReturnValues(new KeyValuePair<int, Dictionary<string,ReturnUnit>>(machine.Id, null));
         }
     }
 }
    /// Create utility class which has menu item function to create an asset file.
    protected override void CreateAssetCreationScript(BaseMachine m, ScriptPrescription sp)
    {
        sp.className = machine.WorkSheetName;
        sp.worksheetClassName = machine.WorkSheetName;
        sp.assetFileCreateFuncName = "Create" + machine.WorkSheetName + "AssetFile";
        sp.template = GetTemplate("AssetFileClass");

        // write a script to the given folder.
        using (var writer = new StreamWriter(TargetPathForAssetFileCreateFunc(machine.WorkSheetName))) {
            writer.Write(new NewScriptGenerator(sp).ToString());
            writer.Close();
        }
    }
示例#37
0
        /// <summary>
        /// Notify that the task received an event that it was waiting for.
        /// </summary>
        /// <param name="machine">Machine</param>
        internal void NotifyTaskReceivedEvent(BaseMachine machine)
        {
            var taskInfo = this.GetTaskFromMachine(machine);

            Output.Debug("<ScheduleDebug> Task {0} of machine {1}({2}) " +
                "received an event and unblocked.", taskInfo.Id, taskInfo.Machine.GetType(),
                taskInfo.Machine.Id.MVal);

            taskInfo.IsWaiting = false;
        }
示例#38
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="tree">The underlying fruit tree.</param>
 /// <param name="location">The machine's in-game location.</param>
 /// <param name="tile">The tree's tile position.</param>
 public FruitTreeMachine(FruitTree tree, GameLocation location, Vector2 tile)
     : base(tree, location, BaseMachine.GetTileAreaFor(tile))
 {
 }
示例#39
0
 /// <summary>
 /// Checks if there is already an enabled task for the given machine.
 /// </summary>
 /// <param name="machine">Machine</param>
 /// <returns>Boolean</returns>
 internal bool HasEnabledTaskForMachine(BaseMachine machine)
 {
     var enabledTasks = this.Tasks.Where(task => task.IsEnabled).ToList();
     return enabledTasks.Any(task => task.Machine.Equals(machine));
 }