rs232- [C]
Hello,
It *was* a success... however not for long! :-)
Please consider the following code:
============================================
#include "Serial.h"
#include "SerialEx.h"
#include "SerialWnd.h"
CSerialWnd MySerial;
LRESULT CALLBACK WndProc_CW1 (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
static DWORD dwBytesRead = 0;
static BYTE abBuffer[40]; //Bytes
static TCHAR szBuffer[80]; //Wide characters
....other code...
MySerial.Open(TEXT("COM1"),hwnd,WM_NULL,lParam,0,0);
if (message == CSerialWnd::mg_nDefaultComMsg)
{
// A serial message occurred
const CSerialWnd::EEvent eEvent = CSerialWnd::EEvent(LOWORD(wParam));
const CSerialWnd::EError eError = CSerialWnd::EError(HIWORD(wParam));
switch (eEvent)
{
case CSerialWnd::EEventRecv:
MySerial.Read(abBuffer,sizeof(abBuffer),&dwBytesRead); //Break point
break;
default:
break;
}
MultiByteToWideChar(CP_ACP,0,(LPCSTR)abBuffer,40,szBuffer,80);
MySerial.Close();
return 0;
}
switch(message)
{
case WM_SIZE:
....other code...
=================================================
The micro controller is sending the following message to VC++,
printf("Enter the first number: ");
And all I am able to read is the following as I put my cursor over abBuffer
(in which has a breakpoint on it) is:
"Enter thUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"
Except that there is two dots on top of al the U.
A little discouraged!
I mean why would it read the first 8 characters and then all Us?
And furthermore, sometimes I get the right result, being:
"Enter the first number: UUUUUUUUUUUUUUUU"
Its like rs232 is inconsistant?
Can someone help!
Thanking you in advance!
--
Best regards
Robert