Re: simple serial string display help

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Ok, I had the serial string stuff already from various examples I had
found across the net. So I am glad to see you have the same stuff here,
it reasures me that I am on the right track.
The CreateThread() is for creating the thread to check the serial port
I assume, yes? I figure that I could induce a screen re-draw if the
WaitCommEvent thread for receiving data was running simultaneously with
the WinMain thread . ( I am assuming that this wait event acts like an
interrupt and jumps to a portion of pre-defined code once the interupt
condition is met).
If thats the case, why couldn't I just put in all the screen redraw
stuff under the "subroutiene" of getting the serial data?

Let me add that this is going to go onto a Pencentra handheld tablet
and is ultimately going to end up in my old Bronco. I hopefully will
get it to communicate with an Atmel microcontroller and get the ADC
data from it(the Atmel). There are 8 ADC's each having 8bit usable
resolution, for vaious sensors that are on the vehicle such as
temperature, pressure, oxygen(in the exhaust), etc.... Basically I want
to display the 8 sensors, their digitized values on the Handheld, and I
would like to do it as the data comes in. Later in life, I want to use
one of the parallel ports on the Atmel to Bitbang a GPS signal into the
serial stream going to the handheld, but that is a much later project.

Anyhow, I hope this helps you understand where I am going with all
these crazy questions...



Paul G. Tobey [eMVP] wrote:
No, no UI notification of new serial data available. You have a whole
separate learning curve for that. You can create a queue, if that's really
the interface you're looking for and, each time something is added to the
queue (by the serial receive thread), the thread adding it could invalidate
the main window so that it will be repainted (in the UI thread), I guess.
One character at a time, is a very painful way to display stuff! Here are
the calls for serial I/O:

CreateThread() - not for inside the thread, but to start it.
WaitForSingleObject() - you'll probably want to signal the thread to exit
before exiting the application as a whole and you might want to wait to make
sure it exited. This call will do that when passed the thread handle.
CloseHandle() - don't forget to do this to the thread handle.

CreateFile() - open the serial port.
GetCommState() - get the default configuration of the port.
SetCommState() - change it to match whatever it's connected to.
SetCommTimeouts() - set up how ReadFile and WriteFile will react to various
port states.
ReadFile() - get data from the port.
CloseHandle() - don't forget that!

Paul T.

"benkokes@xxxxxxxxxxx" <benkokes@xxxxxxxxx> wrote in message
news:1160006331.367931.208780@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Paul, thats exactly what I needed to know! Thank you.

Now, just one more piece of help, if you dont mind. The WM_PAINT will
just pull in the value of the serial stream at the time of starting the
application. I figure there is some sort of API message that will
check when there is new data, that will allow me to "repaint" the
screen, but I dont exactly know what to look for... I was thinking of
WM_SOCKET_NOTIFY, but I dont think thats quite the correct direction.
Would you happen to know if there is some sort of "message" that will
allow me to check for new serial data? If not, I am going to have to do
some sort of timer, which would not be as desireable...

Thank you,
-Ben



Paul G. Tobey [eMVP] wrote:
Well, application programming for Win32 is too big a topic for a
newsgroup.
I'll give you a skeletal set of steps and you'll have to figure out the
rest
or be more specific about what the problem is.

1. Use the New Project wizard in eVC to generate the Hello, world
application (which seems to have been done).

2. Look at the handling of the WM_PAINT message in the main window's
window
procedure (just search the code for "WM_PAINT"). What that does is a)
start
the paint process, b) get the client (drawable), area of the main window
(a
rectangle), c) load a static string which is in the resources for the
application (defined in the .rc file and built into the .exe by eVC), d)
draw the string in the middle of the client rectangle, and e) complete
the
paint process.

3. So, what you need to do is get the serial character that you want to
display and use the same code as in the default WM_PAINT, *except*
drawing a
string consisting of just that one character. I'll assume that you're
right, that you do know how to get serial data, and that you've stored
the
character in a global variable called g_lastSerialChar. In WM_PAINT,
then,
you don't need the LoadString call any more. You can comment that out.
Instead, you need to put the g_lastSerialChar in the first character
position of szHello and make sure that the next character is 0, to
terminate
the string.

Here we get into a long discourse on Unicode. Windows CE programs are
*all*
Unicode based. This is different than the desktop, standard C, etc.
programs that you're likely to see. Pretty nearly every string that
you'll
use in Windows CE, other than serial port data, file data, and network
data,
is expressed in Unicode characters, *not* of standard C data type 'char'.
Each Unicode character is 16 bits, unsigned short or wchar_t, long. So,
we
have a single char, but we need to pass DrawText a Unicode string. In
this
case, for a single character, it's pretty easy, since the serial data is
presumably 7-bit ASCII, you can just assign the characters:

szHello[0] = g_lastSerialChar;
szHello[1] = 0;
DrawText(...);

For more complicated strings, you'll want to use a conversion functions
(which will also allow you to handle non-English languages). Those are,
amongst others:

MultiByteToWideChar()
WideCharToMultiByte()

They're in the help.

Paul T.

"benkokes@xxxxxxxxxxx" <benkokes@xxxxxxxxx> wrote in message
news:1159999651.810316.298780@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hey all,

So I would like to make a very small WinCE 2.11 application that would
take a serial stream and display the incoming 8-bit word on the screen.
Basically I would like to take the default "Hello World" applicaiton
and replace the words Hello World with a character (whatever ascii
character gets transmitted over the serial line) on the display. Just
one character, I dont want it to scroll, or move.

I cant think that it would be all that hard, but the Hello World
example in eVC 3.0 has it pointing to a .rc file and I have never dealt
with those before.

I think I understand how to setup the serial comms part of the code,
but I dont quite understand how to update the display of the character
on the screen.

I bought the Windows CE developers Kit which contains the books, but
its all still a hair convoluted...

Any help would be appreciated.
Thanks!
-Ben



.



Relevant Pages

  • [TOMOYO #15 3/8] Common functions for TOMOYO Linux.
    ... This file contains common functions (e.g. policy I/O, pattern matching). ... Since TOMOYO Linux is a name based access control, ... TOMOYO Linux's string manipulation functions make reviewers feel crazy, ... the Linux kernel accepts all characters but NUL character ...
    (Linux-Kernel)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • Re: simple serial string display help
    ... you tell the main window to update. ... draw the string in the middle of the client rectangle, ... what you need to do is get the serial character that you want to ... Here we get into a long discourse on Unicode. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: RfD: Escaped Strings
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... \b BS (backspace, ASCII 8) ... \ ** escapes to characters much as C does. ...
    (comp.lang.forth)