|
I am debugging the application dealing with COM port.
The WaitCommEvent() function is called after setting mask with EV_RXCHAR and EV_TXEMPTY.
Even when there is no data coming from outside to COM port, WaitCommEvent() returns with new line character(10) continuously and the CPU usage becomes 100%.
Does anybody know why the new line character is coming?
Any help would be greatly appreciable!!
Best Regards,
Suman
|
|
|
|
|
rp_suman wrote: WaitCommEvent() returns with new line character(10)
WaitCommEvent returns a BOOL. Did you check if it returns TRUE ?
And what do you mean by "returns new line character" ? You read the port just after WaitCommEvent returns ?
Can you post a relevant code snippet ?
|
|
|
|
|
Hi, Sorry, WaitCommEvent() returns "false" and its 2nd parameter set to value RX_CHAR(i.e, 1)
and the ReadFile() function gives the new line character in its 2nd parameter.
Best Regards,
Suman
code snippet is here:
<br />
if(!SetCommMask(serialObj.m_hCom, EV_RXCHAR | EV_TXEMPTY)) <br />
return ERRCODE;<br />
<br />
while(serialObj.m_hCom != NULL)<br />
{<br />
BOOL bRet = WaitCommEvent( serialObj.m_hCom, &dwCommEvt, &serialObj.comReader );<br />
<br />
if ( dwCommEvt & EV_RXCHAR ) {<br />
<br />
do {<br />
retval = ReadFile( serialObj.m_hCom, &lpBuff, 1, &dwRead, &serialObj.comReader );<br />
<br />
if( retval && dwRead > 0 ) { <br />
<br />
....<br />
SetEvent(serialObj.hReadEvent);<br />
}<br />
}<br />
} while( dwRead > 0 );<br />
}<br />
}<br />
<br />
AfxEndThread(0);<br />
|
|
|
|
|
rp_suman wrote: WaitCommEvent() returns "false"
Well, that's your problem. The function failed. Did you check what was the problem by calling GetLastError() ?
BTW, did you check the documentation of the function ? You know that the function will return immediately when you are in overlapped mode ?
rp_suman wrote: AfxEndThread(0);
This is out of the context of your question but why do you call AfxEndThread here ? You should try to avoid killing your threads in such a brutal way, in general this can be easily avoided.
|
|
|
|
|
Hi, Thanks for the great help!!
I will check the points you have adviced.
Best Regards,
Suman
|
|
|
|
|
Hi,
After having WaitForSingleObject() function next to WaitCommEvent() function, the CPU rate become less.
With Thanks & Regards,
Suman
|
|
|
|
|
Hello everyone,
Could anyone show me the usage of pointer_default please (sample of when we need to use ref, unique and ptr)? After some search, I found too little materials on this topic.
thanks in advance,
George
|
|
|
|
|
George_George wrote: Could anyone show me the usage of pointer_default please (sample of when we need to use ref, unique and ptr)?
The ref attribute identifies a reference pointer. It is used simply to represent a level of indirection. Can not be NULL .
The unique attribute specifies a unique pointer. Can be NULL .
The ptr attribute designates a pointer as a full pointer. Can be NULL .
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi DavidCrow,
I also got the similar one-setence description from other books, but no detailed description. Especially for ref and unique, what are the restrictions (exception nullable) compared with normal pointer ptr? Any ideas?
regards,
George
|
|
|
|
|
George_George wrote: Especially for ref and unique, what are the restrictions (exception nullable) compared with normal pointer ptr? Any ideas?
Here are whole pages on ref and unique. As an added bonus, there are even code samples.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Read the Remarks section of this to understand aliasing.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks DavidCrow,
I have some further issue for unique attribute after some study for the link you recommended.
http://msdn2.microsoft.com/en-us/library/aa367294(VS.85).aspx[^]
(Especially confused about "before the call")
--------------------
Can use existing memory on the client without allocating new memory. When a unique pointer changes during a call from one non-NULL value to another, the pointer is assumed to point to a data object of the same type. Data returned from the server is written into existing storage specified by the value of the unique pointer before the call.
--------------------
I do not know why "Data returned from the server is written into existing storage specified by the value of the unique pointer before the call", especially "the value of the unique pointer before the call".
Suppose the following scenario,
1. client pass point ptr1 to server and ptr2 originally pointed to memory buffer1;
2. server change ptr1 to pointed to memory buffer2, which is different from buffer1;
3. server writes data through pointer ptr1, it should be written to buffer2.
So, it should be,
Data returned from the server is written into existing storage specified by the "lastest" value of the unique pointer, which is memory buffer 2.
Other than,
Data returned from the server is written into existing storage specified by the value of the unique pointer "before" the call, which is memory buffer 1.
Any comments?
regards,
George
|
|
|
|
|
Hello everyone,
The situation when we need to use this class is, we want to continue to append the content of string (not at one time, but at many times -- appending). Right?
Any other situations which use of this class (compared with other string and stream related class) will give us special benefits?
thanks in advance,
George
|
|
|
|
|
You can also expoit polymorphically the ostrsrteam inheritance from ostream to redirect the output on a string. The following (silly) sample depicts the idea
class HiFolks
{
ostream * _pos;
public:
HiFolks(ostream * pos):_pos(pos){};
void setos(ostream * pos){ _pos = pos;}
void sayHi()
{
(*_pos) << "hi folks" << endl;
}
};
void main()
{
strstream s;
HiFolks hf(&cout);
hf.sayHi();
hf.setos(&s);
hf.sayHi();
}
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
|
|
|
|
|
Thanks CPallini,
Cool sample!
Two more comments,
1. You agree with my points in original post?
2. In MSDN, there is no inheritance hierarchy information (at least I can not find from API document for ostrstream, could you find such information from MSDN)? for example ostrstream inherits from ostream.
regards,
George
|
|
|
|
|
George_George wrote: 1. You agree with my points in original post?
Since it is a (output) stream, yes.
George_George wrote: 2. In MSDN, there is no inheritance hierarchy information (at least I can not find from API document for ostrstream, could you find such information from MSDN)? for example ostrstream inherits from ostream.
Yes, here [^] (check out the grey rectangle).
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
|
|
|
|
|
Thanks CPallini,
For the "grey rectangle" you mentioned, do you mean the grey rectangle containing text "class ostrstream : public ostream", we can not click it to expand, and we only know ostrstream directs inherits from ostream. Right?
Sorry I have not made myself understood, is there an electronic form of all the classes hierarchy (GUI) form from MSDN?
regards,
George
|
|
|
|
|
AFAIK there isn't such diagram for STL in MSDN.
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
|
|
|
|
|
Thanks CPallini,
My question is answered. There is a hard copy in Bjarne's book.
regards,
George
|
|
|
|
|
George_George wrote: Any other situations which use of this class (compared with other string and stream related class) will give us special benefits?
This boost library[^] uses stringstream and offers a good way of formating strings.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
|
Sure.
ostringstream is part of the Standard.
If you are interested in some background, there is a chapter in N. Josuttis "The C++ Standard Library"
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Thanks jhwurmbach,
My question is answered.
regards,
George
|
|
|
|
|
Hi Friends,
I am in need to extract the exported
functions of a DLL.
If a DLL name is given,all exported functions in that
DLL must be listed out.
I used Dumpbin and tdump utility tools to do so.
But I need to make this without using any utility tools,
just mere by coding.
Could anyone please help me?
|
|
|
|