BOOL CSportDlg::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD style=WS_VISIBLE|WS_CHILD;
if (!m_ComPort.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM))
{
TRACE0("Failed to create OLE Communications Contorl\n");
return -1 ;
} int m_baund=2;
int m_comn=0;
int m_databit=3;
int m_jiaoyan=0;
int m_stopbit=0; m_ComPort.SetCommPort(1);
m_ComPort.SetInBufferSize(1024);
m_ComPort.SetOutBufferSize(1024);
m_ComPort.SetInputLen(0);
m_ComPort.SetInputMode(1);}
void CSportDlg::Onconfig()
{
// TODO: Add your control notification handler code here
CSconfig con; con.m_baund=2;
con.m_comn=0;
con.m_databit=3;
con.m_jiaoyan=0;
con.m_stopbit=0; if(con.DoModal()==IDOK)
{
m_ComPort.SetPortOpen(FALSE);
m_ComPort.SetCommPort(1024);
m_ComPort.SetInBufferSize(1024);
m_ComPort.SetOutBufferSize(1024);
m_ComPort.SetInputLen(0);
m_ComPort.SetInputMode(1);
m_ComPort.SetRThreshold(1); CString conf; switch(con.m_baund)
{
case0: conf="2400"; break;
case1: conf="4800"; break;
case2: conf="9600"; break;
default: conf="9600"; break;
} switch (con.m_jiaoyan)
{
case3: conf="无"; break;
case4: conf="寄"; break;
case5: conf="偶"; break;
default: conf="无"; break;
} switch (con.m_databit)
{
case6: conf="5"; break;
case7: conf="6"; break;
case8: conf="7"; break;
case9: conf="8"; break;
default: conf="8"; break;
}
switch (con.m_stopbit)
{
case10: conf="1"; break;
case11: conf="1.5"; break;
case12: conf="2"; break;
case13: conf="1"; break;
default: conf="8"; break;
}
m_ComPort.SetSettings(conf);
m_ComPort.GetPortOpen();
m_ComPort.SetPortOpen(TRUE); }} 编译成功,但运行的时候提示端口设备不能打开(The device is not open),
请问是什么原因,该怎样设置,
{
CDialog::OnInitDialog();
DWORD style=WS_VISIBLE|WS_CHILD;
if (!m_ComPort.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM))
{
TRACE0("Failed to create OLE Communications Contorl\n");
return -1 ;
} int m_baund=2;
int m_comn=0;
int m_databit=3;
int m_jiaoyan=0;
int m_stopbit=0; m_ComPort.SetCommPort(1);
m_ComPort.SetInBufferSize(1024);
m_ComPort.SetOutBufferSize(1024);
m_ComPort.SetInputLen(0);
m_ComPort.SetInputMode(1);}
void CSportDlg::Onconfig()
{
// TODO: Add your control notification handler code here
CSconfig con; con.m_baund=2;
con.m_comn=0;
con.m_databit=3;
con.m_jiaoyan=0;
con.m_stopbit=0; if(con.DoModal()==IDOK)
{
m_ComPort.SetPortOpen(FALSE);
m_ComPort.SetCommPort(1024);
m_ComPort.SetInBufferSize(1024);
m_ComPort.SetOutBufferSize(1024);
m_ComPort.SetInputLen(0);
m_ComPort.SetInputMode(1);
m_ComPort.SetRThreshold(1); CString conf; switch(con.m_baund)
{
case0: conf="2400"; break;
case1: conf="4800"; break;
case2: conf="9600"; break;
default: conf="9600"; break;
} switch (con.m_jiaoyan)
{
case3: conf="无"; break;
case4: conf="寄"; break;
case5: conf="偶"; break;
default: conf="无"; break;
} switch (con.m_databit)
{
case6: conf="5"; break;
case7: conf="6"; break;
case8: conf="7"; break;
case9: conf="8"; break;
default: conf="8"; break;
}
switch (con.m_stopbit)
{
case10: conf="1"; break;
case11: conf="1.5"; break;
case12: conf="2"; break;
case13: conf="1"; break;
default: conf="8"; break;
}
m_ComPort.SetSettings(conf);
m_ComPort.GetPortOpen();
m_ComPort.SetPortOpen(TRUE); }} 编译成功,但运行的时候提示端口设备不能打开(The device is not open),
请问是什么原因,该怎样设置,
if(!m_ComPort.GetPortOpen())
{
m_ComPort.SetPortOpen(TRUE);
m_ComPort.SetRThreshold(1); //为1表示有一个字符引发一个事件
m_ComPort.SetInputLen(0);
m_ComPort.GetInput();
}
DWORD style=WS_VISIBLE|WS_CHILD;
if (!m_ComPort.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM))
{
TRACE0("Failed to create OLE Communications Contorl\n");
return -1 ;
}
这个函数的作用是打开MSCOMM控件吗?
http://www.vckbase.com/document/viewdoc/?id=248
m_ComPort.SetInBufferSize(1024);
m_ComPort.SetOutBufferSize(1024);
m_ComPort.SetInputLen(0);
m_ComPort.SetInputMode(1);
m_ComPort.SetPortOpen(TRUE); //打开端口
LINK : fatal error LNK1168: cannot open Debug/sport.exe for writing
Error executing link.exe.sport.exe - 1 error(s), 0 warning(s)
有出现这个了
是不是还要编接收程序
ON_EVENT(CMainFrame,IDC_MSCOMM,1,OnCommMscomm,VTS_NOSE)
DECLARE_EVENTSINK_MAP请问还需不需要这个函数