Ejemplo n.º 1
0
        private bool objDetect(RichTextBox textCompile, HmiObject obj)
        {
            bool flag = true;

            if (obj.ObjInfo.Panel.X < 0 ||
                obj.ObjInfo.Panel.EndX >= App.LcdWidth ||
                obj.ObjInfo.Panel.Y < 0 ||
                obj.ObjInfo.Panel.EndY >= App.LcdHeight
                )
            {
                textCompile.AddRichTextString(
                    string.Concat("Page:".Translate(), Name, " Error:".Translate(), obj.ObjName, " Position Invalid:".Translate()),
                    Color.Red
                    );
                App.Errors++;
                flag = false;
            }

            for (int i = 0; i < obj.Attributes.Count; i++)
            {
                if (obj.Attributes[i].InfoAttribute.AttrType < 15 &&
                    obj.Attributes[i].InfoAttribute.CanModify == 1 &&
                    obj.checkAttribute(obj.Attributes[i])
                    )
                {
                    string err = obj.CheckAttributeValue(obj.Attributes[i]);
                    if (err != "")
                    {
                        textCompile.AddRichTextString(
                            string.Concat(
                                "Page:".Translate(),
                                Name,
                                " Error:".Translate(),
                                obj.ObjName + "." + obj.Attributes[i].Name.ToString(),
                                " InputVal Invalid:".Translate(),
                                err),
                            Color.Red);
                        App.Errors++;
                        flag = false;
                    }
                }
            }
            return(flag);
        }
Ejemplo n.º 2
0
        public bool Compile(RichTextBox textCompile)
        {
            byte index = 0;

            string[] pageTimers = new string[4];
            bool     flag       = true;

            List <byte[]> newlist = new List <byte[]>();
            List <byte[]> codes   = new List <byte[]>();

            byte[] binTFT     = new byte[HmiOptions.InfoPageObjectSize * HmiObjects.Count + 4];
            byte[] customData = new byte[0];

            Codes.Clear();
            ushort customDataAddress = (ushort)(App.OverBytes.Length - 4);

            try
            {
                int i;
                Utility.ToBytes(((uint)customDataAddress)).CopyTo(binTFT, 0);
                customDataAddress += (ushort)(binTFT.Length - 4);
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    HmiObject hmiObj = HmiObjects[idxObj];
                    if (!objDetect(textCompile, hmiObj))
                    {
                        flag = false;
                        continue;
                    }

                    InfoPageObject infoPageObj;
                    infoPageObj.TouchState = 1;
                    if (hmiObj.ObjInfo.Panel.loadlei == 1)
                    {
                        infoPageObj.Visible = 1;
                    }
                    else
                    {
                        infoPageObj.Visible = 0;
                    }

                    infoPageObj.RefreshFlag = hmiObj.ObjInfo.Panel.loadlei;
                    Utility.ToBytes(infoPageObj).CopyTo(binTFT, idxObj * HmiOptions.InfoPageObjectSize + 4);

                    if (hmiObj.ObjInfo.IsCustomData == 0)
                    {
                        hmiObj.ObjInfo.AttributeStart = customDataAddress;
                        customData = Utility.ToBytes((uint)customDataAddress);
                        ushort objRamBytes = hmiObj.GetObjRamBytes(ref customData, customDataAddress);
                        if (objRamBytes != 0)
                        {
                            codes.Add(customData);
                            hmiObj.ObjInfo.AttributeLength = objRamBytes;
                            customDataAddress += hmiObj.ObjInfo.AttributeLength;
                        }
                    }
                }

                if (customDataAddress > HmiOptions.MaxCustomDataSize)
                {
                    textCompile.AddRichTextString(
                        string.Concat(
                            "Page:".Translate(),
                            Name,
                            " Error! Memory overflow:".Translate(), customDataAddress
                            ),
                        Color.Red
                        );
                    App.Errors++;
                    flag = false;
                }

                if (!flag)
                {
                    return(flag);
                }

                textCompile.AddRichTextString(
                    string.Concat(
                        "Page:".Translate(),
                        Name,
                        " OK! Occupy memory:".Translate(),
                        customDataAddress), Color.Black);

                customData = Utility.MergeBytes(Utility.ToBytes((uint)0xffff), Utility.ToBytes((uint)customDataAddress));
                codes.Add(customData);

                Codes.Add(Utility.PatternBytes("cre"));
                Codes.Add(binTFT);
                Utility.AppendList(Codes, codes);
                Codes.Add(Utility.PatternBytes("end"));

                newlist.Clear();
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    if (HmiObjects[idxObj].ObjInfo.ObjType == HmiObjType.OBJECT_TYPE_CURVE)
                    {
                        newlist.Add(Utility.ToBytes("init " + idxObj.ToString()));
                    }
                }
                Utility.AppendList(Codes, newlist);

                index = 0;
                newlist.Clear();
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    HmiObject obj = HmiObjects[idxObj];
                    if (obj.ObjInfo.ObjType == HmiObjType.TIMER)
                    {
                        if (index > 3)
                        {                               // Maximum 4 timer on page
                            if (index < 0xff)
                            {                           // One time message
                                textCompile.AddRichTextString("Page:".Translate() + Name + "Error! Only 4 Timers are allowed.".Translate(), Color.Red);
                                App.Errors++;
                                flag  = false;
                                index = 0xff;
                            }
                        }
                        else
                        {
                            newlist.Add(Utility.ToBytes("topen " + index.ToString() + "," + obj.ObjName + ".tim"));
                            Utility.AppendList(newlist, obj.Codes[0]);
                            newlist.Add(Utility.PatternBytes("tend"));

                            obj.TimerRefCodes.Clear();
                            obj.TimerRefCodes.Add(Utility.ToBytes("tpau " + index.ToString() + "," + obj.ObjName + ".tim," + obj.ObjName + ".en"));
                            pageTimers[index] = obj.ObjName;
                            ++index;
                        }
                    }
                }
                Utility.DeleteComments(newlist);
                Utility.AppendList(Codes, newlist);

                newlist.Clear();
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    HmiObject obj = HmiObjects[idxObj];
                    if (obj.ObjInfo.Panel.loadlei == 1 &&
                        obj.Codes[0].Count > 0 &&
                        obj.ObjInfo.ObjType != HmiObjType.TIMER)
                    {
                        for (i = 0; i < obj.Codes[0].Count; ++i)
                        {
                            if (Utility.GetComType(obj.Codes[0][i]) == 0)
                            {
                                newlist.Add(obj.Codes[0][i]);
                            }
                        }
                    }
                }
                Utility.DeleteComments(newlist);
                Utility.AppendList(Codes, newlist);

                newlist.Clear();
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    if (HmiObjects[idxObj].ObjInfo.Panel.loadlei == 1)
                    {
                        newlist.Add(Utility.ToBytes("oref " + idxObj.ToString() + ",0"));
                        newlist.Add(Utility.PatternBytes("if(sysda0==1)"));
                        newlist.Add(Utility.PatternBytes("{"));

                        HmiObjects[idxObj].GetLoadCodes(newlist, 0);

                        newlist.Add(Utility.ToBytes("cle_f " + idxObj.ToString() + ",0"));
                        newlist.Add(Utility.PatternBytes("}"));
                    }
                }
                Utility.AppendList(Codes, newlist);

                newlist.Clear();
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    HmiObject obj = HmiObjects[idxObj];
                    if (obj.ObjInfo.Panel.loadlei == 1 &&
                        obj.Codes[0].Count > 0 &&
                        obj.ObjInfo.ObjType != HmiObjType.TIMER
                        )
                    {
                        for (i = 0; i < obj.Codes[0].Count; i++)
                        {
                            if (Utility.GetComType(obj.Codes[0][i]) == 1)
                            {
                                newlist.Add(obj.Codes[0][i]);
                            }
                        }
                    }
                }
                Utility.DeleteComments(newlist);
                Utility.AppendList(Codes, newlist);

                Codes.Add(Utility.PatternBytes("end"));
                return(flag);
            }
            catch (Exception ex)
            {
                textCompile.AddRichTextString("Exception: " + ex.Message, Color.Red);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public bool SaveToFile(string binPath, bool compile, RichTextBox textCompile)
        {
            SaveToFileData data    = new SaveToFileData();
            StreamWriter   writer  = new StreamWriter(binPath);
            InfoApp        infoApp = new InfoApp();

            try
            {
                if (!prepareToSave(ref infoApp, compile, textCompile, data))
                {
                    textCompile.AddRichTextString(
                        string.Concat(
                            "Compile failure!".Translate(), " ",
                            Errors, " Errors,".Translate(), " ",
                            Warnings, " Warnings,".Translate()
                            ), Color.Red);
                    writer.Close();
                    writer.Dispose();
                    return(false);
                }

                infoApp.VersionMajor = HmiOptions.VersionMajor;
                infoApp.VersionMinor = HmiOptions.VersionMinor;

                infoApp.FileType = Utility.FileType(compile);

                byte[] buffer = Utility.ToBytes(infoApp);
                writer.BaseStream.Write(buffer, 0, HmiOptions.InfoAppSize);

                int idx;
                if (compile)
                {                       // Fill zeros to 4K boundary
                    buffer = new byte[0x1000 - HmiOptions.InfoAppSize];
                    for (idx = 0; idx < buffer.Length; idx++)
                    {
                        buffer[idx] = 0;
                    }
                    writer.BaseStream.Write(buffer, 0, buffer.Length);
                }

                for (idx = 0; idx < Pictures.Count; idx++)
                {
                    writer.BaseStream.Write(PictureImages[idx], 0, PictureImages[idx].Length);
                }

                for (idx = 0; idx < Fonts.Count; idx++)
                {
                    writer.BaseStream.Write(FontImages[idx], 0, FontImages[idx].Length);
                }

                if (compile)
                {                       // Compile :
                    int imgSize = (getPictureImagesSize() + getFontImagesSize()) % 0x1000;
                    if (imgSize != 0)
                    {
                        buffer = new byte[0x1000 - imgSize];
                        for (idx = 0; idx < buffer.Length; idx++)
                        {
                            buffer[idx] = 0;
                        }
                        writer.BaseStream.Write(buffer, 0, buffer.Length);
                    }
                }

                for (idx = 0; idx < data.m_infoStrings.Count; idx++)
                {
                    writer.BaseStream.Write(data.m_stringDatas[idx], 0, data.m_stringDatas[idx].Length);
                }

                if (compile)
                {
                    StreamReader reader = new StreamReader(Path.Combine(Application.StartupPath, "fwc.bin"));
                    buffer = new byte[reader.BaseStream.Length];
                    reader.BaseStream.Position = 0L;
                    reader.BaseStream.Read(buffer, 0, buffer.Length);
                    writer.BaseStream.Write(buffer, 0, buffer.Length);
                    reader.Close();
                }

                for (idx = 0; idx < data.m_infoPages.Count; idx++)
                {
                    buffer = Utility.ToBytes(data.m_infoPages[idx]);
                    writer.BaseStream.Write(buffer, 0, HmiOptions.InfoPageSize);
                }

                for (idx = 0; idx < data.m_infoObjects.Count; idx++)
                {
                    buffer = Utility.ToBytes(data.m_infoObjects[idx]);
                    writer.BaseStream.Write(buffer, 0, HmiOptions.InfoObjectSize);
                }

                uint dataStart = 0;
                for (idx = 0; idx < infoApp.PictureCount; idx++)
                {
                    InfoPicture picture = Pictures[idx];
                    picture.DataStart = dataStart;
                    buffer            = Utility.ToBytes(picture);
                    writer.BaseStream.Write(buffer, 0, HmiOptions.InfoPictureSize);
                    dataStart += (uint)PictureImages[idx].Length;
                }

                for (idx = 0; idx < infoApp.StringCount; idx++)
                {
                    buffer = Utility.ToBytes(data.m_infoStrings[idx]);
                    writer.BaseStream.Write(buffer, 0, HmiOptions.InfoStringSize);
                }

                dataStart = 0;
                for (idx = 0; idx < infoApp.FontCount; idx++)
                {
                    InfoFont font = Fonts[idx];
                    font.DataOffset = dataStart;
                    buffer          = Utility.ToBytes(font);
                    writer.BaseStream.Write(buffer, 0, HmiOptions.InfoFontSize);
                    dataStart += (uint)FontImages[idx].Length;
                }
                writer.Close();
                writer.Dispose();
                textCompile.AddRichTextString(
                    string.Concat(
                        "Compile Success!".Translate(), " ",
                        Errors, " Errors,".Translate(), " ",
                        Warnings, " Warnings, FileSize:".Translate(), infoApp.FontDataStart
                        ),
                    Color.Black);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(false);
        }