using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.io.ports;
namespace communicationcomm
#region 傳送接收資料 public void sendmsg(string senstr)
///
/// 傳送接收資料
///
/// 傳送資料的內容
public void sendmsg(string senstr)
///
/// 資料讀取
///
///
/// 串列埠資料緩衝
/// 串列埠資料緩衝空間大小
/// 設定串列埠讀放棄時間
/// 位元組間隔最大時間
/// 串列埠實際讀入資料個數
public int readcomm(out byte readbuf, int bufroom, int howtime, int bytetime)
else if (nreadlen == 0)
nbytelen = 1;
}catch (exception ex)
return nbytelen;
}#endregion
#region public int readblock(out byte readbuf, int readroom, int bytetime) 串列埠同步讀(阻塞方式讀串列埠,直到串列埠緩衝區中沒有資料,靠字元間間隔超時確定沒有資料)
///
/// 串列埠同步讀(阻塞方式讀串列埠,直到串列埠緩衝區中沒有資料,靠字元間間隔超時確定沒有資料)
///
/// 串列埠資料緩衝
/// 串列埠資料緩衝空間大小
/// 位元組間隔最大時間
/// 從串列埠實際讀入的位元組個數
public int readblock(out byte readbuf, int readroom, int bytetime)
catch (exception ex)
}readbuf[nbytelen] = 0x00;
return nbytelen;
}#endregion
#region public static string bytetostring(byte inbytes) 字元陣列轉字串16進製制
///
/// 字元陣列轉字串16進製制
///
/// 二進位制位元組
/// 類似"01 02 0f"
public static string bytetostring(byte inbytes)
", inbyte) + " ";
}return stringout.trim();
}#endregion
#region public static byte stringtobyte(string instring) strhex 轉位元組陣列
///
/// strhex 轉位元組陣列
///
/// 類似"01 02 0f" 用空格分開的
///
public static byte stringtobyte(string instring)
return byteout;
}#endregion
#region ublic static byte stringtobyte_2(string instring) strhex 轉位元組陣列
///
/// strhex 轉位元組陣列
///
/// 類似"01 02 0f" 中間無空格
///
public static byte stringtobyte_2(string instring)
byteout = new byte[bytestrings.length];
for (int i = 0; i <= bytestrings.length - 1; i++)
}catch (exception ex)
return byteout;
}#endregion
#region public static string str_to_0x(string instring) 字串 轉16進製制字串
///
/// 字串 轉16進製制字串
///
/// unico
/// 類似「01 0f」
public static string str_to_0x(string instring)
#endregion}}
串列埠操作類
public int handle public commport string comstr 設定dcb標誌位 internal void setdcbflag int whichflag,int setting,dcb dcb else if whichflag 15 else dcb.flag...
C 串列埠操作類
最近由於工作需要,在研究串列埠通訊的問題,下面分享一下關於串列埠的乙個操作類,有不足之處,希望大家一起提出改善。using system using system.collections.generic using system.text using system.io.ports public c...
C 串列埠操作實用類
做工業通訊有很長時間了,特別是串列埠 232 485 有vb vc c各種版本的串列埠操作 這些 也經過了多年的現場考驗,應該說是比較健壯的 但是目前卻沒有c 相對成熟的串列埠操作 最近用moxa的裝置開發基於wince5.0的串列埠操作 所以就擴充完善了一下串列埠操作,特別是sendcommand...