cmSerialPort.h/c : Added cmSeSetCallback() and cmSeStart().

This commit is contained in:
kevin.larke 2020-02-21 15:39:03 -05:00
parent 18b815d387
commit 08ae2446b2
2 changed files with 28 additions and 8 deletions

View File

@ -282,12 +282,6 @@ cmSeH_t cmSeCreate( cmCtx_t* ctx, cmSeH_t* hp, const char* deviceStr, unsigned b
goto errLabel; goto errLabel;
} }
if( cmThreadPause(p->_thH,0) != kOkThRC )
{
rc = cmErrMsg(&p->_err,kThreadErrSeRC,0,"Thread start failed.");
goto errLabel;
}
if( hp != NULL ) if( hp != NULL )
hp->h = p; hp->h = p;
else else
@ -321,6 +315,26 @@ cmSeRC_t cmSeDestroy(cmSeH_t* hp )
return rc; return rc;
} }
cmSeRC_t cmSeSetCallback( cmSeH_t h, cmSeCallbackFunc_t cbFunc, void* cbArg )
{
cmSerialPort_t* p = _cmSePtrFromHandle(h);
p->_cbFunc = cbFunc;
p->_cbArg = cbArg;
return kOkSeRC;
}
cmSeRC_t cmSeStart( cmSeH_t h )
{
cmSerialPort_t* p = _cmSePtrFromHandle(h);
if( cmThreadPause(p->_thH,0) != kOkThRC )
return cmErrMsg(&p->_err,kThreadErrSeRC,0,"Thread start failed.");
return kOkSeRC;
}
bool cmSeIsOpen( cmSeH_t h) bool cmSeIsOpen( cmSeH_t h)
{ {
if( h.h == NULL ) if( h.h == NULL )
@ -542,6 +556,9 @@ cmSeRC_t cmSePortTest(cmCtx_t* ctx)
h = cmSeCreate(ctx,&h,device,baud,serialCfgFlags,_cmSePortTestCb,NULL,pollPeriodMs); h = cmSeCreate(ctx,&h,device,baud,serialCfgFlags,_cmSePortTestCb,NULL,pollPeriodMs);
if( cmSeIsOpen(h) )
cmSeStart(h);
bool quitFl = false; bool quitFl = false;
printf("q=quit\n"); printf("q=quit\n");
while(!quitFl) while(!quitFl)

View File

@ -51,6 +51,9 @@ extern "C" {
cmSeH_t cmSeCreate( cmCtx_t* ctx, cmSeH_t* hp, const char* device, unsigned baudRate, unsigned cfgFlags, cmSeCallbackFunc_t cbFunc, void* cbArg, unsigned pollPeriodMs ); cmSeH_t cmSeCreate( cmCtx_t* ctx, cmSeH_t* hp, const char* device, unsigned baudRate, unsigned cfgFlags, cmSeCallbackFunc_t cbFunc, void* cbArg, unsigned pollPeriodMs );
cmSeRC_t cmSeDestroy(cmSeH_t* hp ); cmSeRC_t cmSeDestroy(cmSeH_t* hp );
cmSeRC_t cmSeSetCallback( cmSeH_t h, cmSeCallbackFunc_t cbFunc, void* cbArg );
cmSeRC_t cmSeStart( cmSeH_t h );
bool cmSeIsOpen( cmSeH_t h); bool cmSeIsOpen( cmSeH_t h);
cmSeRC_t cmSeSend( cmSeH_t h, const void* byteA, unsigned byteN ); cmSeRC_t cmSeSend( cmSeH_t h, const void* byteA, unsigned byteN );