Re: WriteFile is sending screwy data to the Serial Port

From: tech_at_aquameasure (pmains_at_aquameasure.com)
Date: 07/22/04


Date: 22 Jul 2004 15:14:54 -0700


"Bruce Eitman \(eMVP\)" <beitmannospam@nospam.neo.rr.com> wrote in message news:<O0iER#5bEHA.1356@TK2MSFTNGP09.phx.gbl>...
> As a sanity check, try putting it in a debugger and change to CreateFile on
> a text file. That will allow you to debug the code first, then you can
> debug the serial.
>
> The problem isn't on the receiving end is it?

Here's my setup: I have a WinCE device (LogicPD LH7A400, ARM922T chip)
which is acting as a front end for a 1970s style moisture sensor. I
currently have the device connected to my PC via a 9-pin serial cable
and I'm using Tera Term to monitor the output. This way, I can see
what data would be passed to the target device in a real-world
situation.

I used the EVC debugger in emulator mode, which helped me work out a
few annoying kinks elsewhere in the program. However, I could find no
reason why WriteFile shouldn't print 'M', 'C', 'L', and '?'. I believe
the debugger may have helped my sanity though, Bruce.

When using the debugger, I can see the value of the parameters being
passed to WriteFile, so I know the data isn't mangled before being
written. It's only after the data is transmitted that the value of the
data is off by either 192 (A0) or 160 (C0). The offset is dependent on
the original value of the character, not the order in which the
characters are printed (I have determined experimentally).

This leads me to question the integrity of pin 3 (Transmitted Data) on
my DB9 Serial Port. Or, there could be a quirk in WriteFile that I'm
unaware of. Or, I simply have stored the data in an inappropriate data
type. If so, I am curious as to what type of data type I should use.

The serial port reads fine given the same settings (GENERIC_READ |
GENERIC_WRITE, 9600, 8 and 1). If I change the OpenPort function to
open a file on the flash card, I can write data fine. But writing to
the serial port only creates mangled output. I've read the data 4
different ways on 3 different machines (A PC, a laptop, and the
intended target device). I always get the same errors -- phi instead
of M, infinity instead of L, and pi instead of C.

To paint a more complete picture, here's how I'm calling DoTxData():

bool SendM(HWND hWnd)
{
        DWORD dwDataSize = 1;
        char *txData = new char[2];
        strcpy(txData, "M");

        if( !DoTxData(hWnd, txData, dwDataSize) )
        { ErrorReport(hWnd, TEXT("Can't write M: ") );
                return false; }

        Sleep(200);
        strcpy(txData, "?");
        
        if( !DoTxData(hWnd, txData, dwDataSize) )
                { ErrorReport(hWnd, TEXT("Can't write ?: ") );
                delete txData;
                return false; }

        delete txData;
        return true;
}



Relevant Pages

  • Re: 7.0-STABLE amd64 kernel trap during boot-time device probe
    ... problem still occurs with 7.0-STABLE (csup on 20080301). ... A trap triggering a panic is still a panic. ... anything once I got into the debugger. ... This means that the serial port is expecting to talk to a remote GDB ...
    (freebsd-stable)
  • Re: Connectivity problem with PB 5.0
    ... why it doesn't boot when uploaded from PB ... ... you still have upload image from PB using the ... have a serial cable attached to the serial port ... Debugger service map is set to none. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Interrupt-driven serial comm for Linux ?
    ... serial port are the ones you need. ... file descriptor (which also gives me a chance to set a timeout ... application framework with a low level debugger. ... Perhaps because there aren't that many "nasty intricacies" as ...
    (comp.os.linux.development.apps)
  • sio / puc wedging on both -current and -stable
    ... shorts across the serial port *or* plug the serial port into a working ... I have a remote debugger setup and I can send a break and drop the unit ... but kernel debugging is a little beyond our skillset. ...
    (freebsd-current)
  • Re: How to connect to children process
    ... Main problem is amount of manual operations required per debug cycle. ... connection to DLL with debugger takes sensible amount of time and manual ... Is the main problem that the debugger keeps symbols file loaded ... AFAIK that's how VS2003 debugger works, but WinDbg should usually ...
    (microsoft.public.vsnet.debugging)