Example #1
0
        public void Prg_TestVariables()
        {
            var prg = Prg.Load(TestUtilities.GetFullPathForPrgFile("testvariables.prg"));

            var variable1 = prg.Variables[0];

            Assert.AreEqual("FirstDescription    ", variable1.Description);
            Assert.AreEqual("FirstLabe", variable1.Label);
            Assert.AreEqual(new VariableValue(5.0, Unit.DegreesC), variable1.Value);
            Assert.AreEqual(AutoManual.Automatic, variable1.AutoManual);
            Assert.AreEqual(DigitalAnalog.Analog, variable1.DigitalAnalog);
            Assert.AreEqual(OffOn.Off, variable1.Control);

            var variable2 = prg.Variables[1];

            Assert.AreEqual("SecondDescription   ", variable2.Description);
            Assert.AreEqual("SecondLab", variable2.Label);
            ObjectAssert.AreEqual(new VariableValue("On", Unit.OffOn).Value, variable2.Value.Value);
            Assert.AreEqual(AutoManual.Manual, variable2.AutoManual);
            Assert.AreEqual(DigitalAnalog.Digital, variable2.DigitalAnalog);
            Assert.AreEqual(OffOn.Off, variable2.Control);

            var variable3 = prg.Variables[2];

            Assert.AreEqual("ThirdDescription    ", variable3.Description);
            Assert.AreEqual("ThirdLabe", variable3.Label);
            Assert.AreEqual(new VariableValue(new TimeSpan(0, 22, 22, 22, 0), Unit.Time), variable3.Value);
            Assert.AreEqual(AutoManual.Automatic, variable3.AutoManual);
            Assert.AreEqual(DigitalAnalog.Analog, variable3.DigitalAnalog);
            Assert.AreEqual(OffOn.Off, variable3.Control);
        }
Example #2
0
        private void SaveAsPrg(object sender, EventArgs e)
        {
            if (!IsOpened)
            {
                statusLabel.Text = Resources.FileIsNotOpen;
                return;
            }

            var dialog = new SaveFileDialog();

            dialog.Filter = $"{Resources.PrgFiles}|*.prg;*.prog|{Resources.AllFiles} (*.*)|*.*";
            dialog.Title  = Resources.SavePrgFile;
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var path = dialog.FileName;

            try
            {
                Prg.Save(path);
                statusLabel.Text = string.Format(Resources.Saved, path);
            }
            catch (Exception exception)
            {
                MessageBoxUtilities.ShowException(exception);
            }
        }
        public void StartTypeChecking(Prg tree)
        {
            // main class
            TypeChecking(tree.MainClass.Statement, tree.MainClass.Name, "main");

            foreach (var classDecl in tree.ClassDeclarations)
            {
                string currentClass = classDecl.Name;

                foreach (var methodDecl in classDecl.MethodDeclarations)
                {
                    string currentMethod = methodDecl.MethodName;
                    try
                    {
                        TypeChecking(methodDecl.MethodBody, currentClass, currentMethod);
                    }
                    catch (Exception e)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(e.Message + " in " + currentClass + "." + currentMethod);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                }
            }
        }
        public ProgramsForm(ref Prg CurPRG, string Path)
        {
            SelectedPrg = CurPRG;
            PrgPath     = Path;

            SetView(SelectedPrg.Programs, SelectedPrg.ProgramCodes);
        }
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case (Keys.Enter):
                Regex Val = new Regex(@"^[+-]?\d+(\.\d+)?$");
                if (IsNumeric(textBox1.Text) || Val.IsMatch(textBox1.Text))
                {
                    dgv.Rows[Pos].Cells[3].Value = textBox1.Text;
                    var form = new VariablesForm(Prg.Variables, Prg.CustomUnits);

                    form.ExternalSaveValue(Pos, dgv.Rows[Pos]);

                    UpdatePoint up = new UpdatePoint();
                    if (up.Update_point(id, dgv.Rows[Pos].Cells[1].Value.ToString() + " " + textBox1.Text))
                    {
                        Console.WriteLine("Name Update Success");
                    }
                    else
                    {
                        Console.WriteLine("Error");
                    }
                    Prg.Save(PrgPath);
                    MessageBox.Show("Saved");
                    flag         = true;
                    DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Invalid parameter");
                }
                break;
            }
        }
Example #6
0
 /// <summary>
 /// Builds a copy from PRG Control Points
 /// </summary>
 /// <param name="prg">PRG object</param>
 public ControlPoints(Prg prg)
 {
     foreach (var vars in prg.Variables)
     {
         Add(vars.Label);
     }
     foreach (var ins in prg.Inputs)
     {
         Add(ins.Label, IdentifierTypes.INS);
     }
     foreach (var outs in prg.Outputs)
     {
         Add(outs.Label, IdentifierTypes.OUTS);
     }
     foreach (var prgs in prg.Programs)
     {
         Add(prgs.Label, IdentifierTypes.PRGS);
     }
     foreach (var schs in prg.Schedules)
     {
         Add(schs.Label, IdentifierTypes.SCHS);
     }
     foreach (var hols in prg.Holidays)
     {
         Add(hols.Label, IdentifierTypes.HOLS);
     }
 }
Example #7
0
        public ProgramsForm(ref Prg CurPRG, string Path)
        {
            Prg     = CurPRG;
            PrgPath = Path;

            SetView(Prg.Programs, Prg.ProgramCodes);
        }
        public ProgramEditorForm(Prg CurrentPrg, int Index) : this()
        {
            ProgramCode prgcode = CurrentPrg.ProgramCodes[Index];

            //CurrentPrg.Programs[Index].Description
            this.Text = "Edit Code: " + CurrentPrg.Programs[Index].Label;
            SetCode(prgcode.Code.ToString());
        }
        private List <TreeFunction> BuildFunctions(Prg prg)
        {
            PrepareTree(prg);
            List <TreeFunction> functions = new List <TreeFunction>();

            // main method
            Temp mainReturnTemp = new Temp();

            functions.Add(new TreeFunction(new Label("main"), 2, new List <TreeStm>()
            {
                (BuildBody(prg.MainClass.Statement)), new StmMove(new ExpTemp(mainReturnTemp), new ExpConst(0))
            }, mainReturnTemp));



            foreach (var classDecl in prg.ClassDeclarations)
            {
                currentClass = classDecl.Name;
                foreach (var instanceVar in classDecl.VarDeclarations)
                {
                    instanceVariables.Add(instanceVar.Name, instanceVar.Type);
                }

                foreach (var methodDecl in classDecl.MethodDeclarations)
                {
                    List <TreeStm> body = new List <TreeStm>();

                    // register all params in environment
                    for (int i = 0; i < methodDecl.Parameters.Parameters.Length; i++)
                    {
                        // (i + 1) because of the this pointer which is always the first param
                        parEnv.Add(methodDecl.Parameters.Parameters[i].Item2, new ExpParam(i + 1));
                    }

                    // register local variables in environment
                    foreach (var local in methodDecl.MethodBody.VarDeclarations)
                    {
                        env.Add(local.Name, new Temp());
                    }

                    foreach (var stm in methodDecl.MethodBody.Statements)
                    {
                        body.Add(BuildBody(stm));
                    }
                    // separate return
                    Temp returnVal = new Temp();
                    body.Add(new StmMove(new ExpTemp(returnVal), BuildExpression(methodDecl.MethodBody.ReturnExpression)));
                    // create the treefunction and clear enviroments
                    functions.Add(new TreeFunction(new Label(methodDecl.MethodName), methodDecl.Parameters.Parameters.Length + 1, body, returnVal));
                    parEnv.Clear();
                    env.Clear();
                }

                instanceVariables.Clear();
            }

            return(functions);
        }
Example #10
0
        private void LoadPrg(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog();

            dialog.Filter = $"{Resources.PrgFiles}|*.prg;*.prog|{Resources.AllFiles} (*.*)|*.*";
            dialog.Title  = Resources.SelectPrgFile;
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            try
            {
                var path = dialog.FileName;


                PrgPath = path;
                Prg     = Prg.Load(path);



                statusLabel.Text = string.Format(Resources.CurrentFile, path);

                //File menu
                savePRGToolStripMenuItem.Enabled = true;
                saveAsToolStripMenuItem.Enabled  = true;
                upgradeMenuItem.Enabled          = true;

                //Control menu
                inputsMenuItem.Enabled      = true;
                outputsMenuItem.Enabled     = true;
                variablesMenuItem.Enabled   = true;
                programsMenuItem.Enabled    = true;
                controllersMenuItem.Enabled = true;
                screensMenuItem.Enabled     = true;
                schedulesMenuItem.Enabled   = true;
                holidaysMenuItem.Enabled    = true;

                //Buttons tool strip
                inputsButton.Enabled      = true;
                outputsButton.Enabled     = true;
                variablesButton.Enabled   = true;
                programsButton.Enabled    = true;
                controllersButton.Enabled = true;
                screensButton.Enabled     = true;
                schedulesButton.Enabled   = true;
                holidaysButton.Enabled    = true;

                if (Prg.FileVersion != FileVersion.Current)
                {
                    upgradeMenuItem.Visible = true;
                }
            }
            catch (Exception exception)
            {
                MessageBoxUtilities.ShowException(exception);
            }
        }
Example #11
0
        public void UnsupportedTest(string name)
        {
            var exception = Assert.Catch(() =>
            {
                var prg = Prg.Load(TestUtilities.GetFullPathForPrgFile(name));

                Console.WriteLine(prg.PropertiesText());
            });

            Console.WriteLine(exception.Message);
        }
 private void PrepareTree(Prg prg)
 {
     foreach (var classDecl in prg.ClassDeclarations)
     {
         vshit.RawClass.Add(classDecl.Name, classDecl.VarDeclarations.Select(v => v.Name).ToArray());
         foreach (var methodDecl in classDecl.MethodDeclarations)
         {
             methodDecl.MethodName = classDecl.Name + "$" + methodDecl.MethodName;
         }
     }
 }
 public void InitTypeChecking(Prg tree)
 {
     try
     {
         symbolTable = CreateSymbolTable(tree);
     }
     catch (Exception e)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(e.Message);
         Console.ForegroundColor = ConsoleColor.White;
     }
 }
Example #14
0
        public void Prg_TemcoPanelRev6()
        {
            #region TestData

            var path = TestUtilities.GetFullPathForPrgFile("BTUMeter.prg");
            var prg  = Prg.Load(path);

            #endregion

            //Program codes
            BaseProgramCodeTest("BTUMeter1.txt", prg.ProgramCodes[0]);
            //BaseProgramCodeTest("BTUMeter3.txt", prg.ProgramCodes[2]);
            //BaseProgramCodeTest("BTUMeter4.txt", prg.ProgramCodes[3]);
            //BaseProgramCodeTest("BTUMeter5.txt", prg.ProgramCodes[4]);
        }
Example #15
0
        private void Save(object sender, EventArgs e)
        {
            if (!view.Validate())
            {
                MessageBoxUtilities.ShowWarning(Resources.ViewNotValidated);
                DialogResult = DialogResult.None;
                return;
            }

            try
            {
                for (var i = 0; i < view.RowCount && i < Points.Count; ++i)
                {
                    var point = Points[i];
                    var row   = view.Rows[i];
                    point.Description = row.GetValue <string>(DescriptionColumn);
                    point.PictureFile = row.GetValue <string>(PictureColumn);
                    point.GraphicMode = row.GetValue <TextGraphic>(ModeColumn);
                    point.Label       = row.GetValue <string>(LabelColumn);
                    point.RefreshTime = row.GetValue <int>(RefreshColumn);

                    string      name     = row.GetValue <string>(PictureColumn);
                    var         building = "Default_Building";
                    string      path     = GetFullPathForPicture(name, building);
                    UpdatePoint up       = new UpdatePoint();
                    if (up.Update_point_image(Prfileid, path, i))
                    {
                        Console.WriteLine("Image Update Success");
                    }
                    else
                    {
                        Console.WriteLine("Error");
                    }
                }
                Prg.Save(PrgPath);
            }
            catch (Exception exception)
            {
                MessageBoxUtilities.ShowException(exception);
                DialogResult = DialogResult.None;
                return;
            }

            DialogResult = DialogResult.OK;
            Close();
        }
        private void textBox1_ClickVars(object sender, MouseEventArgs e)
        {
            Regex Val = new Regex(@"^[+-]?\d+(\.\d+)?$");

            if (IsNumeric(textBox1.Text) || Val.IsMatch(textBox1.Text))
            {
                textBox1.Enabled = true;
            }
            else
            {
                if (textBox1.Text.ToLower().Contains("on") || textBox1.Text.ToLower().Contains("off"))
                {
                    dgv.Rows[Pos].Cells[3].Value = ((textBox1.Text.Equals("On")) ? "Off" : "On");
                }
                else if (textBox1.Text.ToLower().Contains("yes") || textBox1.Text.ToLower().Contains("no"))
                {
                    dgv.Rows[Pos].Cells[3].Value = ((textBox1.Text.Equals("Yes")) ? "No" : "Yes");
                }



                textBox1.Text = dgv.Rows[Pos].Cells[3].Value.ToString();
                var form = new VariablesForm(Prg.Variables, Prg.CustomUnits);

                form.ExternalSaveValue(Pos, dgv.Rows[Pos]);


                UpdatePoint up = new UpdatePoint();
                if (up.Update_point(id, dgv.Rows[Pos].Cells[1].Value.ToString() + " " + textBox1.Text))
                {
                    Console.WriteLine("Name Update Success");
                }
                else
                {
                    Console.WriteLine("Error");
                }
                Prg.Save(PrgPath);
                MessageBox.Show("Saved");
                flag         = true;
                DialogResult = DialogResult.OK;
            }
        }
Example #17
0
        private void SavePrg(object sender, EventArgs e)
        {
            if (!IsOpened)
            {
                statusLabel.Text = Resources.FileIsNotOpen;
                return;
            }

            try
            {
                var path = PrgPath;

                Prg.Save(path);
                statusLabel.Text = string.Format(Resources.Saved, path);
            }
            catch (Exception exception)
            {
                MessageBoxUtilities.ShowException(exception);
            }
        }
Example #18
0
        public void GetLinePart_Tests()
        {
            var path = TestUtilities.GetFullPathForPrgFile("BTUMeter.prg");
            var prg  = Prg.Load(path, null);

            var bytes = prg.ProgramCodes[0].Code;
            {
                //20 IF TIME-ON ( INIT ) > 00:00:05 AND METERTOT < 1 THEN STOP INIT
                var offset = 56;

                var ifPart = Line.GetLinePart(bytes, ref offset);
                Assert.AreEqual(20, ifPart.Length);
                var ff = bytes.ToByte(ref offset);
                Assert.AreEqual(0xFF, ff);
                var thenEnd = bytes.ToUInt16(ref offset);
                Assert.AreEqual(83, thenEnd);
                var thenPart = Line.GetLinePart(bytes, ref offset, nextPart: thenEnd);
                Assert.AreEqual(4, thenPart.Length);
            }
        }
Example #19
0
 /// <summary>
 /// Builds a copy from PRG Control Points
 /// </summary>
 /// <param name="prg">PRG object</param>
 public ControlPoints(Prg prg)
 {
     try
     {
         int i;
         //Copy variables info
         for (i = 0; i < prg.Variables.Count(); i++)
         {
             Add(prg.Variables[i], i + 1);
         }
         //Copy inputs info
         for (i = 0; i < prg.Inputs.Count(); i++)
         {
             Add(prg.Inputs[i], i + 1);
         }
         //Copy outputs info
         for (i = 0; i < prg.Outputs.Count(); i++)
         {
             Add(prg.Outputs[i], i + 1);
         }
         //Copy programs info
         for (i = 0; i < prg.Programs.Count(); i++)
         {
             Add(prg.Programs[i], i + 1);
         }
         //Copy schedules info
         for (i = 0; i < prg.Schedules.Count(); i++)
         {
             Add(prg.Schedules[i], i + 1);
         }
         //Copy holidays info
         for (i = 0; i < prg.Holidays.Count(); i++)
         {
             Add(prg.Holidays[i], i + 1);
         }
     }
     catch (Exception ex)
     {
         ExceptionHandler.Show(ex, "Copying Control Points");
     }
 }
        public SymbolTable CreateSymbolTable(Prg tree)
        {
            SymbolTable symbolTable = new SymbolTable();

            // main class
            symbolTable.AddClass(tree.MainClass.Name);
            symbolTable.AddMethod(tree.MainClass.Name, "main", new ObjectType("void"));
            symbolTable.AddMethodParameter(tree.MainClass.Name, "main", tree.MainClass.Param, new ObjectType("StringArray"));


            // class stuff
            foreach (ClassDeclaration classDecl in tree.ClassDeclarations)
            {
                string currentClass = classDecl.Name;
                symbolTable.AddClass(currentClass);
                foreach (VarDeclaration varDecl in classDecl.VarDeclarations)
                {
                    symbolTable.AddField(currentClass, varDecl.Name, varDecl.Type);
                }
                // method stuff
                foreach (MethodDeclaration methodDecl in classDecl.MethodDeclarations)
                {
                    string currentMethod = methodDecl.MethodName;
                    symbolTable.AddMethod(currentClass, methodDecl.MethodName, methodDecl.ReturnType);

                    // parameters
                    foreach (var par in methodDecl.Parameters.Parameters)
                    {
                        symbolTable.AddMethodParameter(currentClass, currentMethod, par.Item2, par.Item1);
                    }

                    // method vars
                    foreach (var varDecl in methodDecl.MethodBody.VarDeclarations)
                    {
                        symbolTable.AddMethodVariable(currentClass, currentMethod, varDecl.Name, varDecl.Type);
                    }
                }
            }

            return(symbolTable);
        }
Example #21
0
        private void DoCycle()
        {
            if (_frameCycles == 0)
            {
                _board.InputRead = false;
                _board.PollInput();
                _board.Cpu.LagCycles = 0;
            }

            _driveLed = _board.Serial.ReadDeviceLight();

            _board.Execute();
            _frameCycles++;

            // load PRG file if needed
            if (_loadPrg)
            {
                // check to see if cpu PC is at the BASIC warm start vector
                if (_board.Cpu.Pc != 0 && _board.Cpu.Pc == ((_board.Ram.Peek(0x0303) << 8) | _board.Ram.Peek(0x0302)))
                {
                    Prg.Load(_board.Pla, _inputFileInfo.Data);
                    _loadPrg = false;
                }
            }

            if (_frameCycles != _cyclesPerFrame)
            {
                return;
            }

            _board.Flush();
            IsLagFrame = !_board.InputRead;

            if (IsLagFrame)
            {
                LagCount++;
            }
            _frameCycles -= _cyclesPerFrame;
            _frame++;
        }
Example #22
0
        private void Upgrade(object sender, EventArgs e)
        {
            if (!IsOpened)
            {
                statusLabel.Text = Resources.FileIsNotOpen;
                return;
            }

            try
            {
                var path = PrgPath;

                Prg.Upgrade(FileVersion.Current);
                statusLabel.Text = string.Format(Resources.Upgraded, path);

                upgradeMenuItem.Visible = false;
            }
            catch (Exception exception)
            {
                MessageBoxUtilities.ShowException(exception);
            }
        }
Example #23
0
 /// <summary>
 /// Set a local copy of all identifiers in prg
 /// </summary>
 /// <param name="prg">Program prg</param>
 static public void SetControlPoints(Prg prg)
 {
     Identifiers = new ControlPoints(prg);
 }
Example #24
0
        public void Prg_BTUMeter()
        {
            var path = TestUtilities.GetFullPathForPrgFile("BTUMeter.prg");
            var prg  = Prg.Load(path);

            ObjectAssert.AreEqual(new CustomDigitalUnitsPoint(false, "TANK1", "TANK2"), prg.CustomUnits.Digital[0]);

            //Inputs
            {
                //IN1
                var expected = new InputPoint
                {
                    Description     = "TANK2 TOP",
                    AutoManual      = AutoManual.Automatic,
                    Value           = new VariableValue(0.683, Unit.PercentsVolts5),
                    CalibrationH    = 0.0,
                    CalibrationL    = 0.0,
                    CalibrationSign = Sign.Negative,
                    Control         = OffOn.On,
                    CustomUnits     = null,
                    DigitalAnalog   = DigitalAnalog.Analog,
                    FileVersion     = FileVersion.Rev6,
                    Filter          = 1,
                    Status          = InputStatus.Normal,
                    Jumper          = Jumper.To5V,
                    Label           = "T2_TOP",
                    SubNumber       = 0.1,
                    //Decom = 32
                };
                ObjectAssert.AreEqual(expected, prg.Inputs[0]);

                //IN2
                expected = new InputPoint
                {
                    Description     = "TANK2 BOT",
                    AutoManual      = AutoManual.Automatic,
                    Value           = new VariableValue(true, Unit.LowHigh, null, 1000),
                    CalibrationH    = 0.0,
                    CalibrationL    = 0.0,
                    CalibrationSign = Sign.Negative,
                    Control         = OffOn.On,
                    CustomUnits     = null,
                    DigitalAnalog   = DigitalAnalog.Digital,
                    FileVersion     = FileVersion.Rev6,
                    Filter          = 1,
                    Status          = InputStatus.Normal,
                    Jumper          = Jumper.Thermistor,
                    Label           = "T2_BOT",
                    SubNumber       = 0.1
                };
                ObjectAssert.AreEqual(expected, prg.Inputs[1]);

                //IN3
                expected = new InputPoint
                {
                    Description     = "IN 3",
                    AutoManual      = AutoManual.Automatic,
                    Value           = new VariableValue(19.824, Unit.Psi20),
                    CalibrationH    = 0.0,
                    CalibrationL    = 0.0,
                    CalibrationSign = Sign.Negative,
                    Control         = OffOn.On,
                    CustomUnits     = null,
                    DigitalAnalog   = DigitalAnalog.Analog,
                    FileVersion     = FileVersion.Rev6,
                    Filter          = 32,
                    Status          = InputStatus.Normal,
                    Jumper          = Jumper.Thermistor,
                    Label           = "IN3",
                    SubNumber       = 0.1
                };
                ObjectAssert.AreEqual(expected, prg.Inputs[2]);
            }

            //Outputs
            {
                //OUT1
                var expected = new OutputPoint()
                {
                    Description    = "VALVE LEFT",
                    AutoManual     = AutoManual.Manual,
                    HwSwitchStatus = SwitchStatus.Auto,
                    Value          = new VariableValue(true, Unit.OffOn, null, 1000),
                    LowVoltage     = 0,
                    HighVoltage    = 0,
                    PwmPeriod      = 0,
                    Control        = OffOn.On,
                    CustomUnits    = null,
                    DigitalAnalog  = DigitalAnalog.Digital,
                    FileVersion    = FileVersion.Rev6,
                    Label          = "VAL_LEFT",
                    SubNumber      = 0.1
                };
                ObjectAssert.AreEqual(expected, prg.Outputs[0]);

                //OUT2
                expected = new OutputPoint()
                {
                    Description    = "VALVE RIGHT",
                    AutoManual     = AutoManual.Automatic,
                    HwSwitchStatus = SwitchStatus.Auto,
                    Value          = new VariableValue(true, Unit.OffOn, null, 1000),
                    LowVoltage     = 0,
                    HighVoltage    = 0,
                    PwmPeriod      = 0,
                    Control        = OffOn.On,
                    CustomUnits    = null,
                    DigitalAnalog  = DigitalAnalog.Digital,
                    FileVersion    = FileVersion.Rev6,
                    Label          = "VAL_RIT",
                    SubNumber      = 0.1
                };
                ObjectAssert.AreEqual(expected, prg.Outputs[1]);
            }

            //Variables
            {
                //VAR1
                var expected = new VariablePoint()
                {
                    Description   = "START TEST FLAG",
                    AutoManual    = AutoManual.Automatic,
                    Value         = new VariableValue(false, Unit.OffOn, null, 1000),
                    Control       = OffOn.Off,
                    DigitalAnalog = DigitalAnalog.Digital,
                    FileVersion   = FileVersion.Rev6,
                    Label         = "INIT"
                };
                ObjectAssert.AreEqual(expected, prg.Variables[0]);

                //VAR10
                expected = new VariablePoint()
                {
                    Description   = "NOW FILLING",
                    AutoManual    = AutoManual.Automatic,
                    Value         = new VariableValue(false, Unit.CustomDigital1, null, 2000),
                    Control       = OffOn.Off,
                    DigitalAnalog = DigitalAnalog.Digital,
                    FileVersion   = FileVersion.Rev6,
                    Label         = "FILLTANK",
                };
                ObjectAssert.AreEqual(expected, prg.Variables[9]);
            }

            //Program codes
            {
                //var expected = new ProgramCode()
                //{
                //    Code = new byte[2000],
                //    FileVersion = FileVersion.Rev6
                //};
                //ObjectAssert.AreEqual(expected, prg.ProgramCodes[0]);

                //Console.WriteLine(prg.ProgramCodes[0].PropertiesText());
                //foreach (var line in prg.ProgramCodes[0].Lines)
                //{
                //Console.WriteLine(line.GetString());
                //}

                //Console.WriteLine(DebugUtilities.CompareBytes(prg.ProgramCodes[0].Code,
                //    prg.ProgramCodes[0].Code, onlyDif: false));
            }
        }
 /// <summary>
 /// Set a local copy of all identifiers in prg
 /// </summary>
 /// <param name="prg">Program prg</param>
 public void SetControlPoints(Prg prg)
 {
     Identifiers = new ControlPoints(prg);
     TimeBuff    = new TimeBuffer(Identifiers);
 }
 public TreeNode BuildIntermediateAst(Prg prg)
 {
     return(new TreePrg(BuildFunctions(prg)));
 }
Example #27
0
        public void BaseTest(string name)
        {
            var path = TestUtilities.GetFullPathForPrgFile(name);
            var prg  = Prg.Load(path);

            var temp = Path.GetTempFileName();

            //Test variables binary load/save compatible

            //Bit to bit compatible supported only for current version
            if (prg.FileVersion == FileVersion.Current)
            {
                foreach (var input in prg.Inputs)
                {
                    VariableVariantToFromTest(input.Value, prg.CustomUnits);

                    ObjectAssert.AreEqual(input, new InputPoint(input.ToBytes()),
                                          $"{nameof(input)} ToFromBytes test failed.");
                }

                foreach (var output in prg.Outputs)
                {
                    VariableVariantToFromTest(output.Value, prg.CustomUnits);

                    ObjectAssert.AreEqual(output, new OutputPoint(output.ToBytes()),
                                          $"{nameof(output)} ToFromBytes test failed.");
                }

                foreach (var variable in prg.Variables)
                {
                    VariableVariantToFromTest(variable.Value, prg.CustomUnits);

                    ObjectAssert.AreEqual(variable, new VariablePoint(variable.ToBytes()),
                                          $"{nameof(variable)} ToFromBytes test failed.");
                }

                foreach (var program in prg.Programs)
                {
                    ObjectAssert.AreEqual(program, new ProgramPoint(program.ToBytes()),
                                          $"{nameof(program)} ToFromBytes test failed.");
                }

                foreach (var controller in prg.Controllers)
                {
                    ObjectAssert.AreEqual(controller, new ControllerPoint(controller.ToBytes()),
                                          $"{nameof(controller)} ToFromBytes test failed.");
                }

                foreach (var screen in prg.Screens)
                {
                    ObjectAssert.AreEqual(screen, new ScreenPoint(screen.ToBytes()),
                                          $"{nameof(screen)} ToFromBytes test failed.");
                }

                foreach (var graphic in prg.Graphics)
                {
                    ObjectAssert.AreEqual(graphic, new GraphicPoint(graphic.ToBytes()),
                                          $"{nameof(graphic)} ToFromBytes test failed.");
                }

                foreach (var user in prg.Users)
                {
                    ObjectAssert.AreEqual(user, new UserPoint(user.ToBytes()),
                                          $"{nameof(user)} ToFromBytes test failed.");
                }

                foreach (var unit in prg.CustomUnits.Digital)
                {
                    ObjectAssert.AreEqual(unit, new CustomDigitalUnitsPoint(unit.ToBytes()),
                                          $"{nameof(unit)} ToFromBytes test failed.");
                }

                foreach (var table in prg.Tables)
                {
                    ObjectAssert.AreEqual(table, new TablePoint(table.ToBytes()),
                                          $"{nameof(table)} ToFromBytes test failed.");
                }

                {
                    var settings = prg.Settings;
                    ObjectAssert.AreEqual(settings, new Settings(settings.ToBytes()),
                                          $"{nameof(settings)} ToFromBytes test failed.");
                }

                foreach (var schedule in prg.Schedules)
                {
                    ObjectAssert.AreEqual(schedule, new SchedulePoint(schedule.ToBytes()),
                                          $"{nameof(schedule)} ToFromBytes test failed.");
                }

                foreach (var holiday in prg.Holidays)
                {
                    ObjectAssert.AreEqual(holiday, new HolidayPoint(holiday.ToBytes()),
                                          $"{nameof(holiday)} ToFromBytes test failed.");
                }

                foreach (var monitor in prg.Monitors)
                {
                    ObjectAssert.AreEqual(monitor, new MonitorPoint(monitor.ToBytes()),
                                          $"{nameof(monitor)} ToFromBytes test failed.");
                }

                foreach (var code in prg.ScheduleCodes)
                {
                    ObjectAssert.AreEqual(code, new ScheduleCode(code.ToBytes(), 0),
                                          $"{nameof(code)} ToFromBytes test failed.");
                }

                foreach (var code in prg.HolidayCodes)
                {
                    ObjectAssert.AreEqual(code, new HolidayCode(code.ToBytes(), 0),
                                          $"{nameof(code)} ToFromBytes test failed.");
                }

                foreach (var code in prg.ProgramCodes)
                {
                    //Currently unsupported
                    //ObjectAssert.AreEqual(code, new ProgramCode(code.ToBytes(), 0),
                    //    $"{nameof(code)} ToFromBytes test failed.");
                }

                foreach (var units in prg.CustomUnits.Analog)
                {
                    ObjectAssert.AreEqual(units, new CustomAnalogUnitsPoint(units.ToBytes()),
                                          $"{nameof(units)} ToFromBytes test failed.");
                }
            }

            prg.Save(temp);
            try
            {
                FileAssert.AreEqual(path, temp,
                                    $@"Name: {name}. 
See console log for details.
");
            }
            catch (Exception exception)
            {
                var offset = GetDifferOffset(exception);
                Console.WriteLine(DebugUtilities.CompareBytes(File.ReadAllBytes(path),
                                                              prg.ToBytes(), offset - 35, 70, onlyDif: false, toText: true));
                throw;
            }

            if (prg.Variables.Count > 0)
            {
                prg = Prg.Load(temp);
                prg.Variables[0].Value = new VariableValue("9998.8999", Unit.DegreesC);
                prg.Save(temp);
                FileAssert.AreNotEqual(path, temp);
            }

            //Additional check for upgrade to current
            if (prg.FileVersion != FileVersion.Current)
            {
                prg.Upgrade(FileVersion.Current);
                prg.Save(temp);
                prg = Prg.Load(temp);
                Assert.AreEqual(FileVersion.Current, prg.FileVersion);
            }
        }