精簡版CE串列埠類庫

2021-06-05 10:32:54 字數 2898 閱讀 6314

#ifndef serial_port_h

#define serial_port_h

#include // mfc 核心元件和標準元件

/// /// 描述:evc串列埠類庫

/// 日期:2012/3/30

///

class cserialport : public cobject

virtual ~cserialport()

/// 最大輸入緩衝大小

static const uint32 s_maxinqueue = 4096;

/// 最大輸出緩衝大小

static const uint32 s_maxoutqueue = 4096;

/// 獲取系統錯誤訊息

/// 輸出的錯誤訊息

static void getlasterror(cstring& pserrormessage) }

/// 獲取串列埠裝置控制塊

/// 輸出的串列埠裝置控制塊

bool getcommstate(lpdcb lpdcb)

/// 設定串列埠裝置控制塊

/// 輸入的串列埠裝置控制塊

bool setcommstate(lpdcb lpdcb)

/// 開啟串列埠裝置

/// 埠號

/// 波特率

/// 奇偶校驗

/// 資料位

/// 停止位

/// cserialport::open(1, 9600, 0, 8, 0)

/// 是否開啟成功

virtual bool open(dword dwport, dword dwbaudrate = cbr_9600, byte byparity = noparity,

byte bybytesize = 8, byte bystopbits = onestopbit)

/// 開啟串列埠裝置

/// 埠名稱

/// 波特率

/// 奇偶校驗

/// 資料位

/// 停止位

/// cserialport::open(1, 9600, 0, 8, 0)

/// 是否開啟成功

virtual bool open(lpctstr pszport, dword dwbaudrate = cbr_9600, byte byparity = noparity,

byte bybytesize = 8, byte bystopbits = onestopbit)

/// 關閉串列埠裝置

/// 是否關閉成功

virtual void close(dword dwtimeout = 5000)

closehandle(m_hwatchthread);

m_hwatchthread = null;

closehandle(m_hserialport);

m_hserialport = invalid_handle_value;

} }

/// 獲取串列埠裝置狀態

/// 是否已開啟

bool isopen()

/// 將指定數量的資料寫入串列埠

/// 輸入緩衝區指標

/// 輸入緩衝區位置

/// 輸入緩衝區大小

/// 是否寫入成功

bool write(const byte* pbybuffer, dword dwoffset = 0, dword dwcount = 1)

/// 將指定數量的字元寫入串列埠

/// 輸入緩衝區指標

/// 輸入緩衝區位置

/// 輸入緩衝區大小

/// 是否寫入成功

bool write(lpctstr pszbuffer, dword dwoffset = 0, dword dwcount = 1)

/// 從串列埠讀取指定數量的資料

/// 輸出緩衝區指標

/// 輸出緩衝區位置

/// 輸出緩衝區大小

/// 是否讀取成功

bool read(lpbyte pbybuffer, dword dwoffset = 0, dword dwcount = 1)

/// 從串列埠讀取指定數量的字元

/// 輸出緩衝區指標

/// 輸出緩衝區位置

/// 輸出緩衝區大小

/// 是否讀取成功

bool read(lptstr pszbuffer, dword dwoffset = 0, dword dwcount = 1)

/// 監視串列埠資料收發執行緒處理函式

/// 執行緒退出**

static dword winapi watchthreadproc(lpvoid lpparam)

/// 監視串列埠資料收發執行緒處理函式

/// 執行緒退出**

virtual dword watchthreadproc()}}

}} return 0; // 執行緒正常退出

} /// 串列埠接收事件處理函式

/// 接收到的資料大小

virtual void datareceived(int nbytessize)

private:

/// 串列埠裝置控制代碼

handle m_hserialport;

/// 串列埠超時引數

commtimeouts m_tcommtimeouts;

/// 串列埠裝置控制塊

dcb m_tdevicecontrolblock;

/// 收發執行緒控制代碼

handle m_hwatchthread;

/// 收發執行緒是否活動

bool m_bwatchthreadlived;

};#endif // serial_port_h

verilog簡單實現串列埠(精簡版)

uart 2017.10.9 傳送接收到的資料 波特率9600 8個資料位 乙個停止位 無奇偶校驗 module uart clk,50mhz rst n,reset rx,input tx ouptut input clk,rst n input rx output reg tx 檢測是否有資料來...

AsyncTask原理精簡版

asynctask有三個主要的方法 onpreexecute doinbackground string.params onpostexecute 建立asynctask物件需要重寫乙個類繼承asynctask,因為asynctask本身是抽象類 new asynctask execute para...

Sql優化精簡版

1.select語句中避免使用 盡量應該根據業務需求按欄位進行查詢 2.刪除重覆記錄 delete from tble tb where tb.id select min id from tble ble where tb.name ble.name 3.用 替換 4.盡量多使用commit 如對大...