示例#1
0
        public bool RunComOk(byte[] buf, Range range, ushort valBegin, ushort valEnd, CodeResults result, byte paramCount)
        {
            byte[] val     = Utility.PatternBytes("comok ");
            Range  laction = new Range();
            ushort pos     = 0;
            ushort index   = 0;

            laction.End       = range.End;
            pos               = Utility.IndexOfEx(buf, val, range, false);
            result.CodeResult = Range.List(paramCount);

            if (pos == 0xffff)
            {
                return(false);
            }

            if (paramCount != 0)
            {
                byte[] comma = Utility.ToBytes(",");
                ++pos;
                for (index = 0; index < paramCount; index++)
                {
                    if (pos > range.End)
                    {
                        return(false);
                    }

                    laction.Begin = pos;
                    result.CodeResult[index].Begin = pos;
                    pos = Utility.IndexOfEx(buf, comma, laction, true);
                    if (pos == 0xffff)
                    {
                        if (index != (paramCount - 1))
                        {
                            return(false);
                        }
                        result.CodeResult[index].End = range.End;
                        return(true);
                    }
                    if (pos == result.CodeResult[index].Begin)
                    {
                        return(false);
                    }

                    result.CodeResult[index].End = (ushort)(pos - 1);
                    ++pos;
                }
            }
            return(true);
        }
示例#2
0
        private int getComString()
        {
            int num = 0;
            int index = 0;
            byte[] response = new byte[500];
            CodeResults cgcode = new CodeResults();
            cgcode.CodeResult = Range.List(10);

            try
            {
                while (Port.BytesToRead > 0)
                {
                    response[index] = (byte)Port.ReadByte();
                    index++;
                    if (index > response.Length - 1)
                        break;
                }
                index -= 4;	// Must be >= 5 bytes
                if (index < 1)
                    return 0;

                Range range = new Range(0, index);

                num = Utility.IndexOfEx(response, Utility.PatternBytes("comok "), range, true);
                m_flashSize = 0;
                if (num != 0xffff)
                {
                    range.Begin = num - 5;
                    if (RunComOk(response, range, 0, 5, cgcode, 7))
                    {
                        m_isTouch = (Utility.PosByteGetString(cgcode.CodeResult[0], response) != "0");
                        m_lcdId = Utility.PosGetU16(cgcode.CodeResult[1], response);
                        m_model = Utility.PosByteGetString(cgcode.CodeResult[2], response);
                        m_fwVersion[0] = (byte)Utility.PosGetU16(cgcode.CodeResult[3], response);
                        m_fwVersion[1] = (byte)Utility.PosGetU16(cgcode.CodeResult[4], response);
                        m_flashId = Utility.PosByteGetString(cgcode.CodeResult[5], response);
                        m_flashSize = Utility.GetInt(Utility.PosByteGetString(cgcode.CodeResult[6], response));
                        if (m_model.Length > 1)
                        {
                            if ((HmiOptions.Language == 0 && m_model.Substring(0, 1) == "T")
                             || (HmiOptions.Language == 1 && m_model.Substring(0, 1) == "N")
                                )
                                return 1;

                            if (m_model.Length > 6)
                            {
                                if (HmiOptions.Language == 1 && m_model.Substring(0, 6) == "TJC024")
                                {
                                    Port.SendStringEnd("tjchmi-setapp 1,9325,NX3224T024_011R");
                                    return 1;
                                }
                                if (HmiOptions.Language == 1 && m_model.Substring(0, 6) == "TJC043")
                                {
                                    Port.SendStringEnd("tjchmi-setapp 1,0043,NX4827T043_011R");
                                    return 1;
                                }
                            }
                            MessageBox.Show("Invalid Device.".Translate() + m_model);
                        }
                        return 0;
                    }

                    if (RunComOk(response, range, 0, 5, cgcode, 6))
                    {
                        m_isTouch = Utility.PosByteGetString(cgcode.CodeResult[0], response) != "0";
                        m_lcdId = Utility.PosGetU16(cgcode.CodeResult[1], response);
                        m_model = Utility.PosByteGetString(cgcode.CodeResult[2], response);
                        m_fwVersion[0] = (byte)Utility.PosGetU16(cgcode.CodeResult[3], response);
                        m_fwVersion[1] = (byte)Utility.PosGetU16(cgcode.CodeResult[4], response);
                        m_flashId = Utility.PosByteGetString(cgcode.CodeResult[5], response);

                        if (m_model.Length > 1)
                        {
                            if (m_model.Substring(0, 1) == "T")
                                return 1;
                            if (m_model.Substring(0, 1) == "N")
                                return 1;

                            if (m_model.Length > 6)
                            {
                                if (m_model.Substring(0, 6) == "TJC024")
                                {
                                    Port.SendStringEnd("tjchmi-setapp 1,9325,NX3224T024_011R");
                                    return 1;
                                }
                                if (m_model.Substring(0, 6) == "TJC043")
                                {
                                    Port.SendStringEnd("tjchmi-setapp 1,0043,NX4827T043_011R");
                                    return 1;
                                }
                            }
                        }
                        return 0;
                    }
                }
                else if (Utility.IndexOfEx(response, Utility.PatternBytes("downbin"), range, true) != 0xffff)
                    return 2;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return 0;
        }
示例#3
0
        private int getComString()
        {
            int num   = 0;
            int index = 0;

            byte[]      response = new byte[500];
            CodeResults cgcode   = new CodeResults();

            cgcode.CodeResult = Range.List(10);

            try
            {
                while (Port.BytesToRead > 0)
                {
                    response[index] = (byte)Port.ReadByte();
                    index++;
                    if (index > response.Length - 1)
                    {
                        break;
                    }
                }
                index -= 4;                     // Must be >= 5 bytes
                if (index < 1)
                {
                    return(0);
                }

                Range range = new Range(0, index);

                num         = Utility.IndexOfEx(response, Utility.PatternBytes("comok "), range, true);
                m_flashSize = 0;
                if (num != 0xffff)
                {
                    range.Begin = num - 5;
                    if (RunComOk(response, range, 0, 5, cgcode, 7))
                    {
                        m_isTouch      = (Utility.PosByteGetString(cgcode.CodeResult[0], response) != "0");
                        m_lcdId        = Utility.PosGetU16(cgcode.CodeResult[1], response);
                        m_model        = Utility.PosByteGetString(cgcode.CodeResult[2], response);
                        m_fwVersion[0] = (byte)Utility.PosGetU16(cgcode.CodeResult[3], response);
                        m_fwVersion[1] = (byte)Utility.PosGetU16(cgcode.CodeResult[4], response);
                        m_flashId      = Utility.PosByteGetString(cgcode.CodeResult[5], response);
                        m_flashSize    = Utility.GetInt(Utility.PosByteGetString(cgcode.CodeResult[6], response));
                        if (m_model.Length > 1)
                        {
                            if ((HmiOptions.Language == 0 && m_model.Substring(0, 1) == "T") ||
                                (HmiOptions.Language == 1 && m_model.Substring(0, 1) == "N")
                                )
                            {
                                return(1);
                            }

                            if (m_model.Length > 6)
                            {
                                if (HmiOptions.Language == 1 && m_model.Substring(0, 6) == "TJC024")
                                {
                                    Port.SendStringEnd("tjchmi-setapp 1,9325,NX3224T024_011R");
                                    return(1);
                                }
                                if (HmiOptions.Language == 1 && m_model.Substring(0, 6) == "TJC043")
                                {
                                    Port.SendStringEnd("tjchmi-setapp 1,0043,NX4827T043_011R");
                                    return(1);
                                }
                            }
                            MessageBox.Show("Invalid Device.".Translate() + m_model);
                        }
                        return(0);
                    }

                    if (RunComOk(response, range, 0, 5, cgcode, 6))
                    {
                        m_isTouch      = Utility.PosByteGetString(cgcode.CodeResult[0], response) != "0";
                        m_lcdId        = Utility.PosGetU16(cgcode.CodeResult[1], response);
                        m_model        = Utility.PosByteGetString(cgcode.CodeResult[2], response);
                        m_fwVersion[0] = (byte)Utility.PosGetU16(cgcode.CodeResult[3], response);
                        m_fwVersion[1] = (byte)Utility.PosGetU16(cgcode.CodeResult[4], response);
                        m_flashId      = Utility.PosByteGetString(cgcode.CodeResult[5], response);

                        if (m_model.Length > 1)
                        {
                            if (m_model.Substring(0, 1) == "T")
                            {
                                return(1);
                            }
                            if (m_model.Substring(0, 1) == "N")
                            {
                                return(1);
                            }

                            if (m_model.Length > 6)
                            {
                                if (m_model.Substring(0, 6) == "TJC024")
                                {
                                    Port.SendStringEnd("tjchmi-setapp 1,9325,NX3224T024_011R");
                                    return(1);
                                }
                                if (m_model.Substring(0, 6) == "TJC043")
                                {
                                    Port.SendStringEnd("tjchmi-setapp 1,0043,NX4827T043_011R");
                                    return(1);
                                }
                            }
                        }
                        return(0);
                    }
                }
                else if (Utility.IndexOfEx(response, Utility.PatternBytes("downbin"), range, true) != 0xffff)
                {
                    return(2);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(0);
        }
示例#4
0
        public bool RunComOk(byte[] buf, Range range, ushort valBegin, ushort valEnd, CodeResults result, byte paramCount)
        {
            byte[] val = Utility.PatternBytes("comok ");
            Range laction = new Range();
            ushort pos = 0;
            ushort index = 0;
            laction.End = range.End;
            pos = Utility.IndexOfEx(buf, val, range, false);
            result.CodeResult = Range.List(paramCount);

            if (pos == 0xffff)
                return false;

            if (paramCount != 0)
            {
                byte[] comma = Utility.ToBytes(",");
                ++pos;
                for (index = 0; index < paramCount; index++)
                {
                    if (pos > range.End)
                        return false;

                    laction.Begin = pos;
                    result.CodeResult[index].Begin = pos;
                    pos = Utility.IndexOfEx(buf, comma, laction, true);
                    if (pos == 0xffff)
                    {
                        if (index != (paramCount - 1))
                            return false;
                        result.CodeResult[index].End = range.End;
                        return true;
                    }
                    if (pos == result.CodeResult[index].Begin)
                        return false;

                    result.CodeResult[index].End = (ushort)(pos - 1);
                    ++pos;
                }
            }
            return true;
        }