mobile databases, mobile forms, and mobile synchronization … where you need to work
Providing Pocket Access, Mobile Database, Windows CE Database, and Windows CE Development Solutions

Tip of the Month (December 2009)

Sending Binary Data Over a COM Port

In a macro, Visual CE allows you to open a COM port (Communicate | Open) and send a text (Communicate | Send). But what if you want to send binary information? It can be done, but it is a little tricky.

Normally we send characters. So, if you specify the character string

    A B C
then Visual CE will send the ASCII equivalent of
    0x41 0x42 0x43
We do not send the zero terminator.

Visual CE has a @char function, so if you send

gets sent (hexadecimal 0x41 is the same as decimal 65).

Sending a byte of zero could be a problem (since 0x00 is the terminator for character strings). To accomodate this, we made a special case for when you send just

If this is the entire expression specified in the Communicate | Send, then we will send a byte of zeros.

So, lets say you wanted to transmit

You can do this by doing Communicate | Send three times. The first would send
    @char(65) & @char(67)
the second would send
and the third would send
(you couldn't just send @char(65) & @char(67) & @char(0) & @char(19) since the @char(0) has to be in a Communicate | Send all by itself in order to send the byte of zeros).

Previous Tips of the Month