예제 #1
0
 private void button_read_ushort_Click(object sender, EventArgs e)
 {
     // 读取ushort变量
     if (textBox14.Text == "1")
     {
         DemoUtils.ReadResultRender(fastEnet.ReadUInt16(textBox3.Text), textBox3.Text, textBox4);
     }
     else
     {
         DemoUtils.ReadResultRender(fastEnet.ReadUInt16(textBox3.Text, ushort.Parse(textBox14.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 = fastEnet.ReadUInt16(address, length).Content;

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

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

            if (typeof(TValue) == typeof(short))
            {
                var b = fastEnet.ReadInt16(address, length).Content;
                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(double))
            {
                var b = fastEnet.ReadDouble(address, length).Content;
                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(float))
            {
                var b = fastEnet.ReadFloat(address, length).Content;
                return((TValue[])(object)b);
            }
            if (typeof(TValue) == typeof(string))
            {
                var b = fastEnet.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_ushort_Click(object sender, EventArgs e)
 {
     // 读取ushort变量
     DemoUtils.ReadResultRender(fastEnet.ReadUInt16(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);
            }
            else if (typeof(TValue) == typeof(ushort))
            {
                OperateResult <ushort[]> b = fastEnet.ReadUInt16(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"TValue[] Read {b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }
            else if (typeof(TValue) == typeof(int))
            {
                OperateResult <int[]> b = fastEnet.ReadInt32(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"TValue[] Read {b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }
            else if (typeof(TValue) == typeof(uint))
            {
                OperateResult <uint[]> b = fastEnet.ReadUInt32(address, length);
                if (!b.IsSuccess)
                {
                    throw new InvalidOperationException($"TValue[] Read {b.Message}");
                }
                else
                {
                    return((TValue[])(object)b.Content);
                }
            }
            else if (typeof(TValue) == typeof(long))
            {
                OperateResult <long[]> b = fastEnet.ReadInt64(address, length);

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

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

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