public static void write(byte[] message, WriteModel model) { if (message == null || message.Length <= 0) { return; } StringBuilder str = new StringBuilder(); for (int i = 0; i < message.Length; i++) { str.Append(" 0x" + Convert.ToString(message[i], 16)); } if (model.Equals(WriteModel.send)) { //4.0协议 int serial = 0; if (message.Length > 13) { serial = StringUtil.byte2Int(new byte[] { message[10], message[11], message[12], message[13] }); } //开始写入 swS.WriteLine("serial:" + serial + " data:" + str.ToString() + " time:" + DateTime.Now.ToString("yyyyMMddhhmmssfff")); //清空缓冲区 swS.Flush(); } else { //4.0协议 int serial = 0; if (message.Length > 10) { serial = StringUtil.byte2Int(new byte[] { message[7], message[8], message[9], message[10] }); } //开始写入 swR.WriteLine("serial:" + serial + " data:" + str.ToString() + " time:" + DateTime.Now.ToString("yyyyMMddhhmmssfff")); //清空缓冲区 swR.Flush(); } }
public static void write(string message, WriteModel model) { if (message == null || message.Length <= 0) { return; } if (model.Equals(WriteModel.send)) { //开始写入 swS.WriteLine("data:" + message + " time:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff")); //清空缓冲区 swS.Flush(); } else { //开始写入 swR.WriteLine("data:" + message + " time:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff")); //清空缓冲区 swR.Flush(); } }