/// <summary> /// /// </summary> /// <param name="bytes"></param> /// <returns></returns> public override object ConvertToObject(byte[] bytes) { int[] values = new int[POINT_COUNT]; for (int i = 0; i < POINT_COUNT; i++) { byte[] temp = new byte[] { bytes[i * 2], bytes[i * 2 + 1] }; Int16 n = Int16ModbusConverter.BytesToInt16(temp); // 读时缩小10倍 // n = Convert.ToInt16(n / 10); values[i] = n; } return(values); }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public override byte[] ConvertToBytes(object obj) { //return base.ConvertToBytes(obj); MemoryStream ms = new MemoryStream(); int[] values = obj as int[]; for (int i = 0; i < POINT_COUNT; i++) { int n = values[i]; // 写入时候放大10倍 // n = n * 10; byte[] bs = Int16ModbusConverter.Int16ToBytes((Int16)n); ms.Write(bs, 0, bs.Length); } return(ms.ToArray()); }