Hi All,
I am using serial manager but i am facing a problem regarding loopback. I
want to run a small program in emulator. But i am getting nothing on the
receiving side.
Can anyone help me?
After going through forums and knowledge base, i understood that usinf
serial manager and ir we can send data without using any cable or
intermediate device. Am i correct? If so, please tell me how to go about it.
For this i am using following functions -
OpenSerial() // to open a serial connection. here i specify for
loopback in SrmControl
WriteSerial() // to write to the port
ReadSerial() // to receive the data
static Err OpenSerial()
{
Err error;
UInt32 value;
UInt32 flags =0;
UInt16 flagsSize = sizeof(flags);
error = FtrGet(sysFileCSerialMgr,sysFtrNewSerialPresent,&value);
if(value == 0)
FrmCustomAlert(DummyAlert,"new serial manager","","");
else
{
error = SrmControl(gPortID,srmCtlStartLocalLoopback,NULL,0); // for
loopback
error = SrmOpen('ircm' ,9600,&gPortID);
ErrNonFatalDisplayIf(error == serErrBadPort,"serErrBadport");
switch(error)
{
case errNone:
break;
case serErrAlreadyOpen:
SrmClose(gPortID);
FrmCustomAlert(DummyAlert,"serial manager busy","","");
return error;
break;
default:
FrmCustomAlert(DummyAlert,"serial manager open","","");
return error;
break;
}
g_connected = true;
SrmReceiveFlush(gPortID,100);
return error;
}
return error;
}
static void WriteSerial()
{
Err error;
Char *text;
UInt16 s1;
Char linefeed = chrLineFeed;
if(g_connected == false) return;
text = MemPtrNew(30);
StrCopy(text,"12345678");
s1 = SrmSend(gPortID,text,StrLen(text),&error);
SrmControl(gPortID, srmCtlStartLocalLoopback, NULL, 0);
SrmControl(gPortID, srmCtlRxEnable, 0, 0 );
if(error)
FrmCustomAlert(DummyAlert,"error in sending data","","");
SrmSend(gPortID,&linefeed,1,&error);
if(error)
FrmCustomAlert(DummyAlert,"error in sending data","","");
}
static void ReadSerial()
{
static Char buffer[50];
static UInt16 index =0;
Err error;
UInt32 bytes=0;
Char *msg;
if(g_connected == false)
return;
SrmControl(gPortID, srmCtlRxEnable, NULL, 0);
SrmControl(gPortID,srmCtlStartLocalLoopback, NULL, 0);
error =SrmReceiveCheck(gPortID,&bytes);
if(error)
{
FrmCustomAlert(DummyAlert,"error in receiving","","");
return;
}
MemSet(buffer,50,0);
if(bytes + index > sizeof(buffer))
bytes = sizeof(buffer) - index - sizeOf7BitChar('\0');
while(bytes)
{
SrmReceive(gPortID,&buffer[index],1,0,&error);
if(error)
{
SrmReceiveFlush(gPortID,1);
index =0;
return;
}
switch(buffer[index])
{
case chrCarriageReturn:
buffer[index] = chrLineFeed;
case chrLineFeed:
buffer[index+1] = chrNull;
FrmCustomAlert(DummyAlert,buffer,"","");
index =0;
break;
default:
index++;
break;
}
bytes--;
}
}
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/