Commit 3f90a544 authored by rswindell's avatar rswindell
Browse files

Added optional terminator character to comReadBuf().

parent 3bbcef92
...@@ -79,7 +79,8 @@ BOOL comWriteByte(COM_HANDLE, BYTE); ...@@ -79,7 +79,8 @@ BOOL comWriteByte(COM_HANDLE, BYTE);
int comWriteBuf(COM_HANDLE, const BYTE*, size_t buflen); int comWriteBuf(COM_HANDLE, const BYTE*, size_t buflen);
int comWriteString(COM_HANDLE, const char*); int comWriteString(COM_HANDLE, const char*);
BOOL comReadByte(COM_HANDLE, BYTE*); BOOL comReadByte(COM_HANDLE, BYTE*);
size_t comReadBuf(COM_HANDLE, char* buf, size_t buflen, int timeout /* in milliseconds */); size_t comReadBuf(COM_HANDLE, char* buf, size_t buflen
,char terminator, int timeout /* in milliseconds */);
BOOL comPurgeInput(COM_HANDLE); BOOL comPurgeInput(COM_HANDLE);
BOOL comPurgeOutput(COM_HANDLE); BOOL comPurgeOutput(COM_HANDLE);
......
...@@ -150,7 +150,7 @@ BOOL comReadByte(COM_HANDLE handle, BYTE* ch) ...@@ -150,7 +150,7 @@ BOOL comReadByte(COM_HANDLE handle, BYTE* ch)
return ReadFile(handle, ch, sizeof(BYTE), &rd, NULL) && rd==sizeof(BYTE); return ReadFile(handle, ch, sizeof(BYTE), &rd, NULL) && rd==sizeof(BYTE);
} }
size_t comReadBuf(COM_HANDLE handle, char* buf, size_t buflen, int timeout) size_t comReadBuf(COM_HANDLE handle, char* buf, size_t buflen, char terminator, int timeout)
{ {
BYTE ch; BYTE ch;
size_t len=0; size_t len=0;
...@@ -163,6 +163,8 @@ size_t comReadBuf(COM_HANDLE handle, char* buf, size_t buflen, int timeout) ...@@ -163,6 +163,8 @@ size_t comReadBuf(COM_HANDLE handle, char* buf, size_t buflen, int timeout)
YIELD(); YIELD();
continue; continue;
} }
if(len && terminator && ch==terminator)
break;
buf[len++]=ch; buf[len++]=ch;
} }
...@@ -178,3 +180,4 @@ BOOL comPurgeOutput(COM_HANDLE handle) ...@@ -178,3 +180,4 @@ BOOL comPurgeOutput(COM_HANDLE handle)
{ {
return PurgeComm(handle, PURGE_TXCLEAR); return PurgeComm(handle, PURGE_TXCLEAR);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment