這個程序非常好,使用微軟的Mscomm1控件進行串口通信。
但是這個程序沒有串口助手里16進制顯示功能,通過修改源碼MSCommProDlg.cpp 241左右:
wsprintf(pCommStr, _T("%.2X"), str[0]&0xff); m_strReceive=m_strReceive+pCommStr+_T(" ");//添加回車換行 m_lineNum++; if (m_lineNum > 6) { m_strReceive += _T("\r\n"); m_lineNum = 0; }
其中,在這個函數開始處定義:wchar_t* pCommStr = new wchar_t[200];
并且在MSCommProDlg.h中定義類屬性:
int m_lineNum;
在類的構造函數中進行初始化:
CMSCommProDlg::CMSCommProDlg(CWnd* pParent /*=NULL*/) : CDialog(CMSCommProDlg::IDD, pParent) , m_strReceive(_T("")) , m_strSend(_T("")) , m_time(0) , m_lineNum(0) {
......
謝謝! |