From 08ae2446b2b50ec42cd8f59c2a76a1abb786cdea Mon Sep 17 00:00:00 2001 From: "kevin.larke" Date: Fri, 21 Feb 2020 15:39:03 -0500 Subject: [PATCH] cmSerialPort.h/c : Added cmSeSetCallback() and cmSeStart(). --- cmSerialPort.c | 29 +++++++++++++++++++++++------ cmSerialPort.h | 7 +++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cmSerialPort.c b/cmSerialPort.c index 35fb037..8f5093d 100644 --- a/cmSerialPort.c +++ b/cmSerialPort.c @@ -282,12 +282,6 @@ cmSeH_t cmSeCreate( cmCtx_t* ctx, cmSeH_t* hp, const char* deviceStr, unsigned b goto errLabel; } - if( cmThreadPause(p->_thH,0) != kOkThRC ) - { - rc = cmErrMsg(&p->_err,kThreadErrSeRC,0,"Thread start failed."); - goto errLabel; - } - if( hp != NULL ) hp->h = p; else @@ -321,6 +315,26 @@ cmSeRC_t cmSeDestroy(cmSeH_t* hp ) 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) { if( h.h == NULL ) @@ -542,6 +556,9 @@ cmSeRC_t cmSePortTest(cmCtx_t* ctx) h = cmSeCreate(ctx,&h,device,baud,serialCfgFlags,_cmSePortTestCb,NULL,pollPeriodMs); + if( cmSeIsOpen(h) ) + cmSeStart(h); + bool quitFl = false; printf("q=quit\n"); while(!quitFl) diff --git a/cmSerialPort.h b/cmSerialPort.h index 78a46f2..3ed5dc2 100644 --- a/cmSerialPort.h +++ b/cmSerialPort.h @@ -48,8 +48,11 @@ extern "C" { typedef cmHandle_t cmSeH_t; - 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 ); + 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 cmSeSetCallback( cmSeH_t h, cmSeCallbackFunc_t cbFunc, void* cbArg ); + cmSeRC_t cmSeStart( cmSeH_t h ); bool cmSeIsOpen( cmSeH_t h);