Browse Source

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

master
kevin.larke 4 years ago
parent
commit
08ae2446b2
2 changed files with 28 additions and 8 deletions
  1. 23
    6
      cmSerialPort.c
  2. 5
    2
      cmSerialPort.h

+ 23
- 6
cmSerialPort.c View File

@@ -282,12 +282,6 @@ cmSeH_t cmSeCreate( cmCtx_t* ctx, cmSeH_t* hp, const char* deviceStr, unsigned b
282 282
     goto errLabel;
283 283
   }
284 284
 
285
-  if( cmThreadPause(p->_thH,0) != kOkThRC )
286
-  {
287
-    rc = cmErrMsg(&p->_err,kThreadErrSeRC,0,"Thread start failed.");
288
-    goto errLabel;
289
-  }
290
-  
291 285
   if( hp != NULL )
292 286
     hp->h = p;
293 287
   else
@@ -321,6 +315,26 @@ cmSeRC_t cmSeDestroy(cmSeH_t* hp )
321 315
   return rc;
322 316
 }
323 317
 
318
+cmSeRC_t  cmSeSetCallback( cmSeH_t h, cmSeCallbackFunc_t cbFunc, void* cbArg  )
319
+{
320
+  cmSerialPort_t* p = _cmSePtrFromHandle(h);
321
+  p->_cbFunc  = cbFunc;
322
+  p->_cbArg   = cbArg;
323
+  return kOkSeRC;
324
+}
325
+
326
+cmSeRC_t  cmSeStart( cmSeH_t h )
327
+{
328
+  cmSerialPort_t* p = _cmSePtrFromHandle(h);
329
+  
330
+  if( cmThreadPause(p->_thH,0) != kOkThRC )
331
+    return cmErrMsg(&p->_err,kThreadErrSeRC,0,"Thread start failed.");
332
+  
333
+  return kOkSeRC;
334
+}
335
+
336
+
337
+
324 338
 bool cmSeIsOpen( cmSeH_t h)
325 339
 {
326 340
   if( h.h == NULL )
@@ -542,6 +556,9 @@ cmSeRC_t cmSePortTest(cmCtx_t* ctx)
542 556
   
543 557
   h = cmSeCreate(ctx,&h,device,baud,serialCfgFlags,_cmSePortTestCb,NULL,pollPeriodMs);
544 558
 
559
+  if( cmSeIsOpen(h) )
560
+    cmSeStart(h);
561
+
545 562
   bool quitFl = false;
546 563
   printf("q=quit\n");
547 564
   while(!quitFl)

+ 5
- 2
cmSerialPort.h View File

@@ -48,8 +48,11 @@ extern "C" {
48 48
 
49 49
   typedef cmHandle_t cmSeH_t;
50 50
     
51
-  cmSeH_t cmSeCreate( cmCtx_t* ctx, cmSeH_t* hp, const char* device, unsigned baudRate, unsigned cfgFlags, cmSeCallbackFunc_t cbFunc, void* cbArg, unsigned pollPeriodMs );
52
-  cmSeRC_t    cmSeDestroy(cmSeH_t* hp );
51
+  cmSeH_t   cmSeCreate( cmCtx_t* ctx, cmSeH_t* hp, const char* device, unsigned baudRate, unsigned cfgFlags, cmSeCallbackFunc_t cbFunc, void* cbArg, unsigned pollPeriodMs );
52
+  cmSeRC_t  cmSeDestroy(cmSeH_t* hp );
53
+
54
+  cmSeRC_t  cmSeSetCallback( cmSeH_t h, cmSeCallbackFunc_t cbFunc, void* cbArg  );
55
+  cmSeRC_t  cmSeStart( cmSeH_t h );
53 56
 
54 57
   bool cmSeIsOpen( cmSeH_t h);
55 58
     

Loading…
Cancel
Save