Success!
rs232 communications between VC++ and a PIC microcontroller have been
established!
What a relief!
I *must* be very thankfull to the news groups for this ! You guys were
great, and I would of never of made it without your help!
Although all was constructive, I ran into one last but simple question!
As I have been learning VC++ and some of all of its vast world of
programming, Windows data types have creeped back, and as I looked at posts
on this from 6 months ago, I feel I would still need some guidence regarding
this particular issue.
So here is my question:
As VC++ is the software that I am using on the PC end, as you may know, one
of the methods of the serial class is :
MySerial.Write("x");
Therefore as you know, the first parameter of the "Write" function takes a
LPCSTR.
You see.... at the microcontroller end, the C code reads this byte by the
following line: c=getc(); in the code fragment below:
=====================
void get_string(char* s)
{
int len;
char c;
len = 0;
do {
c=getc(); //getc is a ready made function by the compiler which waits
// for a character to be received. So until VC++ doesn't
// send something, the controller stays at this line!
if ((c>=' ')&&(c<='~')) //if 'c' is within range, then append to array
s[len++]=c;
} while(c!=13); //Wait for enter key!
...other code...
======================
In the above code, I have only included the pertaining lines to my question,
but its pretty much representative of what the function consists of.
So, in the above code, it waits for a character and once recieved, it
appends it to "s". So, if VC++ sends a "B", then a "B" will be appended in
the string array "s".
This continues until VC++ sends a ascii code for "enter key", which is ascii
code 13.
My question is, given the code shown above for the *PC end*, how would VC++
, by using code, send an "enter" or a "13" in this case?
I tried,
MySerial.Write("13"); //The controller only reads: "1" instead of 13
The next line doesn't work either:
MySerial.Write(13);
And before I try all kinds of type castings, I would prefer to get some
understanding of what needs to be done. I mean, if MySetrial.Write() takes a
LPCSTR and the C language at the controller end needs to see a 13 to
understand that VC++ sent the 'enter key' code, then I need to convert 13 to
"13"... right?
What's happens now, is that the controller doesn't recognize 13, no matter
which of the following commands I do:
MySerial.Write(13);
or
MySerial.Write("13");
or
int x;
x=13;
MySerial.Write((WCHAR)x); //Which makes no sence, since it expects a LPCSTR
If I may be excused on this one, its been a while since I have been set
straight on Windows data types, even though given the fact that the news
groups have done more than great job at explaining me this stuff months ago!
All help much appreciated!
And again, thankyou all fellow newsgroups!
--
Kind regards
Roberto