Пример #1
0
        static void Main(string[] args)
        {
            //   sbloc y = Encoding.UTF8.GetBytes("len");
            //   sbloc x = Encoding.UTF8.GetBytes("idadi");
            //   //Console.WriteLine(x);
            ////arsslen idadi
            //   //x = x-1;
            //   //Console.WriteLine(x);
            //   x = x + " arsslen";
            //   Console.WriteLine(x.ToString());
            //   x = x - y;
            //   y.StartIndex = 1;
            //   sbloc z = x * y;
            //   Console.WriteLine(x.ToString());

            //   Console.WriteLine(z.ToString());
            //   sbloc[] s = x / 6;
            //   foreach (sbloc a in s)
            //       Console.WriteLine(a.ToString());

            //   usbloc alpha = (usbloc)BitConverter.GetBytes((int)1995) + BitConverter.GetBytes((int)11);
            // alpha = alpha + (byte)11;
            //   int[] arr = alpha;
            //binary a = 45978.789;
            //double b = a;
            //Console.WriteLine(a.ToString());
            //Mathexpr ex = "@(Variable1) + $pi()+$sin(90) + 5 + 6";
            //ex.Define("Variable1",12);
            ////ex += eval_AdditionalFunctionEventHandler;
            //long a = ex;
            numeric a = "1234";
            LReal   x = 1;

            x += 2;
            x--;
            Console.WriteLine(x * 2);
            Console.WriteLine((x * 8));

            //varchar b = "idadi";
            //string asd = a +" "+ b;
            //a = "idadi";
            //Console.WriteLine((a == b));

            Console.Read();
        }
Пример #2
0
        /// <summary>
        /// Given a S7 variable type (Bool, Word, DWord, etc.), it converts the bytes in the appropriate C# format.
        /// </summary>
        /// <param name="varType"></param>
        /// <param name="bytes"></param>
        /// <param name="varCount"></param>
        /// <param name="bitAdr"></param>
        /// <returns></returns>
        private object?ParseBytes(VarType varType, byte[] bytes, int varCount, byte bitAdr = 0)
        {
            if (bytes == null || bytes.Length == 0)
            {
                return(null);
            }

            switch (varType)
            {
            case VarType.Byte:
                if (varCount == 1)
                {
                    return(bytes[0]);
                }
                else
                {
                    return(bytes);
                }

            case VarType.Word:
                if (varCount == 1)
                {
                    return(Word.FromByteArray(bytes));
                }
                else
                {
                    return(Word.ToArray(bytes));
                }

            case VarType.Int:
                if (varCount == 1)
                {
                    return(Int.FromByteArray(bytes));
                }
                else
                {
                    return(Int.ToArray(bytes));
                }

            case VarType.DWord:
                if (varCount == 1)
                {
                    return(DWord.FromByteArray(bytes));
                }
                else
                {
                    return(DWord.ToArray(bytes));
                }

            case VarType.DInt:
                if (varCount == 1)
                {
                    return(DInt.FromByteArray(bytes));
                }
                else
                {
                    return(DInt.ToArray(bytes));
                }

            case VarType.Real:
                if (varCount == 1)
                {
                    return(Real.FromByteArray(bytes));
                }
                else
                {
                    return(Real.ToArray(bytes));
                }

            case VarType.LReal:
                if (varCount == 1)
                {
                    return(LReal.FromByteArray(bytes));
                }
                else
                {
                    return(LReal.ToArray(bytes));
                }

            case VarType.String:
                return(String.FromByteArray(bytes));

            case VarType.S7String:
                return(S7String.FromByteArray(bytes));

            case VarType.Timer:
                if (varCount == 1)
                {
                    return(Timer.FromByteArray(bytes));
                }
                else
                {
                    return(Timer.ToArray(bytes));
                }

            case VarType.Counter:
                if (varCount == 1)
                {
                    return(Counter.FromByteArray(bytes));
                }
                else
                {
                    return(Counter.ToArray(bytes));
                }

            case VarType.Bit:
                if (varCount == 1)
                {
                    if (bitAdr > 7)
                    {
                        return(null);
                    }
                    else
                    {
                        return(Bit.FromByte(bytes[0], bitAdr));
                    }
                }
                else
                {
                    return(Bit.ToBitArray(bytes, varCount));
                }

            case VarType.DateTime:
                if (varCount == 1)
                {
                    return(DateTime.FromByteArray(bytes));
                }
                else
                {
                    return(DateTime.ToArray(bytes));
                }

            case VarType.DateTimeLong:
                if (varCount == 1)
                {
                    return(DateTimeLong.FromByteArray(bytes));
                }
                else
                {
                    return(DateTimeLong.ToArray(bytes));
                }

            default:
                return(null);
            }
        }