|
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
|
|
|
|
|
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
|
|
|
|
|
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 of ulLengthReceived ?
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
|
|
|
|
|
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
|
|
|
|
|
Even after modification also, iam not able to collect the data
The serial port timeouts are
GetCommTimeouts(m_comPortHandle, &sCommTimeOuts);
sCommTimeOuts.ReadIntervalTimeout = 5;
sCommTimeOuts.ReadTotalTimeoutMultiplier = 1;
sCommTimeOuts.ReadTotalTimeoutConstant = 1;
sCommTimeOuts.WriteTotalTimeoutMultiplier = 1;
sCommTimeOuts.WriteTotalTimeoutConstant = 1;
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
|
|
|
|
|
|
even if i change the values of commtimeouts to
GetCommTimeouts(m_comPortHandle, &sCommTimeOuts);
sCommTimeOuts.ReadIntervalTimeout = 100;
sCommTimeOuts.ReadTotalTimeoutMultiplier = 10;
sCommTimeOuts.ReadTotalTimeoutConstant = 500;
sCommTimeOuts.WriteTotalTimeoutMultiplier = 10;
sCommTimeOuts.WriteTotalTimeoutConstant = 100;
SetCommTimeouts(m_comPortHandle, &sCommTimeOuts);
i dint observe any change.
|
|
|
|
|
how can i multiply two numbers without using * operator, rather by doing bits manopulation??? plz help me out!
|
|
|
|
|
multiply/divide by how many ?
there's a hack if you multiply/divide integers by 2.
shifting the bits to one position left will multiply by 2.
shifting the bits to one position right will divide by 2.
however, if you're handling floats, this is a useless pain buddy.
modified on Monday, June 9, 2008 7:31 AM
|
|
|
|
|
Google "Bit shifting" and how base-2 number systems (uh, dat be called binary ) sometime...
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
If you are trying to multiply integers you can use addition in a loop, but without knowing more about what you want to acheive I do not think anyone here can really help.
Try to explaion why you need to do this and what you are trying to acheive.
Good Luck,
Ali
|
|
|
|
|
Hint: operators + and <<
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
|
|
|
|
|
I thought building ALUs in circuits class was really fun
|
|
|
|
|
do we get a share of your grade ?
|
|
|
|
|
Try something like this, it's just the same as you do it on paper:
#include "stdafx.h"
#include <iostream>
using namespace std;
unsigned int Multiply(unsigned int l, unsigned int r)
{
unsigned res = 0;
while (l!=0 && r!=0)
{
if (r&1)
{
res += l;
}
l <<= 1;
r >>= 1;
}
return res;
}
int main()
{
cout << "1234 * 2:" << endl;
cout << "\t* = " << 1234*2 << endl;
cout << "\tMultiply = " << Multiply(1234, 2) << endl << endl;
cout << "314159 * 33:" << endl;
cout << "\t* = " << 314159*33 << endl;
cout << "\tMultiply = " << Multiply(314159, 33) << endl << endl;
return 0;
}
Steve
|
|
|
|
|
i have added the following code to create status bar in a dialog.
But its not getting created.
what could be the problem
....
m_StatusBar.Create(this);
m_StatusBar.SetIndicators(indicators, sizeof(indicators)/ sizeof(UINT));
....
|
|
|
|
|
Check this article[^].
BTW, I searched for "dialog status bar" on the codeproject search and that was the first result
|
|
|
|
|
Yes. its good sample.
Meanwhile i am getting the following error.
error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [10]' to 'const wchar_t *'
How to resove this.
|
|
|
|
|
It is because UNICODE is defined for your project. I suggest this excellent article[^] if you want to understand what is happening. If you don't care, just disable UNICODE in your project settings (but you'll miss a chance to learn something usefull).
|
|
|
|
|
Thanks.i gone thru the article.
Look below decl. of unicode.
wchar_t wch = L'1'; // 2 bytes, 0x0031
wchar_t* wsz = L"Hello"; // 12 bytes, 6 wide characters
First stmt one char -> 2Byte.
Second stme five char -> 12 byte. How?
|
|
|
|