public static Byte[] ToBytes(PLCControlObj paras) { Debug.Assert(paras != null); Byte[] bytes = new byte[16]; bytes[0] = (Byte)(paras.xDir >> 8); bytes[1] = (Byte)(paras.xDir % 256); bytes[2] = (Byte)(paras.xVal >> 8); bytes[3] = (Byte)(paras.xVal % 256); bytes[4] = (Byte)(paras.yDir >> 8); bytes[5] = (Byte)(paras.yDir % 256); bytes[6] = (Byte)(paras.yVal >> 8); bytes[7] = (Byte)(paras.yVal % 256); bytes[8] = (Byte)(paras.zDir >> 8); bytes[9] = (Byte)(paras.zDir % 256); bytes[10] = (Byte)(paras.zVal >> 8); bytes[11] = (Byte)(paras.zVal % 256); bytes[12] = (Byte)(paras.rDir >> 8); bytes[13] = (Byte)(paras.rDir % 256); bytes[14] = (Byte)(paras.rVal >> 8); bytes[15] = (Byte)(paras.rVal % 256); return(bytes); }
public static string ToByteJson(PLCControlObj paras) { Byte[] bytes = ToBytes(paras); string json1 = JsonConvert.SerializeObject(bytes); return(json1); }
public static PLCControlObj FromByteJson(string json1) { Byte[] bytes = JsonConvert.DeserializeObject <Byte[]>(json1); PLCControlObj paras = FromBytes(bytes); return(paras); }
public static PLCControlObj FromBytes(Byte[] bytes) { PLCControlObj paras = new PLCControlObj(); paras.XDir = (UInt16)((Convert.ToUInt16(bytes[0]) << 8) + Convert.ToUInt16(bytes[1])); paras.XVal = (UInt16)((Convert.ToUInt16(bytes[2]) << 8) + Convert.ToUInt16(bytes[3])); paras.YDir = (UInt16)((Convert.ToUInt16(bytes[4]) << 8) + Convert.ToUInt16(bytes[5])); paras.YVal = (UInt16)((Convert.ToUInt16(bytes[6]) << 8) + Convert.ToUInt16(bytes[7])); paras.ZDir = (UInt16)((Convert.ToUInt16(bytes[8]) << 8) + Convert.ToUInt16(bytes[9])); paras.ZVal = (UInt16)((Convert.ToUInt16(bytes[10]) << 8) + Convert.ToUInt16(bytes[11])); paras.RDir = (UInt16)((Convert.ToUInt16(bytes[12]) << 8) + Convert.ToUInt16(bytes[13])); paras.RVal = (UInt16)((Convert.ToUInt16(bytes[14]) << 8) + Convert.ToUInt16(bytes[15])); return(paras); }