WINCE6串口怎么都打不开的?大虾们指教指教
我是飞凌OK6410的板子,我就是用数据带扩展连上一个三个COM口的。我程序编写好,可是找不对COM口,
程序如下:
#include "stdafx.h"
#include "com.h"
#include "comDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CcomDlg dialog
CcomDlg::CcomDlg(CWnd* pParent /*=NULL*/)
: CDialog(CcomDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CcomDlg:oDataExchange(CDataExchange* pDX)
{
CDialog:oDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CcomDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CcomDlg::OnBnClickedButton1)
END_MESSAGE_MAP()
// CcomDlg message handlers
BOOL CcomDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CcomDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
if (AfxIsDRAEnabled())
{
DRA::RelayoutDialog(
AfxGetResourceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA:ortrait ?
MAKEINTRESOURCE(IDD_COM_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_COM_DIALOG));
}
}
#endif
void CcomDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
HANDLE hCom;
hCom=CreateFile(_T("COM3"), GENERIC_READ|GENERIC_WRITE, 0,NULL , OPEN_EXISTING, 0, NULL);
if(hCom==INVALID_HANDLE_VALUE)//
{
AfxMessageBox(_T("打开COM2失败"));
}
else
{
AfxMessageBox(_T("ok"));
DCB wdcb;
COMMTIMEOUTS CommTimeOuts,meOuts;
SetupComm(hCom,1024,1024);
PurgeComm(hCom,PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);
meOuts.ReadIntervalTimeout=0xFFFFFFFF;
CommTimeOuts.ReadTotalTimeoutMultiplier=0;
CommTimeOuts.ReadTotalTimeoutConstant=1000;
CommTimeOuts.WriteTotalTimeoutConstant=0;
//给定窜口读与操作限时
SetCommTimeouts(hCom,&CommTimeOuts);
wdcb.DCBlength=sizeof(DCB);
GetCommState(hCom,&wdcb);
wdcb.BaudRate=9600;//波特率:9600,其他:不变
BOOL fPrtVal=SetCommState(hCom,&wdcb);
if(!fPrtVal)
{
}
PurgeComm(hCom, PURGE_TXCLEAR);
}
//wchar
//WriteFile(hCom,&buf,m_send.GetLength(),&wCount,NULL);
}
在CE就是提示打开COM失败。怎么解决???
[解决办法]