public override bool SendData(object data) { try { //端口是否打开 if (!_operator.IsPortOpen) { Open(); } //写入数据 try { //尝试写入string型数据 _operator.Write((string)data); } catch (Exception exp) { try { //尝试写入byte[]型数据 _operator.Write((byte[])data); } catch (Exception exp1) { throw new Exception($"{exp.Message}\r\b{exp1.Message}"); } } } catch (Exception exp) { throw exp; } return(true); }
public override bool SendData(object data) { Open(); if (data.GetType() == typeof(string) || data.GetType() == typeof(byte[])) { try { _operator.Write((string)data); } catch (Exception exp) { try { _operator.Write((byte[])data); } catch (Exception exp1) { throw new Exception($"{exp.Message}\r\n{exp1.Message}"); } } } return(true); }