Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

My app is running and continually polling the sate of the serial port to determine whether the attached device is turned on or not, and when the attached device is turned on then data is retrieved from the device quite happily.

The problem I am having is that, when turning on the device, I occasionally will get an unhandled exception that points to the IsIdleMessage part of CWinThread::Run, and no call stack.

Running a port monitor I am getting between 30 and 70 '0x00' bytes when switching on the device and the app crashes, but otherwise I'm getting no '0x00' bytes when running happily.

I have added a TRY, CATCH_ALL around each of my comport functions. I have critical sections around all the calls to comport functions and usage.
I have overridden the CWinThread::Run fn in my App, and still when it crashes there is no call stack.

Does anyone have any tips, or pointers to possible solutions that might cause the app to crash with no call stack?

I know there is not much to go on, but this is the call stack I am receiving

MyProg.exe!MyProgApp::Run()  Line 373 + 0x11   C++
    MyProg.exe!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00141f18, int nCmdShow=0x00000001)  Line 49 + 0xb  C++
    MyProg.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00141f18, int nCmdShow=0x00000001)  Line 25   C++
    MyProg.exe!WinMainCRTStartup()  Line 251 + 0x30 C
    kernel32.dll!7c817077()
    ntdll.dll!7c915ca7()


Hopefully someone can spot something meaningful in there.

TIA

Tony
Posted
Updated 21-Mar-11 7:14am
v2
Comments
Wendelius 21-Mar-11 13:15pm    
Unchecked the "Ignore HTML in text" option, reapplied pre tags, added some code tags
Sergey Alexandrovich Kryukov 21-Mar-11 14:16pm    
It needs some of your code. Should be something very simple.
--SA
maycockt 22-Mar-11 7:49am    
Hi,

When my Com Port is opened the following is used to open it
<pre>
// If COM is open, close it
if( IsOpen() )
{
CloseCOM();
}

// Convert com port index to string
//_stprintf(buf,ComNames[m_PortNumber]); // build COM port name

// Convert com port index to string
m_hComm = CreateFile(m_PortName, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0 );

// if open ok,
if( m_hComm!=INVALID_HANDLE_VALUE )
{
DCB dcb;

memset( &dcb, 0, sizeof(dcb) );
dcb.DCBlength = sizeof(DCB);

// Get the current state & modify to suit
if( GetCommState( m_hComm, &dcb ) != 0 )
{
dcb.BaudRate = m_dwBaudRate;
dcb.fBinary = TRUE;
dcb.fParity = TRUE;
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fDsrSensitivity = FALSE;
dcb.fOutX = FALSE;
dcb.fNull = FALSE;
dcb.fRtsControl = m_nRtsControl;
dcb.fAbortOnError = FALSE;
dcb.ByteSize = m_bByteSize;
dcb.Parity = m_bParity;
dcb.StopBits = m_bStopBits;
dcb.fBinary = TRUE;
dcb.fNull = FALSE;
dcb.StopBits = m_bStopBits;
dcb.EvtChar = 72;

if( SetCommState( m_hComm, &dcb ) != 0 ) // if OK
{
if( SetCommTimeouts(m_hComm, &m_CommTimeOuts) != 0 )
{
m_fError = FALSE;
}
}

if( (m_fError == FALSE) && (m_fSIRRequired == TRUE) )
{
if( EscapeCommFunction( m_hComm, SETIR ) == 0 )
{
m_fError = TRUE;
}
}
GetCommState( m_hComm, &dcb2 );
}

SwitchDTROff();
SwitchRTSOn();
}
</pre>

In my document I am running a timer that will poll the port every second and queries the device to see if it is still connected
<pre>
void _stdcall PollController(HWND Hwnd,unsigned int a, unsigned int b, DWORD c)
{
static int count = 0xFFFFFFFF;
WORD ec = 0;
CString strTemp;
int ReturnCount;
try
{
//There must be a nicer way of doing this.
CFrameWnd *pMainWnd = (CFrameWnd*)(AfxGetApp()->m_pMainWnd);
if( !pMainWnd ) // if main window not constructed yet, leave.
{ // Required for Win98 which seems to construct/create 1n
// different order from NT & W2K.
return;
}

CCriticalSection c_s;

// Create object for Single Lock
CSingleLock lock(&c_s);

// Lock
lock.Lock();

CView *pView = (CView *)pMainWnd->GetActiveView();

//validate the ProgView ptr
if(NULL != pView)
{
CDocument *pDoc = pView->GetDocument();

//validate the document ptr
if(NULL != pDoc)
{
if( pDoc->IsCommunicating() )
{
ReturnCount = 3;
}
else
{
ReturnCount = 6;
}

// Update the display only every 3 * interval
// But allow 1st update immediately
if( count == 0xFFFFFFFF ) // if first time through
{
count = 0;
}
else
{
count++;
if( count < ReturnCount ) // if not time yet
{
return; // don't do it
}
count = 0; // do it, resetting count
}

g_ComPort.PurgeRX();
g_ComPort.PurgeTX();
pDoc->RefreshDeviceType();

}
}

// Unlock
lock.Unlock();
}
catch(...)
{
TRACE("\nPollController crashed");
}
}
</pre>

This code, just free running, with the device regularly power cycled, will crash as described in the original post, but at differing regularities.

Thanks

Tony

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900