Re: WriteFile is sending screwy data to the Serial Port
From: tech_at_aquameasure (pmains_at_aquameasure.com)
Date: 07/22/04
- Next message: PKNET: "ADOCE 3.1 SDK"
- Previous message: Hank: "Secure sockets PPC 2003 difficulties"
- In reply to: Bruce Eitman \(eMVP\): "Re: WriteFile is sending screwy data to the Serial Port"
- Next in thread: Paul G. Tobey [eMVP]: "Re: WriteFile is sending screwy data to the Serial Port"
- Messages sorted by: [ date ] [ thread ]
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;
}
- Next message: PKNET: "ADOCE 3.1 SDK"
- Previous message: Hank: "Secure sockets PPC 2003 difficulties"
- In reply to: Bruce Eitman \(eMVP\): "Re: WriteFile is sending screwy data to the Serial Port"
- Next in thread: Paul G. Tobey [eMVP]: "Re: WriteFile is sending screwy data to the Serial Port"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|