diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2010-03-17 20:39:20 +0000 |
---|---|---|
committer | Martin Peach <mrpeach@users.sourceforge.net> | 2010-03-17 20:39:20 +0000 |
commit | 6609bc6fbd47b79162db053ae114bc2a791ab148 (patch) | |
tree | d9cc83afb42791ed82536e77f851e11c4893d238 | |
parent | ad24c79d3e072602c33c43000bbb8f523d334fb2 (diff) |
Checks that the port is open before writing to its buffer.
svn path=/trunk/externals/iem/comport/; revision=13221
-rw-r--r-- | comport/comport.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/comport/comport.c b/comport/comport.c index 6b35702..ca95403 100644 --- a/comport/comport.c +++ b/comport/comport.c @@ -1139,20 +1139,32 @@ endsendevent: static int write_serial(t_comport *x, unsigned char serial_byte) { - if(x->x_outbuf_wr_index < x->x_outbuf_len) + if(x->comhandle == INVALID_HANDLE_VALUE) + { + post ("[comport]: Serial port is not open"); + return 0; + } + else if(x->x_outbuf_wr_index < x->x_outbuf_len) { x->x_outbuf[x->x_outbuf_wr_index++] = serial_byte; return 1; } /* handle overrun error */ - else return 0; + post ("[comport]: buffer is full"); + return 0; } static int write_serials(t_comport *x, unsigned char *serial_buf, int buf_length) { int i; + if(x->comhandle == INVALID_HANDLE_VALUE) + { + post ("[comport]: Serial port is not open"); + return 0; + } for (i = 0; ((i < buf_length) && (x->x_outbuf_wr_index < x->x_outbuf_len)); ++x->x_outbuf_wr_index, ++i) x->x_outbuf[x->x_outbuf_wr_index] = serial_buf[i]; + if (i != buf_length) post ("[comport]: buffer is full"); return i; } |