예제 #1
0
 private void button_read_ulong_Click(object sender, EventArgs e)
 {
     // 读取ulong变量
     if (textBox1.Text == "1")
     {
         DemoUtils.ReadResultRender(xGBCnet.ReadUInt64(textBox3.Text), textBox3.Text, textBox4);
     }
     else
     {
         DemoUtils.ReadResultRender(xGBCnet.ReadUInt64(textBox3.Text, ushort.Parse(textBox1.Text)), textBox3.Text, textBox4);
     }
 }
예제 #2
0
        public TValue[] Read <TValue>(string address, ushort length)
        {
            if (typeof(TValue) == typeof(bool))
            {
                var b = ReadCoil(address, length);
                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(ushort))
            {
                var b = xGBCnet.ReadUInt16(address, length).Content;

                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(int))
            {
                var b = xGBCnet.ReadInt32(address, length).Content;

                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(uint))
            {
                var b = xGBCnet.ReadUInt32(address, length).Content;
                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(long))
            {
                var b = xGBCnet.ReadInt64(address, length).Content;
                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(ulong))
            {
                var b = xGBCnet.ReadUInt64(address, length).Content;
                return((TValue[])(object)b);
            }

            if (typeof(TValue) == typeof(short))
            {
                var b = xGBCnet.ReadInt16(address, length).Content;
                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(double))
            {
                var b = xGBCnet.ReadDouble(address, length).Content;
                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(float))
            {
                var b = xGBCnet.ReadFloat(address, length).Content;
                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(string))
            {
                var b = xGBCnet.ReadString(address, length).Content;
                return((TValue[])(object)b);
            }

            throw new InvalidOperationException(string.Format("type '{0}' not supported.", typeof(TValue)));
        }
예제 #3
0
 private void button_read_ulong_Click(object sender, EventArgs e)
 {
     // 读取ulong变量
     DemoUtils.ReadResultRender(xGBCnet.ReadUInt64(textBox3.Text), textBox3.Text, textBox4);
 }
예제 #4
0
        public TValue[] Read <TValue>(string address, ushort length)
        {
            if (typeof(TValue) == typeof(bool))
            {
                object b = ReadCoil(address, length);
                return((TValue[])b);
            }
            if (typeof(TValue) == typeof(ushort))
            {
                OperateResult <ushort[]> b = xGBCnet.ReadUInt16(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"{b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }
            if (typeof(TValue) == typeof(int))
            {
                OperateResult <int[]> b = xGBCnet.ReadInt32(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"{b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }
            if (typeof(TValue) == typeof(uint))
            {
                OperateResult <uint[]> b = xGBCnet.ReadUInt32(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"{b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }
            if (typeof(TValue) == typeof(long))
            {
                OperateResult <long[]> b = xGBCnet.ReadInt64(address, length);

                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"{b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }
            if (typeof(TValue) == typeof(ulong))
            {
                OperateResult <ulong[]> b = xGBCnet.ReadUInt64(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"{b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }

            if (typeof(TValue) == typeof(short))
            {
                OperateResult <short[]> b = xGBCnet.ReadInt16(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"{b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }
            if (typeof(TValue) == typeof(double))
            {
                OperateResult <double[]> b = xGBCnet.ReadDouble(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"{b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }
            if (typeof(TValue) == typeof(float))
            {
                OperateResult <float[]> b = xGBCnet.ReadFloat(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"{b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }
            if (typeof(TValue) == typeof(string))
            {
                OperateResult <string> b = xGBCnet.ReadString(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"{b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }


            throw new InvalidOperationException(string.Format("type '{0}' not supported.", typeof(TValue)));
        }