Пример #1
0
        public byte[] GetEncodingData(int device, bool wbit, long systembytes)
        {
            byte[]   data = null;
            SECSItem root = null;
            long     aLength;

            if (this.mMsg == null)
            {
                aLength = 10L;
            }
            else
            {
                root = this.mMsg.Root;
                if (root == null)
                {
                    aLength = 10L;
                }
                else
                {
                    data    = root.Raw();
                    aLength = (long)(data.Length + 10);
                }
            }
            this.MakeMsgLengthBytes(aLength);
            this.MakeMsgHeader(device, wbit, systembytes);
            if (root != null && data != null && data.Length > 0)
            {
                this.AppendBytes(data);
            }
            return(this.mTotalBytes.ToArray <byte>());
        }
Пример #2
0
 private bool CheckMsgFormat(SECSMessage msg, IEnumerable <SECSMessage> list)
 {
     foreach (SECSMessage message in list)
     {
         if (msg.Root == null && message.Root == null)
         {
             msg.Name        = message.Name;
             msg.Description = message.Description;
             bool result = true;
             return(result);
         }
         if (msg.Root == null || message.Root == null)
         {
             bool result = false;
             return(result);
         }
         SECSItem root   = msg.Root;
         SECSItem format = message.Root;
         if (this.secsPort.Library.CheckSecsItemFormat(ref root, ref format))
         {
             msg.Name        = message.Name;
             msg.Description = message.Description;
             bool result = true;
             return(result);
         }
     }
     return(false);
 }
Пример #3
0
        internal override bool CheckSecsItemFormat(ref SECSItem rcvd, ref SECSItem format)
        {
            bool result;

            try
            {
                if (rcvd.Format != format.Format)
                {
                    result = false;
                }
                else if (format.Format == eSECS_FORMAT.LIST)
                {
                    if (rcvd.ItemCount < format.ItemCount)
                    {
                        for (int i = 0; i < rcvd.ItemCount; i++)
                        {
                            SECSItem item  = format.Item(i + 1);
                            SECSItem item2 = rcvd.Item(i + 1);
                            if (!this.CheckSecsItemFormat(ref item2, ref item))
                            {
                                result = false;
                                return(result);
                            }
                        }
                        rcvd.Name        = format.Name;
                        rcvd.Description = format.Description;
                        result           = true;
                    }
                    else
                    {
                        for (int j = 0; j < format.ItemCount; j++)
                        {
                            SECSItem item3 = format.Item(j + 1);
                            SECSItem item4 = rcvd.Item(j + 1);
                            if (!this.CheckSecsItemFormat(ref item4, ref item3))
                            {
                                result = false;
                                return(result);
                            }
                        }
                        rcvd.Name        = format.Name;
                        rcvd.Description = format.Description;
                        result           = true;
                    }
                }
                else
                {
                    rcvd.Name        = format.Name;
                    rcvd.Description = format.Description;
                    result           = true;
                }
            }
            catch (Exception)
            {
                result = false;
            }
            return(result);
        }
Пример #4
0
        public SECSItem Duplicate()
        {
            if (this.parent == null || this.parent.format != eSECS_FORMAT.LIST)
            {
                throw new Exception("Can not duplicate. Parent is not a list");
            }
            SECSItem child = (SECSItem)this.Clone();

            this.parent.Add(child);
            return(child);
        }
Пример #5
0
 public void Remove(SECSItem item)
 {
     if (this.Format != eSECS_FORMAT.LIST)
     {
         throw new Exception("Can't Remove from a non-list SecsItem");
     }
     if (!this.secslist.Any((SECSItem t) => t == item))
     {
         throw new Exception("SECSItem.Remove: Item not found");
     }
     item.Parent = null;
 }
Пример #6
0
 public void Add(SECSItem child)
 {
     if (child != null)
     {
         if (this.Format != eSECS_FORMAT.LIST)
         {
             throw new Exception("Can't add child to a non-list SECSItem");
         }
         if (!this.ContainsChild(child))
         {
             child.Parent = this;
         }
     }
 }
Пример #7
0
        public object Clone()
        {
            object obj2;

            using (MemoryStream stream = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, this);
                stream.Seek(0L, SeekOrigin.Begin);
                obj2 = formatter.Deserialize(stream);
                stream.Close();
            }
            SECSItem item = (SECSItem)obj2;

            item.parent = null;
            return(item);
        }
Пример #8
0
        private void SendS9Fx(int aFx, byte[] hdr)
        {
            SECSTransaction trans   = new SECSTransaction();
            SECSMessage     message = new SECSMessage();

            trans.Primary       = message;
            message.Transaction = trans;
            message.DeviceIdID  = this.secsPort.DeviceID;
            message.Stream      = 9;
            message.Function    = aFx;
            message.WBit        = false;
            trans.DeviceID      = message.DeviceIdID;
            trans.ExpectReply   = message.WBit;
            SECSItem item = (aFx == 9) ? new SECSItem(eSECS_FORMAT.BINARY, "SHEAD") : new SECSItem(eSECS_FORMAT.BINARY, "MHEAD");

            item.Value   = hdr;
            message.Root = item;
            this.secsPort.Send(trans);
        }
Пример #9
0
        internal SECSMessage XElementToSECSMessage(XElement element)
        {
            SECSMessage message = new SECSMessage("", "");

            foreach (XElement element2 in element.Elements())
            {
                string str = element2.Name.ToString().Trim();
                if (str == "MessageName")
                {
                    message.Name = element2.Value.Trim();
                }
                else if (str == "Description")
                {
                    message.Description = element2.Value.Trim();
                }
                else if (str == "Stream")
                {
                    message.Stream = int.Parse(element2.Value.Trim());
                }
                else if (str == "Function")
                {
                    message.Function = int.Parse(element2.Value.Trim());
                }
                else if (str == "Wait")
                {
                    message.WBit = (element2.Value.Trim().ToUpper() == "TRUE");
                }
                else if (str == "Direction")
                {
                    message.IsHost = (element2.Value.Trim().ToUpper() == "H->E");
                }
                else if (str == "DataItem" && element2.HasElements)
                {
                    SECSItem item = this.XElementToSECSItem(element2.Elements().First <XElement>());
                    if (item != null)
                    {
                        message.Root = item;
                    }
                }
            }
            return(message);
        }
Пример #10
0
        internal static string GetSecsMessageStr(SECSMessage msg)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("S{0}F{1}", msg.Stream, msg.Function);
            if (msg.WBit)
            {
                builder.Append(" W");
            }
            builder.Append(" System Bytes=");
            builder.Append(msg.SystemBytes);
            builder.Append("\n");
            SECSItem root = msg.Root;

            if (root != null)
            {
                builder.Append(SecsItem2Str.GetSecsItemStr(0, root));
                builder.Append(".\n");
            }
            return(builder.ToString());
        }
Пример #11
0
 public bool ContainsChild(SECSItem child)
 {
     if (this.Format == eSECS_FORMAT.LIST)
     {
         foreach (SECSItem item in this.secslist)
         {
             if (item == child)
             {
                 bool result = true;
                 return(result);
             }
             if (item.ContainsChild(child))
             {
                 bool result = true;
                 return(result);
             }
         }
         return(false);
     }
     return(false);
 }
Пример #12
0
 public XElement SECSItemToXElement(SECSItem root)
 {
     return(this.library.SECSItemToXElement(root));
 }
Пример #13
0
        public override SECSItem XElementToSECSItem(XElement element)
        {
            if (element == null)
            {
                return(null);
            }
            string name = ((string)element.Element("Name")).Trim();
            string desc = ((string)element.Element("Description")).Trim();
            string str3 = ((string)element.Element("Format")).Trim().ToUpper(CultureInfo.InvariantCulture);

            if (str3 == "LIST")
            {
                SECSItem item = new SECSItem(eSECS_FORMAT.LIST, name, desc);
                foreach (XElement element2 in element.Elements("Item"))
                {
                    SECSItem child = this.XElementToSECSItem(element2);
                    item.Add(child);
                }
                return(item);
            }
            SECSItem item2 = null;
            string   data  = ((string)element.Element("Value")).Trim();
            string   key;

            switch (key = str3)
            {
            case "ASCII":
                item2 = new SECSItem(eSECS_FORMAT.ASCII, name, desc);
                break;

            case "CHAR2":
                item2 = new SECSItem(eSECS_FORMAT.CHAR2, name, desc);
                break;

            case "BINARY":
                item2 = new SECSItem(eSECS_FORMAT.BINARY, name, desc);
                break;

            case "BOOLEAN":
                item2 = new SECSItem(eSECS_FORMAT.BOOLEAN, name, desc);
                break;

            case "I1":
                item2 = new SECSItem(eSECS_FORMAT.I1, name, desc);
                break;

            case "I2":
                item2 = new SECSItem(eSECS_FORMAT.I2, name, desc);
                break;

            case "I4":
                item2 = new SECSItem(eSECS_FORMAT.I4, name, desc);
                break;

            case "I8":
                item2 = new SECSItem(eSECS_FORMAT.I8, name, desc);
                break;

            case "U1":
                item2 = new SECSItem(eSECS_FORMAT.U1, name, desc);
                break;

            case "U2":
                item2 = new SECSItem(eSECS_FORMAT.U2, name, desc);
                break;

            case "U4":
                item2 = new SECSItem(eSECS_FORMAT.U4, name, desc);
                break;

            case "U8":
                item2 = new SECSItem(eSECS_FORMAT.U8, name, desc);
                break;

            case "F4":
                item2 = new SECSItem(eSECS_FORMAT.F4, name, desc);
                break;

            case "F8":
                item2 = new SECSItem(eSECS_FORMAT.F8, name, desc);
                break;

            case "JIS-8":
            case "JIS8":
                item2 = new SECSItem(eSECS_FORMAT.JIS8, name, desc);
                break;
            }
            if (string.IsNullOrEmpty(data))
            {
                if (item2 != null)
                {
                    item2.Value = null;
                }
                return(item2);
            }
            if (item2 != null && (item2.Format == eSECS_FORMAT.ASCII || item2.Format == eSECS_FORMAT.JIS8 || item2.Format == eSECS_FORMAT.CHAR2))
            {
                item2.Value = data;
                return(item2);
            }
            if (item2 != null)
            {
                switch (item2.Format)
                {
                case eSECS_FORMAT.BINARY:
                {
                    byte[] binary = Str2SecsItem.GetBinary(data);
                    if (binary.Length <= 1)
                    {
                        item2.Value = binary[0];
                        return(item2);
                    }
                    item2.Value = binary;
                    return(item2);
                }

                case eSECS_FORMAT.BOOLEAN:
                {
                    bool[] boolean = Str2SecsItem.GetBoolean(data);
                    if (boolean.Length != 1)
                    {
                        item2.Value = boolean;
                        return(item2);
                    }
                    item2.Value = boolean[0];
                    return(item2);
                }

                case eSECS_FORMAT.I8:
                {
                    long[] numArray7 = Str2SecsItem.GetI8(data);
                    if (numArray7.Length != 1)
                    {
                        item2.Value = numArray7;
                        return(item2);
                    }
                    item2.Value = numArray7[0];
                    return(item2);
                }

                case eSECS_FORMAT.I1:
                {
                    sbyte[] numArray8 = Str2SecsItem.GetI1(data);
                    if (numArray8.Length != 1)
                    {
                        item2.Value = numArray8;
                        return(item2);
                    }
                    item2.Value = numArray8[0];
                    return(item2);
                }

                case eSECS_FORMAT.I2:
                {
                    short[] numArray9 = Str2SecsItem.GetI2(data);
                    if (numArray9.Length != 1)
                    {
                        item2.Value = numArray9;
                        return(item2);
                    }
                    item2.Value = numArray9[0];
                    return(item2);
                }

                case (eSECS_FORMAT)27:
                case (eSECS_FORMAT)29:
                case (eSECS_FORMAT)30:
                case (eSECS_FORMAT)31:
                    return(item2);

                case eSECS_FORMAT.I4:
                {
                    int[] numArray10 = Str2SecsItem.GetI4(data);
                    if (numArray10.Length != 1)
                    {
                        item2.Value = numArray10;
                        return(item2);
                    }
                    item2.Value = numArray10[0];
                    return(item2);
                }

                case eSECS_FORMAT.F8:
                {
                    double[] numArray11 = Str2SecsItem.GetF8(data);
                    if (numArray11.Length != 1)
                    {
                        item2.Value = numArray11;
                        return(item2);
                    }
                    item2.Value = numArray11[0];
                    return(item2);
                }

                case eSECS_FORMAT.F4:
                {
                    float[] numArray12 = Str2SecsItem.GetF4(data);
                    if (numArray12.Length != 1)
                    {
                        item2.Value = numArray12;
                        return(item2);
                    }
                    item2.Value = numArray12[0];
                    return(item2);
                }

                case (eSECS_FORMAT)37:
                case (eSECS_FORMAT)38:
                case (eSECS_FORMAT)39:
                case (eSECS_FORMAT)43:
                    return(item2);

                case eSECS_FORMAT.U8:
                {
                    ulong[] numArray13 = Str2SecsItem.GetU8(data);
                    if (numArray13.Length != 1)
                    {
                        item2.Value = numArray13;
                        return(item2);
                    }
                    item2.Value = numArray13[0];
                    return(item2);
                }

                case eSECS_FORMAT.U1:
                {
                    byte[] buffer2 = Str2SecsItem.GetU1(data);
                    if (buffer2.Length != 1)
                    {
                        item2.Value = buffer2;
                        return(item2);
                    }
                    item2.Value = buffer2[0];
                    return(item2);
                }

                case eSECS_FORMAT.U2:
                {
                    ushort[] numArray14 = Str2SecsItem.GetU2(data);
                    if (numArray14.Length != 1)
                    {
                        item2.Value = numArray14;
                        return(item2);
                    }
                    item2.Value = numArray14[0];
                    return(item2);
                }

                case eSECS_FORMAT.U4:
                {
                    uint[] numArray15 = Str2SecsItem.GetU4(data);
                    if (numArray15.Length != 1)
                    {
                        item2.Value = numArray15;
                        return(item2);
                    }
                    item2.Value = numArray15[0];
                    return(item2);
                }
                }
            }
            return(item2);
        }
Пример #14
0
        public override XElement SECSItemToXElement(SECSItem root)
        {
            if (root == null)
            {
                return(null);
            }
            XElement element = new XElement("Item");

            element.Add(new XElement("Name", new XText(root.Name)));
            element.Add(new XElement("Description", new XText(root.Description)));
            if (root.Format == eSECS_FORMAT.LIST)
            {
                XElement element2 = new XElement("Format", new XText("List"));
                element.Add(element2);
                for (int i = 0; i < root.ItemCount; i++)
                {
                    XElement element3 = this.SECSItemToXElement(root.Item(i + 1));
                    element.Add(element3);
                }
                return(element);
            }
            XElement     element4 = new XElement("Format");
            XText        text     = null;
            eSECS_FORMAT format   = root.Format;

            if (format <= eSECS_FORMAT.I4)
            {
                switch (format)
                {
                case eSECS_FORMAT.BINARY:
                    text = new XText("Binary");
                    break;

                case eSECS_FORMAT.BOOLEAN:
                    text = new XText("Boolean");
                    break;

                default:
                    switch (format)
                    {
                    case eSECS_FORMAT.ASCII:
                        text = new XText("ASCII");
                        break;

                    case eSECS_FORMAT.JIS8:
                        text = new XText("JIS8");
                        break;

                    case eSECS_FORMAT.CHAR2:
                        text = new XText("CHAR2");
                        break;

                    case eSECS_FORMAT.I8:
                        text = new XText("I8");
                        break;

                    case eSECS_FORMAT.I1:
                        text = new XText("I1");
                        break;

                    case eSECS_FORMAT.I2:
                        text = new XText("I2");
                        break;

                    case eSECS_FORMAT.I4:
                        text = new XText("I4");
                        break;
                    }
                    break;
                }
            }
            else if (format != eSECS_FORMAT.F8)
            {
                switch (format)
                {
                case eSECS_FORMAT.F4:
                    text = new XText("F4");
                    break;

                case eSECS_FORMAT.U8:
                    text = new XText("U8");
                    break;

                case eSECS_FORMAT.U1:
                    text = new XText("U1");
                    break;

                case eSECS_FORMAT.U2:
                    text = new XText("U2");
                    break;

                case eSECS_FORMAT.U4:
                    text = new XText("U4");
                    break;
                }
            }
            else
            {
                text = new XText("F8");
            }
            element4.Add(text);
            element.Add(element4);
            XElement element5 = new XElement("Value");
            XText    text2    = null;

            if (root.IsEmpty)
            {
                text2 = new XText("");
            }
            else
            {
                eSECS_FORMAT format2 = root.Format;
                if (format2 <= eSECS_FORMAT.I4)
                {
                    switch (format2)
                    {
                    case eSECS_FORMAT.BINARY:
                        if (!root.IsArray)
                        {
                            text2 = new XText(root.Value.ToString().Trim());
                        }
                        else
                        {
                            text2 = new XText(SecsItem2Str.GetBinaryStr((byte[])root.Value).Trim());
                        }
                        break;

                    case eSECS_FORMAT.BOOLEAN:
                        if (!root.IsArray)
                        {
                            text2 = new XText(SecsItem2Str.GetBooleanStr(new bool[]
                            {
                                (bool)root.Value
                            }));
                        }
                        else
                        {
                            text2 = new XText(SecsItem2Str.GetBooleanStr((bool[])root.Value));
                        }
                        break;

                    default:
                        switch (format2)
                        {
                        case eSECS_FORMAT.ASCII:
                            text2 = new XText((string)root.Value);
                            break;

                        case eSECS_FORMAT.JIS8:
                            text2 = new XText((string)root.Value);
                            break;

                        case eSECS_FORMAT.CHAR2:
                            text2 = new XText((string)root.Value);
                            break;

                        case eSECS_FORMAT.I8:
                            if (!root.IsArray)
                            {
                                text2 = new XText(SecsItem2Str.GetI8Str(new long[]
                                {
                                    (long)root.Value
                                }));
                            }
                            else
                            {
                                text2 = new XText(SecsItem2Str.GetI8Str((long[])root.Value));
                            }
                            break;

                        case eSECS_FORMAT.I1:
                            if (!root.IsArray)
                            {
                                text2 = new XText(SecsItem2Str.GetI1Str(new sbyte[]
                                {
                                    (sbyte)root.Value
                                }));
                            }
                            else
                            {
                                text2 = new XText(SecsItem2Str.GetI1Str((sbyte[])root.Value));
                            }
                            break;

                        case eSECS_FORMAT.I2:
                            if (!root.IsArray)
                            {
                                text2 = new XText(SecsItem2Str.GetI2Str(new short[]
                                {
                                    (short)root.Value
                                }));
                            }
                            else
                            {
                                text2 = new XText(SecsItem2Str.GetI2Str((short[])root.Value));
                            }
                            break;

                        case eSECS_FORMAT.I4:
                            if (!root.IsArray)
                            {
                                text2 = new XText(SecsItem2Str.GetI4Str(new int[]
                                {
                                    (int)root.Value
                                }));
                            }
                            else
                            {
                                text2 = new XText(SecsItem2Str.GetI4Str((int[])root.Value));
                            }
                            break;
                        }
                        break;
                    }
                }
                else if (format2 != eSECS_FORMAT.F8)
                {
                    switch (format2)
                    {
                    case eSECS_FORMAT.F4:
                        if (!root.IsArray)
                        {
                            text2 = new XText(SecsItem2Str.GetF4Str(new float[]
                            {
                                (float)root.Value
                            }));
                        }
                        else
                        {
                            text2 = new XText(SecsItem2Str.GetF4Str((float[])root.Value));
                        }
                        break;

                    case eSECS_FORMAT.U8:
                        if (!root.IsArray)
                        {
                            text2 = new XText(SecsItem2Str.GetU8Str(new ulong[]
                            {
                                (ulong)root.Value
                            }));
                        }
                        else
                        {
                            text2 = new XText(SecsItem2Str.GetU8Str((ulong[])root.Value));
                        }
                        break;

                    case eSECS_FORMAT.U1:
                        if (!root.IsArray)
                        {
                            text2 = new XText(SecsItem2Str.GetU1Str(new byte[]
                            {
                                (byte)root.Value
                            }));
                        }
                        else
                        {
                            text2 = new XText(SecsItem2Str.GetU1Str((byte[])root.Value));
                        }
                        break;

                    case eSECS_FORMAT.U2:
                        if (!root.IsArray)
                        {
                            text2 = new XText(SecsItem2Str.GetU2Str(new ushort[]
                            {
                                (ushort)root.Value
                            }));
                        }
                        else
                        {
                            text2 = new XText(SecsItem2Str.GetU2Str((ushort[])root.Value));
                        }
                        break;

                    case eSECS_FORMAT.U4:
                        if (!root.IsArray)
                        {
                            text2 = new XText(SecsItem2Str.GetU4Str(new uint[]
                            {
                                (uint)root.Value
                            }));
                        }
                        else
                        {
                            text2 = new XText(SecsItem2Str.GetU4Str((uint[])root.Value));
                        }
                        break;
                    }
                }
                else if (root.IsArray)
                {
                    text2 = new XText(SecsItem2Str.GetF8Str((double[])root.Value));
                }
                else
                {
                    text2 = new XText(SecsItem2Str.GetF8Str(new double[]
                    {
                        (double)root.Value
                    }));
                }
            }
            element5.Add(text2);
            element.Add(element5);
            return(element);
        }
Пример #15
0
        private SECSItem DecodeDataItem(eSECS_FORMAT format, int lengthBytes)
        {
            int      aLength = this.getBinaryLength(lengthBytes);
            SECSItem item    = new SECSItem(format);

            if (format <= eSECS_FORMAT.BOOLEAN)
            {
                if (format == eSECS_FORMAT.LIST)
                {
                    item.Name = "L";
                    for (int i = 0; i < aLength; i++)
                    {
                        byte num3 = this.mDataItem[this.mReadIndex];
                        this.mReadIndex++;
                        int num4 = num3 >> 2;
                        int num5 = (int)(num3 & 3);
                        item.Add(this.DecodeDataItem((eSECS_FORMAT)num4, num5));
                    }
                    return(item);
                }
                switch (format)
                {
                case eSECS_FORMAT.BINARY:
                {
                    byte[] buffer2 = this.ParseBinary(aLength);
                    item.Value = buffer2;
                    return(item);
                }

                case eSECS_FORMAT.BOOLEAN:
                {
                    bool[] flagArray = this.ParseBoolean(aLength);
                    if (flagArray.Length <= 1)
                    {
                        if (flagArray.Length == 1)
                        {
                            item.Value = flagArray[0];
                        }
                        return(item);
                    }
                    item.Value = flagArray;
                    return(item);
                }
                }
            }
            else
            {
                switch (format)
                {
                case eSECS_FORMAT.ASCII:
                {
                    string str = this.ParseAscii(aLength);
                    item.Length = aLength;
                    item.Value  = str;
                    return(item);
                }

                case eSECS_FORMAT.JIS8:
                    item.Value = this.ParseJIS8(aLength);
                    return(item);

                case eSECS_FORMAT.CHAR2:
                    item.Value = this.ParseChar2(aLength);
                    return(item);

                case (eSECS_FORMAT)19:
                case (eSECS_FORMAT)20:
                case (eSECS_FORMAT)21:
                case (eSECS_FORMAT)22:
                case (eSECS_FORMAT)23:
                case (eSECS_FORMAT)27:
                    break;

                case eSECS_FORMAT.I8:
                {
                    long[] numArray4 = this.ParseInt8(aLength);
                    if (numArray4.Length <= 1)
                    {
                        if (numArray4.Length == 1)
                        {
                            item.Value = numArray4[0];
                        }
                        return(item);
                    }
                    item.Value = numArray4;
                    return(item);
                }

                case eSECS_FORMAT.I1:
                {
                    sbyte[] numArray5 = this.ParseInt1(aLength);
                    if (numArray5.Length <= 1)
                    {
                        if (numArray5.Length == 1)
                        {
                            item.Value = numArray5[0];
                        }
                        return(item);
                    }
                    item.Value = numArray5;
                    return(item);
                }

                case eSECS_FORMAT.I2:
                {
                    short[] numArray6 = this.ParseInt2(aLength);
                    if (numArray6.Length <= 1)
                    {
                        if (numArray6.Length == 1)
                        {
                            item.Value = numArray6[0];
                        }
                        return(item);
                    }
                    item.Value = numArray6;
                    return(item);
                }

                case eSECS_FORMAT.I4:
                {
                    int[] numArray7 = this.ParseInt4(aLength);
                    if (numArray7.Length <= 1)
                    {
                        if (numArray7.Length == 1)
                        {
                            item.Value = numArray7[0];
                        }
                        return(item);
                    }
                    item.Value = numArray7;
                    return(item);
                }

                default:
                    if (format != eSECS_FORMAT.F8)
                    {
                        switch (format)
                        {
                        case eSECS_FORMAT.F4:
                        {
                            float[] numArray8 = this.ParseFloat(aLength);
                            if (numArray8.Length <= 1)
                            {
                                if (numArray8.Length == 1)
                                {
                                    item.Value = numArray8[0];
                                }
                                return(item);
                            }
                            item.Value = numArray8;
                            return(item);
                        }

                        case eSECS_FORMAT.U8:
                        {
                            ulong[] numArray9 = this.ParseUInt8(aLength);
                            if (numArray9.Length <= 1)
                            {
                                if (numArray9.Length == 1)
                                {
                                    item.Value = numArray9[0];
                                }
                                return(item);
                            }
                            item.Value = numArray9;
                            return(item);
                        }

                        case eSECS_FORMAT.U1:
                        {
                            byte[] buffer3 = this.ParseUInt1(aLength);
                            if (buffer3.Length <= 1)
                            {
                                if (buffer3.Length == 1)
                                {
                                    item.Value = buffer3[0];
                                }
                                return(item);
                            }
                            item.Value = buffer3;
                            return(item);
                        }

                        case eSECS_FORMAT.U2:
                        {
                            ushort[] numArray10 = this.ParseUInt2(aLength);
                            if (numArray10.Length <= 1)
                            {
                                if (numArray10.Length == 1)
                                {
                                    item.Value = numArray10[0];
                                }
                                return(item);
                            }
                            item.Value = numArray10;
                            return(item);
                        }

                        case eSECS_FORMAT.U4:
                        {
                            uint[] numArray11 = this.ParseUInt4(aLength);
                            if (numArray11.Length <= 1)
                            {
                                if (numArray11.Length == 1)
                                {
                                    item.Value = numArray11[0];
                                }
                                return(item);
                            }
                            item.Value = numArray11;
                            return(item);
                        }
                        }
                    }
                    else
                    {
                        double[] numArray12 = this.ParseDouble(aLength);
                        if (numArray12.Length > 1)
                        {
                            item.Value = numArray12;
                            return(item);
                        }
                        if (numArray12.Length == 1)
                        {
                            item.Value = numArray12[0];
                        }
                        return(item);
                    }
                    break;
                }
            }
            throw new Exception("Format Not meet the SECS standard");
        }
Пример #16
0
 internal abstract bool CheckSecsItemFormat(ref SECSItem rcvd, ref SECSItem format);
Пример #17
0
        internal static string GetSecsItemStr(int level, SECSItem data)
        {
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < level; i++)
            {
                builder.Append("    ");
            }
            eSECS_FORMAT format = data.Format;

            if (format == eSECS_FORMAT.LIST)
            {
                builder.Append("<L [");
                builder.Append(data.ItemCount);
                builder.Append("]\n");
                int itemCount = data.ItemCount;
                if (itemCount > 0)
                {
                    for (int j = 0; j < itemCount; j++)
                    {
                        builder.Append(SecsItem2Str.GetSecsItemStr(level + 1, data.Item(j + 1)));
                    }
                }
                for (int k = 0; k < level; k++)
                {
                    builder.Append("    ");
                }
                builder.Append(">\n");
            }
            else
            {
                eSECS_FORMAT eSECSFORMAT = format;
                if (eSECSFORMAT <= eSECS_FORMAT.ASCII)
                {
                    switch (eSECSFORMAT)
                    {
                    case eSECS_FORMAT.BINARY:
                        if (data.IsEmpty)
                        {
                            builder.Append("<B [0] ''>\n");
                        }
                        else
                        {
                            byte[] buffer;
                            if (!data.IsArray)
                            {
                                buffer = new byte[]
                                {
                                    (byte)data.Value
                                };
                            }
                            else
                            {
                                buffer = (byte[])data.Value;
                            }
                            string binaryStr = SecsItem2Str.GetBinaryStr(buffer);
                            builder.Append("<B [");
                            builder.Append(buffer.Length);
                            builder.Append("] '");
                            builder.Append(binaryStr);
                            builder.Append("' >\n");
                        }
                        break;

                    case eSECS_FORMAT.BOOLEAN:
                        if (!data.IsEmpty)
                        {
                            bool[] flagArray;
                            if (!data.IsArray)
                            {
                                flagArray = new bool[]
                                {
                                    (bool)data.Value
                                };
                            }
                            else
                            {
                                flagArray = (bool[])data.Value;
                            }
                            string booleanStr = SecsItem2Str.GetBooleanStr(flagArray);
                            builder.Append("<BOOLEAN [");
                            builder.Append(flagArray.Length);
                            builder.Append("] ");
                            builder.Append(booleanStr);
                            builder.Append(" >\n");
                        }
                        break;

                    default:
                        if (eSECSFORMAT == eSECS_FORMAT.ASCII)
                        {
                            string str = "";
                            if (!data.IsEmpty)
                            {
                                str = (string)data.Value;
                            }
                            builder.Append("<A [");
                            builder.Append(str.Length);
                            builder.Append("] '");
                            builder.Append(str);
                            builder.Append("' >\n");
                        }
                        break;
                    }
                }
                else
                {
                    switch (eSECSFORMAT)
                    {
                    case eSECS_FORMAT.I8:
                        if (!data.IsEmpty)
                        {
                            long[] numArray8;
                            if (!data.IsArray)
                            {
                                numArray8 = new long[]
                                {
                                    (long)data.Value
                                };
                            }
                            else
                            {
                                numArray8 = (long[])data.Value;
                            }
                            string str2 = SecsItem2Str.GetI8Str(numArray8);
                            builder.Append("<I8 [");
                            builder.Append(numArray8.Length);
                            builder.Append("] ");
                            builder.Append(str2);
                            builder.Append(" >\n");
                        }
                        break;

                    case eSECS_FORMAT.I1:
                        if (!data.IsEmpty)
                        {
                            sbyte[] numArray9;
                            if (!data.IsArray)
                            {
                                numArray9 = new sbyte[]
                                {
                                    (sbyte)data.Value
                                };
                            }
                            else
                            {
                                numArray9 = (sbyte[])data.Value;
                            }
                            string str3 = SecsItem2Str.GetI1Str(numArray9);
                            builder.Append("<I1 [");
                            builder.Append(numArray9.Length);
                            builder.Append("] ");
                            builder.Append(str3);
                            builder.Append(" >\n");
                        }
                        break;

                    case eSECS_FORMAT.I2:
                        if (!data.IsEmpty)
                        {
                            short[] numArray10;
                            if (!data.IsArray)
                            {
                                numArray10 = new short[]
                                {
                                    (short)data.Value
                                };
                            }
                            else
                            {
                                numArray10 = (short[])data.Value;
                            }
                            string str4 = SecsItem2Str.GetI2Str(numArray10);
                            builder.Append("<I2 [");
                            builder.Append(numArray10.Length);
                            builder.Append("] ");
                            builder.Append(str4);
                            builder.Append(" >\n");
                        }
                        break;

                    case (eSECS_FORMAT)27:
                    case (eSECS_FORMAT)29:
                    case (eSECS_FORMAT)30:
                    case (eSECS_FORMAT)31:
                        break;

                    case eSECS_FORMAT.I4:
                        if (!data.IsEmpty)
                        {
                            int[] numArray11;
                            if (!data.IsArray)
                            {
                                numArray11 = new int[]
                                {
                                    (int)data.Value
                                };
                            }
                            else
                            {
                                numArray11 = (int[])data.Value;
                            }
                            string str5 = SecsItem2Str.GetI4Str(numArray11);
                            builder.Append("<I4 [");
                            builder.Append(numArray11.Length);
                            builder.Append("] ");
                            builder.Append(str5);
                            builder.Append(" >\n");
                        }
                        break;

                    case eSECS_FORMAT.F8:
                        if (!data.IsEmpty)
                        {
                            double[] numArray12;
                            if (data.IsArray)
                            {
                                numArray12 = (double[])data.Value;
                            }
                            else
                            {
                                numArray12 = new double[]
                                {
                                    (double)data.Value
                                };
                            }
                            string str6 = SecsItem2Str.GetF8Str(numArray12);
                            builder.Append("<F8 [");
                            builder.Append(numArray12.Length);
                            builder.Append("] ");
                            builder.Append(str6);
                            builder.Append(" >\n");
                        }
                        break;

                    default:
                        switch (eSECSFORMAT)
                        {
                        case eSECS_FORMAT.F4:
                            if (!data.IsEmpty)
                            {
                                float[] numArray13;
                                if (!data.IsArray)
                                {
                                    numArray13 = new float[]
                                    {
                                        (float)data.Value
                                    };
                                }
                                else
                                {
                                    numArray13 = (float[])data.Value;
                                }
                                string str7 = SecsItem2Str.GetF4Str(numArray13);
                                builder.Append("<F4 [");
                                builder.Append(numArray13.Length);
                                builder.Append("] ");
                                builder.Append(str7);
                                builder.Append(" >\n");
                            }
                            break;

                        case eSECS_FORMAT.U8:
                            if (!data.IsEmpty)
                            {
                                ulong[] numArray14;
                                if (!data.IsArray)
                                {
                                    numArray14 = new ulong[]
                                    {
                                        (ulong)data.Value
                                    };
                                }
                                else
                                {
                                    numArray14 = (ulong[])data.Value;
                                }
                                string str8 = SecsItem2Str.GetU8Str(numArray14);
                                builder.Append("<U8 [");
                                builder.Append(numArray14.Length);
                                builder.Append("] ");
                                builder.Append(str8);
                                builder.Append(" >\n");
                            }
                            break;

                        case eSECS_FORMAT.U1:
                            if (!data.IsEmpty)
                            {
                                byte[] buffer2;
                                if (!data.IsArray)
                                {
                                    buffer2 = new byte[]
                                    {
                                        (byte)data.Value
                                    };
                                }
                                else
                                {
                                    buffer2 = (byte[])data.Value;
                                }
                                string str9 = SecsItem2Str.GetU1Str(buffer2);
                                builder.Append("<U1 [");
                                builder.Append(buffer2.Length);
                                builder.Append("] ");
                                builder.Append(str9);
                                builder.Append(" >\n");
                            }
                            break;

                        case eSECS_FORMAT.U2:
                            if (!data.IsEmpty)
                            {
                                ushort[] numArray15;
                                if (!data.IsArray)
                                {
                                    numArray15 = new ushort[]
                                    {
                                        (ushort)data.Value
                                    };
                                }
                                else
                                {
                                    numArray15 = (ushort[])data.Value;
                                }
                                string str10 = SecsItem2Str.GetU2Str(numArray15);
                                builder.Append("<U2 [");
                                builder.Append(numArray15.Length);
                                builder.Append("] ");
                                builder.Append(str10);
                                builder.Append(" >\n");
                            }
                            break;

                        case eSECS_FORMAT.U4:
                            if (!data.IsEmpty)
                            {
                                uint[] numArray16;
                                if (!data.IsArray)
                                {
                                    numArray16 = new uint[]
                                    {
                                        (uint)data.Value
                                    };
                                }
                                else
                                {
                                    numArray16 = (uint[])data.Value;
                                }
                                string str11 = SecsItem2Str.GetU4Str(numArray16);
                                builder.Append("<U4 [");
                                builder.Append(numArray16.Length);
                                builder.Append("] ");
                                builder.Append(str11);
                                builder.Append(" >\n");
                            }
                            break;
                        }
                        break;
                    }
                }
            }
            return(builder.ToString());
        }
Пример #18
0
 public abstract XElement SECSItemToXElement(SECSItem root);
Пример #19
0
 private void RcvdData(byte data)
 {
     if (this.secs1.PortStatus == eSECS1_PORT_STATUS.PortRcvd)
     {
         lock (this.syncRcvd)
         {
             this.rcvdBlock.Add(data);
             if (this.rcvdBlockLength == 0)
             {
                 this.rcvdBlockLength = (int)this.rcvdBlock[0];
                 this.secs1.StopTimer(eTimeout.T2);
                 if (this.rcvdBlockLength < 10 || this.rcvdBlockLength > 254)
                 {
                     this.Logger.Debug(string.Format("RECV Invalid Length Bytes: {0}.", this.rcvdBlockLength));
                     this.rcvdBlockLength = 0;
                     this.rcvdBlock.Clear();
                     this.secs1.UpdatePortStatus(eSECS1_PORT_STATUS.PortRcvd, eSECS1_PORT_STATUS.PortCmpl);
                     this.secs1.StartTimer(eTimeout.T1);
                     goto IL_3E2;
                 }
             }
             else
             {
                 this.secs1.StopTimer(eTimeout.T1);
             }
             byte[] buffer = this.rcvdBlock.ToArray();
             if (this.rcvdBlockLength == this.rcvdBlock.Count - 3)
             {
                 byte[] buffer2 = new byte[10];
                 Array.Copy(buffer, 1, buffer2, 0, 10);
                 byte[] buffer3 = new byte[2];
                 Array.Copy(buffer, buffer.Length - 2, buffer3, 0, 2);
                 byte[] buffer4 = new byte[buffer.Length - 13];
                 Array.Copy(buffer, buffer2.Length + 1, buffer4, 0, buffer4.Length);
                 //this.Logger.Info(string.Format("[RECV] HDR = {0}\nDATA = {1}\nCSUM = {2}", SecsItem2Str.GetBinaryStr(buffer2), SecsItem2Str.GetBinaryStr(buffer4), SecsItem2Str.GetBinaryStr(buffer3)));
                 int num  = (int)buffer3[0] << 8 | (int)buffer3[1];
                 int num2 = (int)(buffer2[4] & 128);
                 int num3 = 0;
                 for (int i = 1; i < this.rcvdBlock.Count - 2; i++)
                 {
                     num3 += (int)this.rcvdBlock[i];
                 }
                 if (num != num3)
                 {
                     this.secs1.UpdatePortStatus(this.secs1.PortStatus, eSECS1_PORT_STATUS.PortIdle);
                     this.secs1.SendNAK();
                     this.Logger.Debug("Checksum not match, Reply to send NAK.");
                 }
                 else
                 {
                     if (this.rcvdBlocks.Count > 0)
                     {
                         this.secs1.StopTimer(eTimeout.T4);
                     }
                     this.secs1.UpdatePortStatus(this.secs1.PortStatus, eSECS1_PORT_STATUS.PortIdle);
                     this.secs1.SendACK();
                     if (num2 == 0)
                     {
                         SECSBlock block = new SECSBlock
                         {
                             Header   = buffer2,
                             DataItem = buffer4,
                             CheckSum = buffer3
                         };
                         this.rcvdBlocks.Add(block);
                         this.Logger.Debug("RECV One of Multi-Block Ok, Send ACK.");
                         this.secs1.StartTimer(eTimeout.T4);
                     }
                     else if (this.rcvdBlocks.Count == 0)
                     {
                         this.Logger.Debug("RECV Single-Block Message Ok, Send ACK.");
                         SECSDecoding decoding = new SECSDecoding();
                         SECSMessage  msg      = decoding.Byte_TO_SecsMessage(buffer2);
                         SECSItem     item     = decoding.Byte_TO_SecsItem(buffer4);
                         if (item != null)
                         {
                             msg.Root = item;
                         }
                         this.eventExecutor.NofityRECV(msg);
                     }
                     else
                     {
                         this.Logger.Debug("RECV Multi-Block Message Ok, Send ACK.");
                         SECSDecoding decoding2 = new SECSDecoding();
                         SECSMessage  message2  = decoding2.Byte_TO_SecsMessage(buffer2);
                         List <byte>  list      = new List <byte>();
                         for (int j = 0; j < this.rcvdBlocks.Count; j++)
                         {
                             list.AddRange(this.rcvdBlocks[j].DataItem);
                         }
                         this.rcvdBlocks.Clear();
                         list.AddRange(buffer4);
                         byte[]   aDataByte = list.ToArray();
                         SECSItem item2     = decoding2.Byte_TO_SecsItem(aDataByte);
                         if (item2 != null)
                         {
                             message2.Root = item2;
                         }
                         this.eventExecutor.NofityRECV(message2);
                     }
                 }
             }
             else
             {
                 this.secs1.StartTimer(eTimeout.T1);
             }
             IL_3E2 :;
         }
         return;
     }
     if (this.secs1.PortStatus == eSECS1_PORT_STATUS.PortCmpl)
     {
         this.secs1.StopTimer(eTimeout.T1);
         this.Logger.Info(string.Format("PortCmpl, Invalid data {0}", data));
         this.secs1.StartTimer(eTimeout.T1);
         return;
     }
     this.Logger.Info(string.Format("Invalid Status - {0}, Invalid data: {1}", this.secs1.PortStatus, data));
 }
Пример #20
0
 internal bool CheckSecsItemFormat(ref SECSItem rcvd, ref SECSItem format)
 {
     return(this.library.CheckSecsItemFormat(ref rcvd, ref format));
 }
Пример #21
0
        public override XElement SECSItemToXElement(SECSItem root)
        {
            if (root == null)
            {
                return(null);
            }
            if (root.Format == eSECS_FORMAT.LIST)
            {
                XElement element = new XElement("L");
                element.SetAttributeValue("Count", root.ItemCount.ToString(CultureInfo.InvariantCulture));
                element.SetAttributeValue("Fixed", root.Fixed ? "True" : "False");
                element.SetAttributeValue("ItemName", root.Name);
                for (int i = 1; i <= root.ItemCount; i++)
                {
                    element.Add(this.SECSItemToXElement(root.Item(i)));
                }
                return(element);
            }
            XElement element2 = new XElement(SECSFormat2.Format2Str((int)root.Format));

            element2.SetAttributeValue("Count", root.ItemCount.ToString(CultureInfo.InvariantCulture));
            element2.SetAttributeValue("Fixed", root.Fixed ? "True" : "False");
            element2.SetAttributeValue("ItemName", root.Name);
            if (root.IsEmpty)
            {
                element2.Value = "";
                return(element2);
            }
            eSECS_FORMAT format = root.Format;

            if (format <= eSECS_FORMAT.I4)
            {
                switch (format)
                {
                case eSECS_FORMAT.BINARY:
                    element2.Value = SecsItem2Str.GetBinaryStr(root.Value as byte[]);
                    return(element2);

                case eSECS_FORMAT.BOOLEAN:
                    if (!root.IsArray)
                    {
                        bool[] data = new bool[]
                        {
                            (bool)root.Value
                        };
                        element2.Value = SecsItem2Str.GetBooleanStr(data);
                        return(element2);
                    }
                    element2.Value = SecsItem2Str.GetBooleanStr(root.Value as bool[]);
                    return(element2);

                case eSECS_FORMAT.ASCII:
                    element2.Value = (string)root.Value;
                    return(element2);

                case eSECS_FORMAT.JIS8:
                    element2.Value = (string)root.Value;
                    return(element2);

                case eSECS_FORMAT.CHAR2:
                    element2.Value = (string)root.Value;
                    return(element2);

                case (eSECS_FORMAT)19:
                case (eSECS_FORMAT)20:
                case (eSECS_FORMAT)21:
                case (eSECS_FORMAT)22:
                case (eSECS_FORMAT)23:
                case (eSECS_FORMAT)27:
                    return(element2);

                case eSECS_FORMAT.I8:
                    if (!root.IsArray)
                    {
                        long[] numArray9 = new long[]
                        {
                            (long)root.Value
                        };
                        element2.Value = SecsItem2Str.GetI8Str(numArray9);
                        return(element2);
                    }
                    element2.Value = SecsItem2Str.GetI8Str(root.Value as long[]);
                    return(element2);

                case eSECS_FORMAT.I1:
                    if (!root.IsArray)
                    {
                        sbyte[] numArray10 = new sbyte[]
                        {
                            (sbyte)root.Value
                        };
                        element2.Value = SecsItem2Str.GetI1Str(numArray10);
                        return(element2);
                    }
                    element2.Value = SecsItem2Str.GetI1Str(root.Value as sbyte[]);
                    return(element2);

                case eSECS_FORMAT.I2:
                    if (!root.IsArray)
                    {
                        short[] numArray11 = new short[]
                        {
                            (short)root.Value
                        };
                        element2.Value = SecsItem2Str.GetI2Str(numArray11);
                        return(element2);
                    }
                    element2.Value = SecsItem2Str.GetI2Str(root.Value as short[]);
                    return(element2);

                case eSECS_FORMAT.I4:
                    if (!root.IsArray)
                    {
                        int[] numArray12 = new int[]
                        {
                            (int)root.Value
                        };
                        element2.Value = SecsItem2Str.GetI4Str(numArray12);
                        return(element2);
                    }
                    element2.Value = SecsItem2Str.GetI4Str(root.Value as int[]);
                    return(element2);
                }
                return(element2);
            }
            switch (format)
            {
            case eSECS_FORMAT.F8:
            {
                if (root.IsArray)
                {
                    element2.Value = SecsItem2Str.GetF8Str(root.Value as double[]);
                    return(element2);
                }
                double[] numArray13 = new double[]
                {
                    (double)root.Value
                };
                element2.Value = SecsItem2Str.GetF8Str(numArray13);
                return(element2);
            }

            case eSECS_FORMAT.F4:
                if (!root.IsArray)
                {
                    float[] numArray14 = new float[]
                    {
                        (float)root.Value
                    };
                    element2.Value = SecsItem2Str.GetF4Str(numArray14);
                    return(element2);
                }
                element2.Value = SecsItem2Str.GetF4Str(root.Value as float[]);
                return(element2);

            case (eSECS_FORMAT)37:
            case (eSECS_FORMAT)38:
            case (eSECS_FORMAT)39:
            case (eSECS_FORMAT)43:
                return(element2);

            case eSECS_FORMAT.U8:
                if (!root.IsArray)
                {
                    ulong[] numArray15 = new ulong[]
                    {
                        (ulong)root.Value
                    };
                    element2.Value = SecsItem2Str.GetU8Str(numArray15);
                    return(element2);
                }
                element2.Value = SecsItem2Str.GetU8Str(root.Value as ulong[]);
                return(element2);

            case eSECS_FORMAT.U1:
                if (!root.IsArray)
                {
                    byte[] buffer = new byte[]
                    {
                        (byte)root.Value
                    };
                    element2.Value = SecsItem2Str.GetU1Str(buffer);
                    return(element2);
                }
                element2.Value = SecsItem2Str.GetU1Str(root.Value as byte[]);
                return(element2);

            case eSECS_FORMAT.U2:
                if (!root.IsArray)
                {
                    ushort[] numArray16 = new ushort[]
                    {
                        (ushort)root.Value
                    };
                    element2.Value = SecsItem2Str.GetU2Str(numArray16);
                    return(element2);
                }
                element2.Value = SecsItem2Str.GetU2Str(root.Value as ushort[]);
                return(element2);

            case eSECS_FORMAT.U4:
                if (!root.IsArray)
                {
                    uint[] numArray17 = new uint[]
                    {
                        (uint)root.Value
                    };
                    element2.Value = SecsItem2Str.GetU4Str(numArray17);
                    return(element2);
                }
                element2.Value = SecsItem2Str.GetU4Str(root.Value as uint[]);
                return(element2);
            }
            return(element2);
        }
Пример #22
0
        public override SECSItem XElementToSECSItem(XElement element)
        {
            if (element == null)
            {
                return(null);
            }
            string   str  = element.Name.ToString().Trim().ToUpper();
            SECSItem item = null;

            if (str == "L")
            {
                item = new SECSItem(eSECS_FORMAT.LIST);
                using (IEnumerator <XElement> enumerator = element.Elements().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        XElement element2 = enumerator.Current;
                        SECSItem child    = this.XElementToSECSItem(element2);
                        if (child != null)
                        {
                            item.Add(child);
                        }
                    }
                    goto IL_3F2;
                }
            }
            string data = element.Value.Trim();
            string key;

            switch (key = str)
            {
            case "A":
                item = new SECSItem(eSECS_FORMAT.ASCII)
                {
                    Value = data
                };
                break;

            case "B":
                item = new SECSItem(eSECS_FORMAT.BINARY)
                {
                    Value = Str2SecsItem.GetBinary(data)
                };
                break;

            case "BOOLEAN":
            {
                item = new SECSItem(eSECS_FORMAT.BOOLEAN);
                bool[] boolean = Str2SecsItem.GetBoolean(data);
                if (boolean.Length == 1)
                {
                    item.Value = boolean[0];
                }
                else
                {
                    item.Value = boolean;
                }
                break;
            }

            case "U1":
            {
                item = new SECSItem(eSECS_FORMAT.U1);
                byte[] buffer = Str2SecsItem.GetU1(data);
                if (buffer.Length == 1)
                {
                    item.Value = buffer[0];
                }
                else
                {
                    item.Value = buffer;
                }
                break;
            }

            case "U2":
            {
                item = new SECSItem(eSECS_FORMAT.U2);
                ushort[] numArray = Str2SecsItem.GetU2(data);
                if (numArray.Length == 1)
                {
                    item.Value = numArray[0];
                }
                else
                {
                    item.Value = numArray;
                }
                break;
            }

            case "U4":
            {
                item = new SECSItem(eSECS_FORMAT.U4);
                uint[] numArray2 = Str2SecsItem.GetU4(data);
                if (numArray2.Length == 1)
                {
                    item.Value = numArray2[0];
                }
                else
                {
                    item.Value = numArray2;
                }
                break;
            }

            case "U8":
            {
                item = new SECSItem(eSECS_FORMAT.U8);
                ulong[] numArray3 = Str2SecsItem.GetU8(data);
                if (numArray3.Length == 1)
                {
                    item.Value = numArray3[0];
                }
                else
                {
                    item.Value = numArray3;
                }
                break;
            }

            case "I1":
            {
                item = new SECSItem(eSECS_FORMAT.I1);
                sbyte[] numArray4 = Str2SecsItem.GetI1(data);
                if (numArray4.Length == 1)
                {
                    item.Value = numArray4[0];
                }
                else
                {
                    item.Value = numArray4;
                }
                break;
            }

            case "I2":
            {
                item = new SECSItem(eSECS_FORMAT.I2);
                short[] numArray5 = Str2SecsItem.GetI2(data);
                if (numArray5.Length == 1)
                {
                    item.Value = numArray5[0];
                }
                else
                {
                    item.Value = numArray5;
                }
                break;
            }

            case "I4":
            {
                item = new SECSItem(eSECS_FORMAT.I4);
                int[] numArray6 = Str2SecsItem.GetI4(data);
                if (numArray6.Length == 1)
                {
                    item.Value = numArray6[0];
                }
                else
                {
                    item.Value = numArray6;
                }
                break;
            }

            case "I8":
            {
                item = new SECSItem(eSECS_FORMAT.I8);
                long[] numArray7 = Str2SecsItem.GetI8(data);
                if (numArray7.Length == 1)
                {
                    item.Value = numArray7[0];
                }
                else
                {
                    item.Value = numArray7;
                }
                break;
            }

            case "CHAR2":
                item = new SECSItem(eSECS_FORMAT.CHAR2)
                {
                    Value = data
                };
                break;

            case "JIS8":
                item = new SECSItem(eSECS_FORMAT.JIS8)
                {
                    Value = data
                };
                break;
            }
IL_3F2:
            if (item != null)
            {
                if (element.Attribute("ItemName") != null)
                {
                    item.Name = element.Attribute("ItemName").Value;
                }
                if (element.Attribute("Count") != null)
                {
                    item.Length = int.Parse(element.Attribute("Count").Value);
                }
                if (element.Attribute("Fixed") != null)
                {
                    item.Fixed = (element.Attribute("Fixed").Value.Trim().ToUpper() == "TRUE");
                }
            }
            return(item);
        }
Пример #23
0
        internal override bool CheckSecsItemFormat(ref SECSItem rcvd, ref SECSItem format)
        {
            bool result;

            try
            {
                if (rcvd.Format != format.Format)
                {
                    result = false;
                }
                else if (format.Format == eSECS_FORMAT.LIST)
                {
                    if (format.Fixed)
                    {
                        if (rcvd.ItemCount != format.Length)
                        {
                            result = false;
                        }
                        else
                        {
                            for (int i = 1; i <= format.ItemCount; i++)
                            {
                                SECSItem item  = format.Item(i);
                                SECSItem item2 = rcvd.Item(i);
                                if (!this.CheckSecsItemFormat(ref item2, ref item))
                                {
                                    result = false;
                                    return(result);
                                }
                            }
                            rcvd.Name        = format.Name;
                            rcvd.Description = format.Description;
                            result           = true;
                        }
                    }
                    else if (rcvd.ItemCount > format.Length)
                    {
                        result = false;
                    }
                    else
                    {
                        for (int j = 1; j <= rcvd.ItemCount; j++)
                        {
                            SECSItem item3 = format.Item(1);
                            SECSItem item4 = rcvd.Item(j);
                            if (!this.CheckSecsItemFormat(ref item4, ref item3))
                            {
                                result = false;
                                return(result);
                            }
                        }
                        rcvd.Name        = format.Name;
                        rcvd.Description = format.Description;
                        result           = true;
                    }
                }
                else if (format.Format == eSECS_FORMAT.ASCII)
                {
                    string str = (rcvd.Value as string) ?? "";
                    if (format.Fixed)
                    {
                        if (str.Length > format.Length)
                        {
                            result = false;
                        }
                        else
                        {
                            result = true;
                        }
                    }
                    else if (str.Length > format.Length)
                    {
                        result = false;
                    }
                    else
                    {
                        result = true;
                    }
                }
                else
                {
                    result = true;
                }
            }
            catch (Exception)
            {
                result = false;
            }
            return(result);
        }