From 6609bc6fbd47b79162db053ae114bc2a791ab148 Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Wed, 17 Mar 2010 20:39:20 +0000 Subject: Checks that the port is open before writing to its buffer. svn path=/trunk/externals/iem/comport/; revision=13221 --- comport/comport.c | 16 ++++++++++++++-- 1 file 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; } -- cgit v1.2.1