hi!
ok.. going crazy over this :)) time to reach our for any comments and
suggestions from someone who has done this before :P
i am trying to get some communication going between my application and
a special piece of hardware that is connected via the serial port. my
code is as follows:
---
// find the library, it MUST be there
SysLibFind("Serial Library", &globals->serialLibRef);
// open the serial port, configure it
{
SerSettingsType newSettings;
newSettings.baudRate = 57600L;
newSettings.flags = serSettingsFlagStopBits1 |
serSettingsFlagRTSAutoM |
serSettingsFlagCTSAutoM |
serSettingsFlagBitsPerChar8;
// open port + force settings
SerOpen(globals->serialLibRef, 0, 57600L);
SerSetSettings(globals->serialLibRef, &newSettings);
}
// ok, lets determine if we have a connection (battery ok)?
{
Char cmd[4] = { 0x47, 0x42, 0x54, 0x31 };
Char response[32] = "";
UInt32 qty, count, delay;
Char strStatus[32];
Err err;
// send the command
SerReceiveFlush(globals->serialLibRef, 0);
SerSend10(globals->serialLibRef, cmd, 4);
// lets give the "box" 1/8th of a second to respond
delay = SysTicksPerSecond() >> 3;
SysTaskDelay(delay);
// let wait until there is something there, timeout after 7/8 second
for (count=0; count < 7; count++) {
// whats in the queue?
err = SerReceiveWait(globals->serialLibRef, 5, delay);
if (err == serErrLineErr) SerReceiveFlush(globals->serialLibRef, 0); else
if (err == errNone) break; // its there, get out
}
// how many bytes are really available?
err = SerReceiveCheck(globals->serialLibRef, &qty);
if (qty >= 32) qty = 31; // our buffer limit
// did we get a response we can understand?
if ((err == errNone) && (qty != 0)) {
// get the bytes from the queue
SerReceive10(globals->serialLibRef, response, qty, 0);
response[qty] = '\0';
// we got the right protocol?
if ((qty == 5) && (response[0] == 'C') && (response[1] = 'T')) {
StrPrintF(strStatus, "v%c.%c, %s",
response[2], response[3],
response[4] == 'G' ? "Ready" : "Bad Battery");
}
else
StrCopy(strStatus, "Unknown Device");
}
else
StrCopy(strStatus, "Not Connected");
}
---
this code works, if i connect my Palm Device to the serial port and use
a terminal program like Hyperterminal to send text and back forth. As
soon as i connect it to my "device", i always get a "qty == 0"
situation. no bytes are being received when i connect to the real
device..
i have tested if the device works correctly, by using Online 1.41
(demo) and sending info and and from it.. getting responses. the device
gives all the responses i would expect :) i used the same config options
57600, 8N1 :P
does *anyone* have an idea what could be wrong here? :))
i am using SerSend10() and SerReceive10() - but even with the 2.0+
versions, i get the same results.. using thew new serial manager is not
an option. its just confusion i can get it working if i act as the
device over Hyperterminal :)
i lost another days sleep on this :) hehe
cheers
// az
[EMAIL PROTECTED]
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/