private void button_read_bool_Click(object sender, EventArgs e) { // 读取byte变量 if (textBox14.Text == "1") { DemoUtils.ReadResultRender(fastEnet.ReadBool(textBox3.Text), textBox3.Text, textBox4); } else { DemoUtils.ReadResultRender(fastEnet.ReadBool(textBox3.Text, ushort.Parse(textBox14.Text)), textBox3.Text, textBox4); } }
public TValue Read <TValue>(string address) { if (typeof(TValue) == typeof(bool)) { OperateResult <bool[]> read = fastEnet.ReadBool(address, 1); if (!read.IsSuccess) { throw new InvalidOperationException($"TValue Read {address} {read.Message}"); } else { return((TValue)(object)read.Content[0]); } } else if (typeof(TValue) == typeof(ushort)) { OperateResult <ushort[]> b = fastEnet.ReadUInt16(address, 1); if (!b.IsSuccess) { throw new InvalidOperationException($"TValue Read {b.Message}"); } else { return((TValue)(object)b.Content[0]); } } else if (typeof(TValue) == typeof(int)) { OperateResult <int[]> b = fastEnet.ReadInt32(address, 1); if (!b.IsSuccess) { throw new InvalidOperationException($"TValue Read {b.Message}"); } else { return((TValue)(object)b.Content[0]); } } else if (typeof(TValue) == typeof(uint)) { OperateResult <uint[]> b = fastEnet.ReadUInt32(address, 1); if (!b.IsSuccess) { throw new InvalidOperationException($"TValue Read {b.Message}"); } else { return((TValue)(object)b.Content[0]); } } else if (typeof(TValue) == typeof(long)) { OperateResult <long[]> b = fastEnet.ReadInt64(address, 1); if (!b.IsSuccess) { throw new InvalidOperationException($"TValue Read {b.Message}"); } else { return((TValue)(object)b.Content[0]); } } else if (typeof(TValue) == typeof(ulong)) { OperateResult <ulong[]> b = fastEnet.ReadUInt64(address, 1); if (!b.IsSuccess) { throw new InvalidOperationException($"TValue Read {b.Message}"); } else { return((TValue)(object)b.Content[0]); } } else if (typeof(TValue) == typeof(short)) { OperateResult <short[]> b = fastEnet.ReadInt16(address, 1); if (!b.IsSuccess) { throw new InvalidOperationException($"TValue Read {b.Message}"); } else { return((TValue)(object)b.Content[0]); } } else if (typeof(TValue) == typeof(double)) { OperateResult <double[]> b = fastEnet.ReadDouble(address, 1); if (!b.IsSuccess) { throw new InvalidOperationException($"TValue Read {b.Message}"); } else { return((TValue)(object)b.Content[0]); } } else if (typeof(TValue) == typeof(float)) { OperateResult <float[]> b = fastEnet.ReadFloat(address, 1); if (!b.IsSuccess) { throw new InvalidOperationException($"TValue Read {b.Message}"); } else { return((TValue)(object)b.Content[0]); } } else if (typeof(TValue) == typeof(string)) { OperateResult <string> b = fastEnet.ReadString(address, 1); if (!b.IsSuccess) { throw new InvalidOperationException($"TValue[] Read {b.Message}"); } else { return((TValue)(object)b.Content[0]); } } throw new InvalidOperationException(string.Format("type '{0}' not supported.", typeof(TValue))); }