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))); }
private void button_read_string_Click(object sender, EventArgs e) { // 读取字符串 DemoUtils.ReadResultRender(xGBCnet.ReadString(textBox3.Text, ushort.Parse(textBox5.Text)), textBox3.Text, textBox4); }
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))); }