Hello,
I have had success doing rs232 where my cpu can read from my PC. I am now
trying to get my PC to read from my cpu. I had success on this also, 2 months
ago at reading 8 bytes into the PC end. Everything was fine, however, today I
had the uncontrollable urge to try to read 9 bytes!!!!!! Well guess what?
back to the drawing board I am!
:-)
I want to ask a very simple question and go step by step! Because I though I
understood what I was doing 2 months ago after extensive research on the
subject, but I am obviously wrong!
On my cpu end, I am sending a string like this:
///////////////////////////////////////////////////////////////
char RS232_1_ExtOut[] = "ABCDEFGH";
for(i=0;i<7;i++)
fputc(RS232_1_ExtOut[i],COM_1);
/////////////////////////////////////////////////////////////
As you can guess, this sends a string of eight characters out on com 1 of
the cpu!
Now, on the PC side (VC++) I have:
///////////////////////////////////////////////////////////////////
static DWORD dwBytesRead = 8;
static BYTE abBuffer[9];
int TEMP;
MySerial.Read(abBuffer,sizeof(abBuffer),&dwBytesRead);
TEMP++;
//////////////////////////////////////////////////////////////////
Okay, I have a break point on the "TEMP++;" line!
For starters, ain't I supposed to read 8 bytes max, hence the variable
dwBytesRead?
And, abBuffer has enough room to hold the total amount of bytes read plus a
null termination character. Right!
So why, at this particular moment at breakpoint time! , abBuffer contains,
"ABCDEFGÃ?Ã?"
2 Months ago when I got this to work, in the cpu code, I used to send a null
character "\0" after my string. I stopped doing this, because I realized it
didin't have any effect.
I have been told before by news groups fellows that rs232 returns many
bytes, but isn't the purpose of the:
MySerial.Read(abBuffer,sizeof(abBuffer),&dwBytesRead);
function, supposed to limit the amount of bytes read to the value passed in
the 3rd parameter?
All suggestions and help is very appreciated!
P.S. Does anyone know where I can get documentation describing all of the
Serial class.... I tried to ask this to the author, but got no response!!!
--
Best regards
Robert