Regarding System Error Code 995 in Serial Communication
-
hi one and all, iam having a problem with accessing serial port in my pc. i have developed an application which access the serial port in VC++ 6.0.After configuring the Serial port to 115200, iam able to send the data to the com port using WriteFile().But, iam unable to receive the data from the com port through ReadFile() operation and i have checked the error by using GetLastError() and it is given as 995(system error code).Even though i have restarted my system several times,iam unable to debug. Please help me why this error is getting and how to fix this error? Thanks in advance Regards, Praveen
modified on Monday, June 9, 2008 8:23 AM
Cross post: http://www.codeproject.com/script/Forums/View.aspx?fid=1648&msg=2588888[^], please don't do it. BTW why didn't you post the relevant code, as I suggested? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Cross post: http://www.codeproject.com/script/Forums/View.aspx?fid=1648&msg=2588888[^], please don't do it. BTW why didn't you post the relevant code, as I suggested? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeIam calling this function for capturing data. The ReadFile() returns 0 value and GetLastError() gives error 995 bool CSerialPort::bReceiveBytes( unsigned char* x_pcBuffer, unsigned short x_usLengthExpected, unsigned short *x_pusLengthReceived ) { bool bResult = FALSE; unsigned long ulLengthReceived=0; int iResult; iResult = ReadFile( m_comPortHandle, x_pcBuffer[0], x_usLengthExpected, &ulLengthReceived, NULL ); DWORD err1 = GetLastError(); *x_pusLengthReceived = (unsigned short)ulLengthReceived; return( bResult ); }
-
Iam calling this function for capturing data. The ReadFile() returns 0 value and GetLastError() gives error 995 bool CSerialPort::bReceiveBytes( unsigned char* x_pcBuffer, unsigned short x_usLengthExpected, unsigned short *x_pusLengthReceived ) { bool bResult = FALSE; unsigned long ulLengthReceived=0; int iResult; iResult = ReadFile( m_comPortHandle, x_pcBuffer[0], x_usLengthExpected, &ulLengthReceived, NULL ); DWORD err1 = GetLastError(); *x_pusLengthReceived = (unsigned short)ulLengthReceived; return( bResult ); }
pra84veen wrote:
x_pcBuffer[0]
The above is wrong: you should use
x_pcBuffer
instead. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
pra84veen wrote:
x_pcBuffer[0]
The above is wrong: you should use
x_pcBuffer
instead. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
hello, thanks for your reply... even though if i replace x_pcBuffer instead of x_pcBuffer[0], i dint get any data into the buffer. but here the return values for ReadFile is 1 but iam unable to capture the data.. Thanks & Regards, praveen
When return value is 1,
ReadFile
succeeded. What is the value ofulLengthReceived
? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
When return value is 1,
ReadFile
succeeded. What is the value ofulLengthReceived
? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarkethe value received by the ulLengthReceived is 0.
void CER2TSerialDlg::OnStartThread()
{
CWinThread *pThread = NULL;
m_SerialCommn->bOpen()
pThread = AfxBeginThread((AFX_THREADPROC)ReadFromModuleThread,NULL);
}UINT CER2TSerialDlg::ReadFromModuleThread(LPVOID pPARAM)
{
unsigned char ucLengthExpected=10;
char chBuffer[FIFO_SIZE]={0};
unsigned short usReceived=0;while(TRUE)
{
m_SerialCommn->bReceiveBytes(chBuffer,ucLengthExpected,&usReceived);
}
return 0;
}bool CSerialPort::bReceiveBytes(char* x_pcBuffer,
unsigned short x_usLengthExpected,
unsigned short *x_pusLengthReceived )
{unsigned long ulLengthReceived=0;
int iResult;
iResult = ReadFile(m_comPortHandle,
x_pcBuffer[0],
x_usLengthExpected,
ulLengthReceived,
NULL );
DWORD err1 = GetLastError();
*x_pusLengthReceived = (unsigned short)ulLengthReceived;
return( iResult );}/
Regards praveen
modified on Wednesday, June 11, 2008 1:48 AM
-
the value received by the ulLengthReceived is 0.
void CER2TSerialDlg::OnStartThread()
{
CWinThread *pThread = NULL;
m_SerialCommn->bOpen()
pThread = AfxBeginThread((AFX_THREADPROC)ReadFromModuleThread,NULL);
}UINT CER2TSerialDlg::ReadFromModuleThread(LPVOID pPARAM)
{
unsigned char ucLengthExpected=10;
char chBuffer[FIFO_SIZE]={0};
unsigned short usReceived=0;while(TRUE)
{
m_SerialCommn->bReceiveBytes(chBuffer,ucLengthExpected,&usReceived);
}
return 0;
}bool CSerialPort::bReceiveBytes(char* x_pcBuffer,
unsigned short x_usLengthExpected,
unsigned short *x_pusLengthReceived )
{unsigned long ulLengthReceived=0;
int iResult;
iResult = ReadFile(m_comPortHandle,
x_pcBuffer[0],
x_usLengthExpected,
ulLengthReceived,
NULL );
DWORD err1 = GetLastError();
*x_pusLengthReceived = (unsigned short)ulLengthReceived;
return( iResult );}/
Regards praveen
modified on Wednesday, June 11, 2008 1:48 AM
pra84veen wrote:
iResult = ReadFile(m_comPortHandle, x_pcBuffer[0], x_usLengthExpected, ulLengthReceived, NULL );
That's completely wrong (compiler doesn't complain, does it?). Should be:
ReadFile(m_comPortHandle,
x_pcBuffer,
x_usLengthExpected,
&ulLengthReceived,
NULL );Please note the ampersand in front of
ulLengthReceived
. BTW: How did you set serial port timeouts? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
pra84veen wrote:
iResult = ReadFile(m_comPortHandle, x_pcBuffer[0], x_usLengthExpected, ulLengthReceived, NULL );
That's completely wrong (compiler doesn't complain, does it?). Should be:
ReadFile(m_comPortHandle,
x_pcBuffer,
x_usLengthExpected,
&ulLengthReceived,
NULL );Please note the ampersand in front of
ulLengthReceived
. BTW: How did you set serial port timeouts? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeEven after modification also, iam not able to collect the data The serial port timeouts are
GetCommTimeouts(m_comPortHandle, &sCommTimeOuts);
sCommTimeOuts.ReadIntervalTimeout = 5;//100; //[ms]
sCommTimeOuts.ReadTotalTimeoutMultiplier = 1;//10; //[ms]
sCommTimeOuts.ReadTotalTimeoutConstant = 1;//500; //[ms]
sCommTimeOuts.WriteTotalTimeoutMultiplier = 1;//10; //[ms]
sCommTimeOuts.WriteTotalTimeoutConstant = 1;//100; //[ms]
SetCommTimeouts(m_comPortHandle, &sCommTimeOuts);Thanks & Regards, Praveen
-
Even after modification also, iam not able to collect the data The serial port timeouts are
GetCommTimeouts(m_comPortHandle, &sCommTimeOuts);
sCommTimeOuts.ReadIntervalTimeout = 5;//100; //[ms]
sCommTimeOuts.ReadTotalTimeoutMultiplier = 1;//10; //[ms]
sCommTimeOuts.ReadTotalTimeoutConstant = 1;//500; //[ms]
sCommTimeOuts.WriteTotalTimeoutMultiplier = 1;//10; //[ms]
sCommTimeOuts.WriteTotalTimeoutConstant = 1;//100; //[ms]
SetCommTimeouts(m_comPortHandle, &sCommTimeOuts);Thanks & Regards, Praveen
Why don't you widen them (you can also set them for a blocking call, just to make a test)? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Why don't you widen them (you can also set them for a blocking call, just to make a test)? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
even if i change the values of commtimeouts to
GetCommTimeouts(m_comPortHandle, &sCommTimeOuts);
sCommTimeOuts.ReadIntervalTimeout = 100; //[ms]
sCommTimeOuts.ReadTotalTimeoutMultiplier = 10; //[ms]
sCommTimeOuts.ReadTotalTimeoutConstant = 500; //[ms]
sCommTimeOuts.WriteTotalTimeoutMultiplier = 10; //[ms]
sCommTimeOuts.WriteTotalTimeoutConstant = 100; //[ms]
SetCommTimeouts(m_comPortHandle, &sCommTimeOuts);i dint observe any change.