RE: rs232- [C]
Hi,
This is an update of the comm problem on rs232!
Did anyone experience severe inconsistencies in rs232 communications! Because
I am!
Its been 32 hours of consistencies to be more precise!
I have narrowed it down to the fact that it can't be the communications
hardware settings, because when I connect the Micro controller end to the
manufacturer's Serial monitor program which is on the PC end, the
communications are fine!!! And the Serial monitor program is set to 9600, No
parity, 8 data bits, 1 Stop bit, and I tried also to set it up in VC++ by
doing:
MySerial.Setup(CSerial::EBaud9600,CSerial::EData8,
CSerial::EParNone,CSerial::EStop1);
And I get the same inconsistencies.... Always with the read though! I have
no problems with the write!
So basically I have problems only with the read.... is it because of the way
I set up the read code...(See innitial question in this post).
I usually like to understand every bit of code I do, however I feel
vulnerable because I don't quite know everything about the serial classes I
added to my project, there is some coding in there that I have not even
learnt yet! so I am sort of taking it for granted that these serial classes
work and that I am using them right!
....is it because I should create the Serial object in a class somewhere?
....is it because my cable is approximately 25 feet long between my PC and
the micro controller chip?
All I know is that I am using two wire communications (Recv and transm).
ANd if we refer to a DB9 connector pin outs. On the PC end, the receive pin
#2 is connected to the DCD pin#1. I don't know exactly why it is wired this
way, I mean a DCD is used to indicate that the carrier of a remote modem has
been senced by the local modem....or simpler yet, it informs the PC that
somdething has been detected... so be ready!
Well! I am washed out on this one! It is approximately a week that I have
kept on asking questions and pushing so to try to get this rs232 up and
kicking, but I have to admit, I am out of ideas, and I hope to hear from you
guys!
At this point, I would appreciate some guidence on the structure of the code
that I did for the Serial object done in my first question of this post!
All sincere help appreciated!
--
Best regards
Roberto
:(
"Robby" wrote:
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