Click here to Skip to main content
15,902,893 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How To Connect Serial Port in MFC? Pin
MrFloyd200928-Apr-08 11:00
MrFloyd200928-Apr-08 11:00 
GeneralRe: How To Connect Serial Port in MFC? Pin
David Crow28-Apr-08 11:06
David Crow28-Apr-08 11:06 
GeneralRe: How To Connect Serial Port in MFC? Pin
MrFloyd200928-Apr-08 11:40
MrFloyd200928-Apr-08 11:40 
GeneralRe: How To Connect Serial Port in MFC? Pin
Randor 28-Apr-08 12:42
professional Randor 28-Apr-08 12:42 
GeneralRe: How To Connect Serial Port in MFC? Pin
CPallini28-Apr-08 21:13
mveCPallini28-Apr-08 21:13 
GeneralRe: How To Connect Serial Port in MFC? Pin
MrFloyd200928-Apr-08 23:11
MrFloyd200928-Apr-08 23:11 
QuestionRe: How To Connect Serial Port in MFC? Pin
CPallini28-Apr-08 23:45
mveCPallini28-Apr-08 23:45 
GeneralRe: How To Connect Serial Port in MFC? Pin
MrFloyd200929-Apr-08 0:11
MrFloyd200929-Apr-08 0:11 
My method is this:
/************************************************************************************************/
void CDlgComPortConnectTest::OpenPort()
{
//if (serial_handle!=INVALID_HANDLE_VALUE)
// CloseHandle(serial_handle);
//serial_handle = INVALID_HANDLE_VALUE;

serial_handle = CreateFile( m_sCOM /*"COM1"*/,
GENERIC_READ | GENERIC_WRITE,
0, /* comm devices must be opened w/exclusive-access */
NULL, /* no security attrs */
OPEN_EXISTING, /* comm devices must use OPEN_EXISTING */
NULL, /* not overlapped I/O */
NULL /* hTemplate must be NULL for comm devices */ );

if (GetCommState(serial_handle,&dcb) == 0)
{
char sMsg[512];
DWORD dwError = GetLastError();
sprintf(sMsg, "Error=%d ",dwError);
AfxMessageBox(sMsg);
AfxMessageBox(GetLastError());
AfxMessageBox("Get configuration port has problem.");
return;
}

FillMemory(&dcb, sizeof(dcb), 0);
dcb.DCBlength = sizeof(dcb);

dcb.BaudRate=(unsigned long)atol(m_sBaudRate);//(unsigned long)(9600);
if ( m_sParity.Compare("None") == 0 )
dcb.Parity = NOPARITY;
else
if ( m_sParity.Compare("Even") == 0 )
dcb.Parity = EVENPARITY;
else
if ( m_sParity.Compare("Odd") == 0 )
dcb.Parity = ODDPARITY;
else
dcb.Parity = NOPARITY;

if ( m_sStopBits.Compare("1") == 0 )
dcb.StopBits = ONESTOPBIT;
else
if ( m_sStopBits.Compare("1.5") == 0 )
dcb.StopBits = ONE5STOPBITS;
else
if ( m_sStopBits.Compare("2") == 0 )
dcb.StopBits = TWOSTOPBITS;
else
dcb.StopBits = ONESTOPBIT;

if ( m_sDataBits.Compare("7") == 0 )
dcb.ByteSize = 7;
else
if( m_sDataBits.Compare("8") == 0 )
dcb.ByteSize = 8;
else
dcb.ByteSize = 8;

dcb.fAbortOnError = TRUE;

if (serial_handle == INVALID_HANDLE_VALUE)
{
CString sDC;
sDC.Format("B_commopen = FALSE;\n%d, %d, %d, %d", dcb.XonChar, dcb.XoffChar, dcb.XonLim, dcb.XoffLim);
AfxMessageBox(sDC);
B_commopen = FALSE;
char sMsg[512];
DWORD dwError = GetLastError();
sprintf(sMsg, "Error=%d ",
dwError);
AfxMessageBox(sMsg);
ASSERT(FALSE);
// error opening port; abort
}
else
{
B_PortReady = SetupComm(serial_handle, 128, 128); // set buffer sizes
B_commopen = TRUE;
}

Read(m_sResults);
}
GeneralRe: How To Connect Serial Port in MFC? Pin
CPallini29-Apr-08 0:23
mveCPallini29-Apr-08 0:23 
GeneralRe: How To Connect Serial Port in MFC? Pin
MrFloyd200929-Apr-08 0:48
MrFloyd200929-Apr-08 0:48 
QuestionRe: How To Connect Serial Port in MFC? Pin
CPallini29-Apr-08 0:54
mveCPallini29-Apr-08 0:54 
GeneralRe: How To Connect Serial Port in MFC? Pin
MrFloyd200929-Apr-08 1:24
MrFloyd200929-Apr-08 1:24 
GeneralRe: How To Connect Serial Port in MFC? Pin
CPallini29-Apr-08 1:33
mveCPallini29-Apr-08 1:33 
GeneralRe: How To Connect Serial Port in MFC? Pin
MrFloyd200929-Apr-08 1:56
MrFloyd200929-Apr-08 1:56 
GeneralRe: How To Connect Serial Port in MFC? Pin
CPallini29-Apr-08 1:58
mveCPallini29-Apr-08 1:58 
AnswerRe: How To Connect Serial Port in MFC? Pin
Hamid_RT29-Apr-08 4:09
Hamid_RT29-Apr-08 4:09 
GeneralRetrieve Win32 Process Memory Map Pin
edfgreen28-Apr-08 8:19
edfgreen28-Apr-08 8:19 
GeneralRe: Retrieve Win32 Process Memory Map Pin
Saurabh.Garg28-Apr-08 14:58
Saurabh.Garg28-Apr-08 14:58 
GeneralRe: Retrieve Win32 Process Memory Map Pin
Stephen Hewitt28-Apr-08 15:18
Stephen Hewitt28-Apr-08 15:18 
GeneralRe: Retrieve Win32 Process Memory Map Pin
edfgreen28-Apr-08 19:11
edfgreen28-Apr-08 19:11 
QuestionC++ image compression LZW algorithm??? Pin
dev_buzz28-Apr-08 6:59
dev_buzz28-Apr-08 6:59 
GeneralRe: C++ image compression LZW algorithm??? Pin
David Crow28-Apr-08 7:01
David Crow28-Apr-08 7:01 
GeneralRe: C++ image compression LZW algorithm??? Pin
Maximilien28-Apr-08 9:02
Maximilien28-Apr-08 9:02 
GeneralRe: C++ image compression LZW algorithm??? Pin
Hamid_RT29-Apr-08 1:59
Hamid_RT29-Apr-08 1:59 
Questionunexpected behaviour of 'atof' and 'strtod' Pin
Member 361100228-Apr-08 6:03
Member 361100228-Apr-08 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.