hi,
i have got a little problem with serial manager. I want to pass some records 
from pc to palm. I read that process should be immediate (read and store)  
but in this case i need process them before storing in database.
As i am receiving 5 k of data, i am using my own buffer. The code failed 
showing some errors, i.e., serLineErrorSWOverrun, but i resolved it using a 
bigger buffer. Now, the size of the buffer is 2.5 k.
The problem is that now there is not errors (I am debugging program with 
messages and i do not get errors), but program is hanging about 75 th 
record. I have tried changing my program but the result is the same because 
I am getting 60-80 records.
In these tests I have seen that SerReceive does not extract bytes from 
buffer, only reads them. Is this correct? I thought that SerReceive was as 
Visual Basic "input" command. Perhaps this is the problem and I  want to 
know if SerReceive is working fine.
I put a buffer of 10 k too, but result was the same one.


Just in case, this is code I am using:
/* Now, I read twice: at first time I read register's size (always 2 bytes) 
and then I read the register with this size.


void RecibirLocalizacion(DmOpenRef *dbp)
{
        ULong   baud=9600;
        UInt    port=0;
        static UInt     refno;
        Boolean bTratar=false;
        Err             error;
        UInt sec=0;
        Err err;
        char *gSerialBuffer;
        ULong numBytes=0;
        CharPtr inp4;
        CharPtr inp5;
        int numB=0;
        Word errFlags;

        sec=SysSetAutoOffTime(0);
        error=SysLibFind("Serial Library",&refno);
        if (!error)
        {
                error=SerOpen(refno,port,baud);
                if (error!=0){
                        if (error==serErrAlreadyOpen)
                                SerClose(refno);

                        FrmCustomAlert(ErrorLibreriaAlert,NULL,NULL,NULL);
                }
                else{
                        gSerialBuffer = MemPtrNew(2560);
                        if (!gSerialBuffer)
                                FrmCustomAlert(ErrorRecibirAlert,"0",NULL,NULL);
                        else
                        {
                                SerSetReceiveBuffer(refno,gSerialBuffer,2560);
                                SerReceiveFlush(refno,0);
                                inp4=MemPtrNew(3);
                                inp5=MemPtrNew(sizeof(Localizacion));
                                do
                                {
                                        inp4[0]='\0';
                                        numBytes=0;
                                        error=0;
                                        error=SerReceiveCheck(refno,&numBytes);
                                        if (error!=0)
                                        {
                                                errFlags=SerGetStatus(refno,NULL,NULL);
                                                switch (errFlags)
                                                {
                                                        case serLineErrorParity:
                                                                
FrmCustomAlert(ErrorRecibirAlert,"1A",NULL,NULL);
                                                                break;
                                                        case serLineErrorHWOverrun:
                                                                
FrmCustomAlert(ErrorRecibirAlert,"1B",NULL,NULL);
                                                                break;

                                                        case serLineErrorFraming:
                                                                
FrmCustomAlert(ErrorRecibirAlert,"1C",NULL,NULL);
                                                                break;

                                                        case serLineErrorBreak:
                                                                
FrmCustomAlert(ErrorRecibirAlert,"1D",NULL,NULL);
                                                                break;

                                                        case serLineErrorHShake:
                                                                
FrmCustomAlert(ErrorRecibirAlert,"1E",NULL,NULL);
                                                                break;

                                                        case serLineErrorSWOverrun:
                                                                
FrmCustomAlert(ErrorRecibirAlert,"1F",NULL,NULL);
                                                                break;


                                                }
                                                SerReceiveFlush(refno,0);
                                                
FrmCustomAlert(ErrorRecibirAlert,"1",NULL,NULL);
                                                continue;
                                        }

                                        if (numBytes<2){
                                                error=SerReceiveWait(refno,2,-1);
                                                if (error!=0){
                                                        SerClearErr(refno);
                                                        
FrmCustomAlert(ErrorRecibirAlert,"2",NULL,NULL);
                                                        continue;
                                                }
                                        }

                                        SerReceive(refno,inp4,2,0,&error);
                                        if (error!=0){
                                                SerClearErr(refno);
                                                
FrmCustomAlert(ErrorRecibirAlert,"3",NULL,NULL);
                                                continue;
                                        }
                                        inp4[2]='\0';
                                        numB=StrAToI(inp4);
                                        error=SerReceiveCheck(refno,&numBytes);
                                        if (error!=0){
                                                SerClearErr(refno);
                                                
FrmCustomAlert(ErrorRecibirAlert,"4",NULL,NULL);
                                                continue;
                                        }

                                        if (numBytes<numB){
                                                error=SerReceiveWait(refno,numB,-1);
                                                if (error!=0){
                                                        SerClearErr(refno);
                                                        
FrmCustomAlert(ErrorRecibirAlert,"5",NULL,NULL);
                                                        continue;
                                                }
                                        }

                                        if (!inp5)
                                                inp5=MemPtrNew(sizeof(Localizacion));


                                        inp5[0]='\0';
                                        SerReceive(refno,inp5,numB,0,&error);
                                        if (error!=0)
                                        {
                                                        SerClearErr(refno);
                                                        
FrmCustomAlert(ErrorRecibirAlert,"6",NULL,NULL);
                                                        continue;
                                        }
                                        inp5[numB+1]='\0';
                                        
bTratar=InsertarLocalizacion(dbp,inp5);//function where i process 
register
                                        iBuffer2=iBuffer2 + numB + 2;
                                        if (inp5)
                                        {
                                                MemPtrFree(inp5);
                                                inp5=NULL;
                                        }

                                } while (!bTratar);

                                if (inp4){
                                        MemPtrFree(inp4);
                                        inp4=NULL;
                                }

                                if (error!=0){
                                        SerReceiveFlush(refno,-1);
                                        
FrmCustomAlert(ErrorRecibirAlert,NULL,NULL,NULL);
                                }

                        }

                        SerSetReceiveBuffer(refno,NULL,0);
                        if (gSerialBuffer)
                        {
                                MemPtrFree(gSerialBuffer);
                                gSerialBuffer=NULL;
                        }
                        SerReceiveFlush(refno,0);
                        SerClose(refno);
                }
        }
        SysSetAutoOffTime(sec);
        err=EvtResetAutoOffTimer();
}


thanks a lot for advance.

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


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

Reply via email to