最近由於工作需要,在研究串列埠通訊的問題,下面分享一下關於串列埠的乙個操作類,有不足之處,希望大家一起提出改善。
using system;
using system.collections.generic;
using system.text;
using system.io.ports;
public class serialclass
///
/// 建構函式,可以自定義串列埠的初始化引數
///
/// 需要操作的com口名稱
/// com的速度
/// 奇偶校驗位
/// 資料長度
/// 停止位
public serialclass(string comportname, int baudrate, parity parity, int databits, stopbits stopbits)
///
/// 設定串列埠資源,還需過載多個設定串列埠的函式
///
void setserialport()
}///
/// 開啟串列埠資源
///
public bool openport()
catch (exception ex)
return ok;
}///
/// 關閉串列埠資源,操作完成後,一定要關閉串列埠
///
public void closeport()
///
/// 獲取埠連線狀態
///
///
public bool getisopen()
catch{}
return flag ;
}///
/// 接收串列埠資料事件
///
///
///
void _serialport_datareceived(object sender, serialdatareceivedeventargs e)}}
///
/// 接收資料出錯事件
///
///
///
void _serialport_errorreceived(object sender, serialerrorreceivedeventargs e)
///
/// 串列埠資料傳送
///
///
public void senddata(string data)
}public void senddata(byte data, int offset, int count)
}///
/// 傳送命令
///
///
///
///
///
public int sendcommand(byte senddata, ref byte receivedata, int overtime)
if (_serialport.bytestoread >= receivedata.length)
ret = _serialport.read(receivedata, 0, receivedata.length);
receiveeventflag = false; //開啟事件
return ret;
}return -1;
}///
/// 獲取所有已連線簡訊貓裝置的串列埠
///
///
public string serialsisconnected()
///
/// 獲得當前電腦上的所有串列埠資源
///
///
public string getserials()}}
C 串列埠操作實用類
做工業通訊有很長時間了,特別是串列埠 232 485 有vb vc c各種版本的串列埠操作 這些 也經過了多年的現場考驗,應該說是比較健壯的 但是目前卻沒有c 相對成熟的串列埠操作 最近用moxa的裝置開發基於wince5.0的串列埠操作 所以就擴充完善了一下串列埠操作,特別是sendcommand...
C 串列埠操作實用類
做工業通訊有很長時間了,特別是串列埠 232 485 有vb vc c各種版本的串列埠操作 這些 也經過了多年的現場考驗,應該說是比較健壯的 但是目前卻沒有c 相對成熟的串列埠操作 最近用moxa的裝置開發基於wince5.0的串列埠操作 所以就擴充完善了一下串列埠操作,特別是sendcommand...
C 串列埠操作實用類
做工業通訊有很長時間了,特別是串列埠 232 485 有vb vc c各種版本的串列埠操作 這些 也經過了多年的現場考驗,應該說是比較健壯的 但是目前卻沒有c 相對成熟的串列埠操作 最近用moxa的裝置開發基於wince5.0的串列埠操作 所以就擴充完善了一下串列埠操作,特別是sendcommand...