Hey Dom,

Looking at your code, I cannot immediately see what is wrong.  The only
issue I see is the use of MemMove.  I would recommend sending the data
across using the address of the data heap ptr (through DmQueryRecord and
MemHandleLock).  Also double check the return values from the SerSend
function to make sure that it is not failing.  I have not used these
funtions myself, but have a look at the SerSendWait() function to see if it
is not a help at all.

You can certainly optimise the code below by using DmQueryRecord instead,
and passing the actual memory pointer to the SerSend function.  This will
remove the need for the 1000 byte buffer (what if a record is bigger?), and
will reduce the need for the DmGetRecord function, which is slower than the
DmQueryRecord function (seeing that you have opened the database as read
only, there is no need to use DmGetRecord).  It will also remove the
MemCopy, which can also be slow.

As a test, try these changes first, and see if you get better results.  I
have attached the new code for you.  I have not compiled it, so there may be
errors ;)

Let me know if this helps.

Regards,
Brian Johnson

Senior Software Developer
E-Commerce
Siemens Business Services
+27 (11) 7097043 (w)
+27 (82) 8208325 (m)
+27 (11) 7097084 (f)
[EMAIL PROTECTED]

<<< ------------ Cut Here ------------ >>>

        UInt16  uiSerialPort;
        LocalID         DBID;
        DmOpenRef       DB;
        char            DBName[] = "001-VMB002-1";
        CharPtr pDatas;
        VoidHand        resH;
        CharPtr         resP;
        UInt16  uiPos = 0;
        UInt32  uiSize = 0;
        UInt32  nDataSent;
        UInt16 uiRecords;


        DBID    = DmFindDatabase(0, DBName);
        if (!DBID)
                return;
                
        DB = DmOpenDatabase(0, DBID, dmModeReadOnly);
        if (!DB || DmGetLastErr() != errNone) // DB does not exist
        {
                return;
        }

        uiRecords = DmNumRecords(DB);
        for (uiPos = 0; uiPos < uiRecords; uiPos++)
        {
                resH = DmQueryRecord(DB, uiPos);
                uiSize = MemHandleSize(resH);

                resP = MemHandleLock(resH);

                SerReceiveFlush(m_uiSerialPortId, 0);
                nDataSent = SerSend(m_uiSerialPortId, resP, uiSize, &err);
                
                if (err != 0 || nDataSent != uiSize)
                {
                        // TODO: Alert the user of the fail... Use
SysErrString to format the error 
                        // to a user readable error
                        MemHandleUnlock(resH);
                        break;
                }
                
                MemHandleUnlock(resH);
        }//end for

<<< ------------ Cut Here ------------ >>>

-----Original Message-----
From: Dominique Martel [mailto:[EMAIL PROTECTED]] 
Sent: 13 August 2002 16:31
To: Palm Developer Forum
Subject: error with reading database


Hi all,

I have a problem with reading a database (PDB file) on a Palm and sending
these datas from the Palm to a device on the serial port. I included part of
the code below. More precisely, what happens is that I read the records of a
database on the Palm, and I send the datas on the serial port. 

To find me problem I opened HyperTerminal and I captured the text. What I
found is that all the datas are sent and captured, but some datas are copied
twice. For example, at positions 0x9B, 0x9C, 0x9D, I'm supposed to have the
following datas: 0x18, 0x70, 0xE0, but, I have 0x18, 0x70, 0x70, 0xE0.

As you can see below, datas are copied from variable resP to pDatas. I
verified with the debugger and the datas are ok, there are no datas copied
twice. The for loop is to read all the records (there are 387 records). The
MemHandleNew(1000) is to allow 1000 bytes of memory (each record is 1000
bytes). 

Would anyone have any advice?

Thank you!

Dominique Martel


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to