aboutsummaryrefslogtreecommitdiff
path: root/comport
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2006-10-16 21:30:29 +0000
committerMartin Peach <mrpeach@users.sourceforge.net>2006-10-16 21:30:29 +0000
commit1377d5dcf550a787e266730253c411f1d390d930 (patch)
treeb933e42f6b2099f65e0e40c7a8c974592eaf3489 /comport
parent8aae01449111e8a0b54f0da1a323dc96d1c786a7 (diff)
write_serial:
Windows version checks GetOverlappedResult to avoid Tx overruns CVSCVS: Committing in . svn path=/trunk/externals/iem/comport/; revision=6117
Diffstat (limited to 'comport')
-rw-r--r--comport/comport.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/comport/comport.c b/comport/comport.c
index ee267ec..0aabdf9 100644
--- a/comport/comport.c
+++ b/comport/comport.c
@@ -13,6 +13,7 @@ MP 20060709 All status goes out the status outlet when an info message is receiv
MP 20060824 added clock_delay call in comport_devicename
MP 20060924 added comport_enum to list available ports in Windows
MP 20060925 add devices message to enumerate actual devices, info just outputs current port state
+MP 20061016 write_serial checks for GetOverlappedResult to avoid tx buffer overflow errors
*/
#include "m_pd.h"
@@ -495,7 +496,7 @@ static HANDLE open_serial(unsigned int com_num, t_comport *x)
if (!GetCommTimeouts(fd, &(x->old_timeouts)))
{
- post("[comport] Couldn't get old timeouts for serial device");
+ post("[comport] Couldn't get old timeouts for serial device (%d)", GetLastError());
}
/* setting new timeouts for read to immediately return */
@@ -507,10 +508,14 @@ static HANDLE open_serial(unsigned int com_num, t_comport *x)
if (!SetCommTimeouts(fd, &timeouts))
{
- post("Couldn't set timeouts for serial device");
+ post("Couldn't set timeouts for serial device (%d)", GetLastError());
return INVALID_HANDLE_VALUE;
}
-
+ if (!SetupComm(x->comhandle, 4096L, 4096L))/* try to get big buffers to avoid overruns*/
+ {
+ post("[comport] Couldn't do SetupComm (%d)", GetLastError());
+ }
+
x->comport = com_num;/* output on next tick */
return fd;
}
@@ -539,9 +544,9 @@ static int write_serial(t_comport *x, unsigned char serial_byte)
{
OVERLAPPED osWrite = {0};
DWORD dwWritten;
- DWORD dwToWrite = 1;
+ DWORD dwToWrite = 1L;
DWORD dwErr;
- char cErr[100];
+ DWORD numTransferred = 0L;
osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (osWrite.hEvent == NULL)
@@ -555,11 +560,15 @@ static int write_serial(t_comport *x, unsigned char serial_byte)
dwErr = GetLastError();
if (dwErr != ERROR_IO_PENDING)
{
- sprintf(cErr, "WriteFile error: %d", (int)dwErr);
- post(cErr);
+ post("WriteFile error: %d", (int)dwErr);
return 0;
}
}
+ if (!GetOverlappedResult(x->comhandle, &osWrite, &numTransferred, TRUE))
+ {/* wait for the character to be sent */
+ dwErr = GetLastError();
+ post("WriteFile:GetOverlappedResult error: %d", (int)dwErr);
+ }
CloseHandle(osWrite.hEvent);
return 1;
}