|
Hi ,
I have created sample application which opens the serial COM Port and tried to write and Read the data.
I have used CreateFile () method to open the COM1.
hCom = CreateFile (pcCommPort,GENERIC_READ | GENERIC_WRITE,0,NULL, OPEN_EXISTING, 0,NULL );
Then I set the COM state
GetCommState( hCom, &lpCC.dcb);
lpCC.dcb.BaudRate = CBR_9600;
lpCC.dcb.StopBits = ONESTOPBIT;
lpCC.dcb.ByteSize = 8;
lpCC.dcb.Parity = NOPARITY;
lpCC.dcb.fBinary = TRUE ;
lpCC.dcb.fParity = TRUE ;
SetCommState( hCom, &lpCC.dcb );
I am trying to write the data using
WriteFile (hCom,(LPCVOID)ptr,20,&byteswritten,NULL);
and trying to read the data using
ReadFile (hCom, (LPVOID)ptr, 20, &dwBytesTransferred, 0);
ptr is pointer to the BYTE array. The above code of "ReadFiles() returns true and Reads Junk characters. I have written exact 20 characters through WriteFile() and it returned TRUE . I am not able to figure out the exact problem . Please provide any input in this regards.
Thanks
|
|
|
|
|
pandit84 wrote: ...and Reads Junk characters.
How are you verifying this?
Do you know that data is available to read before calling ReadFile() ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
I am printing the ptr using printf statement.
|
|
|
|
|
if you're doing this between two computers, you are using a null-modem cable?
|
|
|
|
|
I have not yet tried this on two computers. I am using only one computer to test.
|
|
|
|
|
I doubt very much the COM redirector understands how to loopback
i.e. You can't read and write on the same COM port on the same computer, and if you have a machine with two COM ports, you still need a null modem cable between them
modified on Wednesday, May 18, 2011 4:31 AM
|
|
|
|
|
And that looks like?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
|
That's what your printf() statement looks like?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
oops I am sorry
printf("The date %s", ptr) ;
|
|
|
|
|
Ok, so are you using communications events?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
No I am not using communication event. I have tried using
::WaitCommEvent . But it never get any event and it goes into continuous wait state. So I have removed that and tried to read the Port using ::ReadFile () without using any event.
|
|
|
|
|
pandit84 wrote:
. But it never get any event and it goes into continuous wait state.
Which means nothing is available to read.
pandit84 wrote: So I have removed that and tried to read the Port using ::ReadFile () without using any event.
So reading what's not available (to read) seemed like a better idea?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
You just got to use overlapped I/O when you are using COM ports. There are some classes/samples here. Just search for a suitable article.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Finally this solution works for me. What I did is
1. In ReadFile() - Read from different COM port. E.G Writing is done on COM1 and Reading is Done on COM2. As I was having only 1 COM Port . I installed Virtual Port Software on my machine and Paired COM1 and COM2
2. ReadFile() provided a buffer of exact size which I used in WriteFile () method.
|
|
|
|
|
Is there a method to start a child window ( in a MDI application ) without get a flikering ? I try in this way :
void CMainFrame::OnOpenChildWindow()
{
POSITION pos = theApp.GetFirstDocTemplatePosition();
CMultiDocTemplate* pDocTemplate = (CMultiDocTemplate*)theApp.GetNextDocTemplate(pos);
pDocTemplate = (CMultiDocTemplate*)theApp.GetNextDocTemplate(pos);
pDocTemplate->OpenDocumentFile(NULL);
pChild = (CMDIChildWnd*)MDIGetActive();
if(pChild)MDIMaximize(pChild);
}
but because I have a little code ( that takes time ) in OnNewDocument() , I see child window that is opening in restore state , and after that child window is maximized ...
|
|
|
|
|
You might want to try the OnCreate message for your child window instead. I think you can adjust settings, Eg., window position, state, etc, in this message so that the window opens maximized.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Hi all
I am creating an application in win32 api(c++ not MFC) and when i resize window the portion of non affected window is also get redrawn that causes flicker effect.so can anyone inform me how to handle WM_PAINT message so that only affected part of window will redraw??
Its urgent... Thank you in advance...
--
Thanks and Regards
Hemant metalia
hemant_metalia@yahoo.com
|
|
|
|
|
Hi,
I see three factors here:
1.
the repaint job holds a region, only things inside the region needs repainting, so your painting code could take that into account; however, the repaint region often is larger than necessary, so this may well be insufficient.
2.
improving the paint code performance is always a good idea, it also reduces the disturbance, hence flicker, you would notice. It does not avoid it, just makes it less annoying.
3.
the real solution is using double-buffering, where the actual painting happens in a memory-based buffer, then that buffer gets painted in one swoop to the screen, without erasing the current content. You'll have to Google for details in C++, I'm not able to provide you any code as I work mostly in C#.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
As Luc said take a look at double buffering, this code project article might help.
But in general terms you will need to modifiy you paint routine to do all your drawing to a compatible memDC, once drawing is complete you'll need to blit the area you require to the screen DC.
|
|
|
|
|
What Luc said, plus consider using BeginDeferWindowPos() , DeferWindowPos() , EndDeferWindowPos() in your WM_SIZE handler. These APIs allow you to accumulate the movement of multiple windows (controls), and them update them all when the repositioning is finished.
|
|
|
|
|
Hi all,
I want to convert a CString variable to unsigned long long . I know for long we can do it using api atol(long);
but what to use for unsigned long long...
Anybody please help
modified on Tuesday, May 17, 2011 3:44 AM
|
|
|
|
|
|
Yes, but he wants string to long long.
The best things in life are not things.
|
|
|
|
|
I would guess you probably need this[^].
The best things in life are not things.
|
|
|
|