|
Hi
I am using the library I found here:
http://www.codeproject.com/system/serial.asp
in my program. However, I run into the following problem when I am reading from a comport. (example listener).
I took the code, and created a little function
int readme(CSerial &serial)<br />
{<br />
LONG lLastError = ERROR_SUCCESS;<br />
lLastError = serial.SetMask(CSerial::EEventBreak |<br />
CSerial::EEventCTS |<br />
CSerial::EEventDSR |<br />
CSerial::EEventError |<br />
CSerial::EEventRing |<br />
CSerial::EEventRLSD |<br />
CSerial::EEventRecv);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port event mask"));<br />
<br />
lLastError = serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port read timeout."));<br />
<br />
bool fContinue = true;<br />
do<br />
{<br />
lLastError = serial.WaitEvent();<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to wait for a COM-port event."));<br />
<br />
const CSerial::EEvent eEvent = serial.GetEventType();<br />
<br />
if (eEvent & CSerial::EEventBreak)<br />
{<br />
printf("\n### BREAK received ###\n");<br />
}<br />
<br />
if (eEvent & CSerial::EEventCTS)<br />
{<br />
printf("\n### Clear to send %s ###\n", serial.GetCTS()?"on":"off");<br />
}<br />
<br />
if (eEvent & CSerial::EEventDSR)<br />
{<br />
printf("\n### Data set ready %s ###\n", serial.GetDSR()?"on":"off");<br />
}<br />
<br />
if (eEvent & CSerial::EEventError)<br />
{<br />
printf("\n### ERROR: ");<br />
switch (serial.GetError())<br />
{<br />
case CSerial::EErrorBreak: printf("Break condition"); break;<br />
case CSerial::EErrorFrame: printf("Framing error"); break;<br />
case CSerial::EErrorIOE: printf("IO device error"); break;<br />
case CSerial::EErrorMode: printf("Unsupported mode"); break;<br />
case CSerial::EErrorOverrun: printf("Buffer overrun"); break;<br />
case CSerial::EErrorRxOver: printf("Input buffer overflow"); break;<br />
case CSerial::EErrorParity: printf("Input parity error"); break;<br />
case CSerial::EErrorTxFull: printf("Output buffer full"); break;<br />
default: printf("Unknown"); break;<br />
}<br />
printf(" ###\n");<br />
}<br />
<br />
if (eEvent & CSerial::EEventRing)<br />
{<br />
printf("\n### RING ###\n");<br />
}<br />
<br />
if (eEvent & CSerial::EEventRLSD)<br />
{<br />
printf("\n### RLSD/CD %s ###\n", serial.GetRLSD()?"on":"off");<br />
}<br />
<br />
if (eEvent & CSerial::EEventRecv)<br />
{<br />
DWORD dwBytesRead = 0;<br />
char szBuffer[101];<br />
do<br />
{<br />
lLastError = serial.Read(szBuffer,sizeof(szBuffer)-1,&dwBytesRead);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to read from COM-port."));<br />
<br />
if (dwBytesRead > 0)<br />
{<br />
szBuffer[dwBytesRead] = '\0';<br />
<br />
printf("%s|", szBuffer);<br />
<br />
if (strchr(szBuffer,EOF_Char))<br />
fContinue = false;<br />
}<br />
}<br />
while (dwBytesRead == sizeof(szBuffer)-1);<br />
}<br />
}<br />
while (fContinue);<br />
serial.Close();<br />
lLastError = serial.Open(_T("COM1"),0,0,false);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to open COM-port"));<br />
<br />
lLastError = serial.Setup(CSerial::EBaud38400,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port setting"));<br />
return 0;<br />
}
then, what I do is following:
int __cdecl _tmain (int , char** )<br />
{<br />
CSerial serial;<br />
LONG lLastError = ERROR_SUCCESS;<br />
<br />
lLastError = serial.Open(_T("COM1"),0,0,false);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to open COM-port"));<br />
<br />
lLastError = serial.Setup(CSerial::EBaud38400,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port setting"));<br />
<br />
<br />
<br />
<br />
lLastError = serial.Write("\nwhoami\n");<br />
int r;<br />
<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Error sending a return"));<br />
lLastError = serial.Write("\nwhoami\n");<br />
<br />
r = readme(serial);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Error sending a return"));<br />
<br />
<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Error sending a return"));<br />
<br />
serial.Close();<br />
return 0;<br />
}
ok when the first is commented out, I see the results of both functions. but when the first readme is there, it only reads up to that point, and goes no further.
why is that so? I would like to read information step by step, as it needs to processed.
thanks alot for any help
quarry
|
|
|
|
|
Hello,
Put the caret next to that line and than hit "run to cursor" in your Debug menu. Second step in your code and see where your code hangs and post more specific information on your problem. Until then, most people here will not bother to look at your post with so much code.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
hey thanks for the answer
if (strchr(szBuffer,EOF_Char))<br />
fContinue = false;
I think the problem is, that this never happens.
so it gets stuck in this while loop, where there is a function
lLastError = serial.WaitEvent();
but nothing happens here neither. how can interupt this loop?
thanks
|
|
|
|
|
Hello,
I think your problem is that you wait forever for an event. So I guess that no event arrives on your COM port and that you are stuck in the WaitEvent() function.
See if this helps:
lLastError = serial.WaitEvent(NULL , 100 );
if( lLastError == ERROR_TIMEOUT )
{
}
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi All,
Ive got a project which was developed in Visual C++ version 6.0.
Now Ive got to make it access a web service to get data from a database...
First of all im COMPLETELY ignorant on these matters, but i suppose we've all got to take the plunge sometime...
I know that in the Visual Studio .NET version there are some tools to "automatically" generate the volumes of code required to do the web service method accessing stuff, but I dont want to change to .NET just to do this little thing!
Is there a simple generalized web service accessing API which wraps all the crap required to access a web service into a few simple routines?
Ive been looking around the net but im not convinced that Ive found the perfect solution.
Thanks in advance for any pointers,
Dave
|
|
|
|
|
Search here on CP for an article by Anders Molin. It has a class that does exactly what you are looking for.
|
|
|
|
|
|
Now I am able to read data from a .rtf file and write its contents in a rich edit control. Now I want to include this .rtf file as a resourse (just like we include bitmap), to print its contents in a rich edit control. Please can anyone tell me how can i do that?
Thank you
Aqueel A. Mirza
We Believe in Excellence
|
|
|
|
|
Goto the resource pane: right click on the on the root node of the list and select import.
OR
Insert->Resource->Import
OR
Ctrl+R
You should be able to figure out the rest from there.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Here is a somewhat related example.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi,
I have a class derived off CDialog that I use as a child dialog in a tab control.
The problem I have is that the background of the dialog is gray but the tab control's background is white (xp look).
How can I get the child dialog's background to be the same color as the tab control's background?
I would prefer not to have to change the tab control as I'm using a class from a library and I would like to have a general solution that applies not only to tab controls but any parent window.
I tried overriding OnEraseBkgnd and calling
HBRUSH hBrush = (HBRUSH) GetParent()->SendMessage(WM_CTLCOLORDLG, m_hWnd);
and using the returned hBrush to fill the dialog's client area but that threw exceptions.
I've also tried not erasing the background.
Any help would be appreicated.
Regards,
Liehann
|
|
|
|
|
The window class adjusts the (normal) background color. The easiest way to override these settings is to handle WM_ERASEBKGND with TRUE as return (to prevent flickering) and handle WM_PAINT to paint the background (e.g. CDC::FillSolidRect).
Don't try it, just do it!
|
|
|
|
|
Thanks for the reply.
How can I get the parent window's background color in OnPaint?
|
|
|
|
|
Hi,
I need some help with dlls. It's my first time writting dlls and I have a minor problem.
<br />
#ifdef MYPROJ_EXPORTS<br />
#define _myprojExport __declspec(dllexport)<br />
#else<br />
#define _myprojExport __declspec(dllimport)<br />
#endif<br />
<br />
class _myprojExport MyClass<br />
{<br />
...<br />
protected:<br />
typedef std::list<std::string> StringList;<br />
StringList mylist;<br />
};<br />
As you can see on the above code I have MyClass which is a simple class that I export. When mylist member is missing everything is compiled smoothly, however when I have mylist member variable on the class I get the following warning from my compiler (VS .NET 7.1).
warning C4251: 'MyClass::mylist' : class 'std::list<_Ty>' needs to have dll-interface to be used by clients of class 'MyClass'
with
[
_Ty=std::string
]
How can I create a dll-interface for std::list? I don't have to export std::list the client will find its implementation in <list>. How should I declare mylist in order to get rid of these warnings?
Thanks in advance,
Themis
|
|
|
|
|
Anyone know if this is possible.
I know I can define a function to do that kind of thing......
#ifdef DEBUG
# define STUFF(x) x
#else
# define STUFF(x)
#endif
but what I would like to be able to do is define something so that I could just make the compiler ignore the line.
#ifdef DEBUG
# define ONLY_DEBUG cout
#else
# define ONLY_DEBUG //
#endif
e.g. ONLY_DEBUG << "this is a debug build" << endl;
This is only an example I know I can use TRACE etc, its been able to get rid of something in debug, short of having #ifdef DEBUG around it.
|
|
|
|
|
I don't think that it's possible to set a comment as define.
Why don't you create a define like that:
#ifdef _DEBUG
#define DPRINT( x ) cout << x << endl
#else
#define DPRINT( x )
#endif
Don't try it, just do it!
|
|
|
|
|
Hello,
Why don't you just try it? I think that it is possible, since you canno't use '//' comments in macro's since it will erase some of your code when the preprocessor expands it to a single line...
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
I'm creating a modal child dialog and a modeless child dialog to learn about them.
I have a simple SDI application that calls the dialogs.
The modal child dialog derived from CDialog opens up behind the mainframe and does not have the focus, nor is it ever able to obtain the focus once I find it, i.e. title bar remains grayed and cannot click on any buttons on the modal child dialog. Properties of the dialog are child and visible.
CModalChild cmd;
cmd.DoModal();
The modeless child dialog opens up as it should but does not have the focus nor is it ever able to obtain the focus, i.e. the title bar remains greyed although the modeless child dialog is functional.
if (!m_pModelessChildDialog)
m_pModelessChildDialog= new CModelessChild;
if (!::IsWindow(m_pModelessChildDialog->GetSafeHwnd()))
m_pModelessChildDialog->Create(IDD_DIALOG6, this);
m_pModelessChildDialog->ShowWindow(SW_SHOW);
Hope someone can help me understand this. Thanks.
|
|
|
|
|
Hello.
In the SDI project, you should show your dialogs after created the mainframe class. You should calling the DoModal or ShowWindow Founctions in the your view class.
excuse me if my sentences are not complete. because, I don't know english well.
Zo.Naderi_Iran
|
|
|
|
|
Thanks Zo. Yes both are being called from the Mainframe's view class but still the problems.
|
|
|
|
|
I think, even though u r calling DoModal() on modal dialog box, the main focus is present on the view and mainframe and the Menu is grayed may be because you may have attached the menu to the dialog box instead to the main window. Try attaching the menu to the main frame window.
Work hard and bit of luck is KEY to SUCCESS.
|
|
|
|
|
Thanks, but no menus involved. Just the form view calling a modal child dialog via a button and the form view call a modeless child dialog via another button.
|
|
|
|
|
I want to get the handle for the drop down button of a Combo Box control.
I tested the following code but the drop down button doesn't seem to be a child of the CComboBox:
...
CWnd* pChild = this->GetWindow(GW_CHILD);<br />
hwndChild=pChild->GetSafeHwnd();<br />
::GetClassName(hwndChild, szClassName, 256);<br />
if(!memcmp(szClassName, "Edit", sizeof("Edit")))<br />
{<br />
<br />
pChild = pChild->GetWindow(GW_HWNDNEXT);<br />
<br />
if(pChild)<br />
{<br />
hwndChild=pChild->GetSafeHwnd();<br />
::GetClassName(hwndChild, szClassName, 256);<br />
}<br />
}
...
Any ideas?
Thanks,
Lula Capixaba
|
|
|
|
|
lulacapixaba wrote:
the drop down button doesn't seem to be a child of the CComboBox
of course it isn't, otherwise how could it be itself a par of the conbobox ?
A ComboBox can be see as a set of 3 controls encapsulated into once : an editbox, a listbox and a button.
about accessing one of these parts, i really don't know how to do, and am waiting with interest for an answer too, but i think you should search for Owner Drawn control...
ps: just curious, what are you trying to do with this button ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I've just researched this problem; conclusion:
There is no button to get, the button is drawn by the control and is not a child window.
Where I looked: MSDN, PUI library code (see CP article) and I used spy to double check my conclusions.
I assume you want to control over how the button is drawn. In which case look at the PUI library code, plus other articles on drawing Win2000 and WinXP style minues a buttons.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|