From bdefcbe8acf9791856b28f2bef02e7eb4c40aecf Mon Sep 17 00:00:00 2001 From: borutr Date: Fri, 13 Apr 2007 19:52:07 +0000 Subject: [PATCH] * device/examples/serialcomm/windows/serial.[ch], device/examples/serialcomm/windows/test_serialcomm.cpp: updated by Bela Torok * device/examples/serialcomm/windows/serialcomm.dsw, device/examples/serialcomm/windows/serialcomm.dsp: added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4747 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 5 + device/examples/serialcomm/windows/serial.c | 280 ++++++++++++++++++ device/examples/serialcomm/windows/serial.cpp | 149 ---------- device/examples/serialcomm/windows/serial.h | 34 +-- .../serialcomm/windows/serialcomm.dsp | 105 +++++++ .../serialcomm/windows/serialcomm.dsw | 29 ++ .../serialcomm/windows/test_serialcomm.cpp | 8 +- 7 files changed, 439 insertions(+), 171 deletions(-) create mode 100755 device/examples/serialcomm/windows/serial.c delete mode 100755 device/examples/serialcomm/windows/serial.cpp create mode 100644 device/examples/serialcomm/windows/serialcomm.dsp create mode 100644 device/examples/serialcomm/windows/serialcomm.dsw diff --git a/ChangeLog b/ChangeLog index f3dd1f4f..f5372fc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,11 @@ * doc/sdccman.lyx: -pedantic-parse-number is not in conformance with C99 standard + * device/examples/serialcomm/windows/serial.[ch], + device/examples/serialcomm/windows/test_serialcomm.cpp: + updated by Bela Torok + * device/examples/serialcomm/windows/serialcomm.dsw, + device/examples/serialcomm/windows/serialcomm.dsp: added 2007-04-13 Jan Waclawek diff --git a/device/examples/serialcomm/windows/serial.c b/device/examples/serialcomm/windows/serial.c new file mode 100755 index 00000000..b42338de --- /dev/null +++ b/device/examples/serialcomm/windows/serial.c @@ -0,0 +1,280 @@ +/*------------------------------------------------------------------------- + Serial library functions for the Windows OS (95-XP) + Tested with different versions of MS Visual Studio (C ad C++) + + Written by - Bela Torok / www.torok.info & www.belatorok.com (February 2006) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License (http://www.gnu.org/licenses/gpl.txt). + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ + +#include +#include + +#include "serial.h" +#define ASCII_XON 0x11 +#define ASCII_XOFF 0x13 + +HANDLE SerialInit(char *ComPortName, DWORD BaudRate, int ByteSize, int StopBit, char ParityChar, char Protocol, int RxTimeOut, int TxTimeOut, int RxBufSize, int TxBufSize) +{ + HANDLE hCom; + BOOL bPortReady; + DCB dcb; + COMMTIMEOUTS CommTimeouts; + int Parity; + + switch(ParityChar) { + case 'N': + case 'n': + Parity = NOPARITY; + break; + case 'E': + case 'e': + Parity = EVENPARITY; + break; + case 'O': + case 'o': + Parity = ODDPARITY; + break; + default: + return NULL; // illegal parameter ! + } + + switch(StopBit) + { + case 1: + StopBit = ONESTOPBIT; + break; + case 2: + StopBit = TWOSTOPBITS; + break; + default: + return NULL; // illegal parameter ! + } + + hCom = CreateFile( ComPortName, + GENERIC_READ | GENERIC_WRITE, + 0, // exclusive access + NULL, // no security + OPEN_EXISTING, + 0, // no overlapped I/O + NULL); // null template + + if(hCom == INVALID_HANDLE_VALUE) return NULL; + + bPortReady = SetupComm(hCom, RxBufSize, TxBufSize); // set Rx and Tx buffer sizes + + // Port settings are specified in a Data Communication Block (DCB). + + bPortReady = GetCommState(hCom, &dcb); + + dcb.BaudRate = BaudRate; + dcb.ByteSize = ByteSize; + dcb.Parity = Parity; + dcb.StopBits = StopBit; + dcb.fAbortOnError = TRUE; + + switch(Protocol) { + case 'D': // DTR/DSR + case 'd': + // set XON/XOFF + dcb.fOutX = FALSE; + dcb.fInX = FALSE; + // set RTSCTS + dcb.fOutxCtsFlow = FALSE; + dcb.fRtsControl = RTS_CONTROL_DISABLE; + // set DSRDTR + dcb.fOutxDsrFlow = TRUE; + dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; + break; + case 'R': // RTS/CTS + case 'r': + // set XON/XOFF + dcb.fOutX = FALSE; + dcb.fInX = FALSE; + // set RTSCTS + dcb.fOutxCtsFlow = TRUE; + dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; + // set DSRDTR + dcb.fOutxDsrFlow = FALSE; + dcb.fDtrControl = DTR_CONTROL_DISABLE; + break; + case 'X': // XON/XOFF + case 'x': + // set XON/XOFF + dcb.fOutX = TRUE; + dcb.fInX = TRUE; + dcb.fTXContinueOnXoff = TRUE; + dcb.XoffChar = ASCII_XOFF; + dcb.XoffLim = RxBufSize - (RxBufSize / 4); + dcb.XonChar = ASCII_XON; + dcb.XonLim = RxBufSize - (RxBufSize / 2); + // set RTSCTS + dcb.fOutxCtsFlow = FALSE; + dcb.fRtsControl = RTS_CONTROL_DISABLE; + // set DSRDTR + dcb.fOutxDsrFlow = FALSE; + dcb.fDtrControl = DTR_CONTROL_DISABLE; + break; + case 'N': // NOPROTOCOL + case 'n': + default: + // set XON/XOFF + dcb.fOutX = FALSE; + dcb.fInX = FALSE; + // set RTSCTS + dcb.fOutxCtsFlow = FALSE; + dcb.fRtsControl = RTS_CONTROL_DISABLE; + // set DSRDTR + dcb.fOutxDsrFlow = FALSE; + dcb.fDtrControl = DTR_CONTROL_DISABLE; + break; + } + + bPortReady = SetCommState(hCom, &dcb); + + // Set timeouts + CommTimeouts.ReadIntervalTimeout = RxTimeOut; + CommTimeouts.ReadTotalTimeoutMultiplier = 0; + CommTimeouts.ReadTotalTimeoutConstant = RxTimeOut; + + CommTimeouts.WriteTotalTimeoutMultiplier = 0; + CommTimeouts.WriteTotalTimeoutConstant = TxTimeOut; + + bPortReady = SetCommTimeouts(hCom, &CommTimeouts); + + return hCom; +} + +void SerialClose(HANDLE hSerial) { + CloseHandle(hSerial); +} + +int SerialGetc(HANDLE hSerial) +{ + unsigned char rxchar; + BOOL bReadRC; + static DWORD iBytesRead, dwError; + + if(hSerial == NULL) return 0; + + bReadRC = ReadFile(hSerial, &rxchar, 1, &iBytesRead, NULL); + + if(bReadRC == FALSE) { // error + + ClearCommError(hSerial, &dwError, NULL); + +// PurgeComm(hSerial, PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR); +// PurgeComm(hSerial, PURGE_RXCLEAR | PURGE_TXCLEAR); + + if(dwError == 0) return TIMEOUT; // no error, iBytesRead is probably == 0 + if(dwError & CE_BREAK) return BREAK; // break detected + if(dwError & CE_FRAME) return BREAK; // framing error + + /* One, or a combination of the following conditions: + CE_IOE -> 0x0400 I/O error during communication with the device + CE_OVERRUN -> 0x0002 character-buffer overrun, the next character is lost + CE_RXOVER -> 0x0001 input buffer overflow, no room in the input buffer, + or a character was received after the EOF character + CE_RXPARITY -> 0x0004 parity error + CE_TXFULL -> 0x0100 transmit buffer is full + */ + if(dwError & CE_IOE) printf("SerialGetc() I/O error during communication with the device!\n"); + if(dwError & CE_OVERRUN) printf("SerialGetc() Character-buffer overrun, the next character is lost!\n"); + if(dwError & CE_RXOVER) printf("SerialGetc() Input buffer overflow!\n"); + if(dwError & CE_RXPARITY) printf("SerialGetc() Parity error!\n"); + if(dwError & CE_TXFULL) printf("SerialGetc() Transmit buffer is full!\n"); + return SERIAL_ERROR; + } + + if(iBytesRead == 0) return TIMEOUT; // Timeout occured + + return (int) rxchar; +} + + +int SerialPutc(HANDLE hCom, char txchar) +{ + BOOL bWriteRC; + static DWORD iBytesWritten; + + if(hCom == NULL) return -255; + + bWriteRC = WriteFile(hCom, &txchar, 1, &iBytesWritten,NULL); + + if(iBytesWritten = 1) return 0; + + return TIMEOUT; +} + +char SerialGets(char *rxstring, int MaxNumberOfCharsToRead, HANDLE hCom) +{ + int c; + int pos = 0; + unsigned char success = 0; // set to error + + if(hCom == NULL) return success; // Error! + + while(pos <= MaxNumberOfCharsToRead) { + c = SerialGetc(hCom); + + if(c == TIMEOUT) return success; // Error + if(c == '\n') break; + if(c != '\r') rxstring[pos++] = (char) c; // discard carriage return + } + rxstring[pos] = 0; + + success = 1; + + return success; // No errors +} + +void SerialPuts(HANDLE hCom, char *txstring) +{ + BOOL bWriteRC; + static DWORD iBytesWritten; + + if(hCom == NULL) return; + + bWriteRC = WriteFile(hCom, txstring, (DWORD) strlen(txstring), &iBytesWritten,NULL); +} + +int SerialGetModemStatus(HANDLE hCom, int Mask) +{ +// The value for Mask must be one of the following definitions: +// MS_CTS_ON +// MS_DSR_ON +// MS_RING_ON + int ModemStat; + + GetCommModemStatus(hCom, &ModemStat); + + switch( Mask ) { + case MS_CTS_ON: + case MS_DSR_ON: + case MS_RING_ON: + if((ModemStat & Mask) != 0) { + return 1; + } else { + return 0; + } + default: + return -1; + } +} + +void SerialClearRxBuffer(HANDLE hCom) +{ + PurgeComm(hCom, PURGE_RXCLEAR); +} diff --git a/device/examples/serialcomm/windows/serial.cpp b/device/examples/serialcomm/windows/serial.cpp deleted file mode 100755 index 7b319af4..00000000 --- a/device/examples/serialcomm/windows/serial.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// Elementary functions for for serial communication for Visual C / MFC -// Bela Torok / bela.torok@kssg.ch, March 2001 - -// This version is using the CTS/RTS protocol only, with 8 databits + no parity. -// This file was tested with ser_ir_cts_rts.c (in device/lib) - -// Todo: Imporve the function SerialInit to support communication with no_protocol & XON/XOFF protocol, -// 7 databits, even & odd parity, 1, 1.5 & 2 stopbits, etc... - -#include -#include - -//#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers - -#include // serial.cpp : Defines the entry point for the console application. - -//#include "stdafx.h" -#include - -#include "serial.h" - -// Flow control flags - -#define FC_DTRDSR 0x01 -#define FC_RTSCTS 0x02 -#define FC_XONXOFF 0x04 - -// ascii definitions - -#define ASCII_BEL 0x07 -#define ASCII_BS 0x08 -#define ASCII_LF 0x0A -#define ASCII_CR 0x0D -#define ASCII_XON 0x11 -#define ASCII_XOFF 0x13 - - // variables used with the com port - BOOL bPortReady; - DCB dcb; - COMMTIMEOUTS CommTimeouts; - BOOL bWriteRC; - BOOL bReadRC; - DWORD iBytesWritten; - DWORD iBytesRead; - -HANDLE SerialInit(char *ComPortName, int BaudRate) -{ - HANDLE hCom; - - hCom = CreateFile(ComPortName, - GENERIC_READ | GENERIC_WRITE, - 0, // exclusive access - NULL, // no security - OPEN_EXISTING, - 0, // no overlapped I/O - NULL); // null template - - bPortReady = SetupComm(hCom, 2, 128); // set buffer sizes - - - bPortReady = GetCommState(hCom, &dcb); - dcb.BaudRate = BaudRate; - dcb.ByteSize = 8; - dcb.Parity = NOPARITY; -// dcb.Parity = EVENPARITY; - dcb.StopBits = ONESTOPBIT; - dcb.fAbortOnError = TRUE; - - // set XON/XOFF - dcb.fOutX = FALSE; // XON/XOFF off for transmit - dcb.fInX = FALSE; // XON/XOFF off for receive - // set RTSCTS - dcb.fOutxCtsFlow = TRUE; // turn on CTS flow control - dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; // - // set DSRDTR - dcb.fOutxDsrFlow = FALSE; // turn on DSR flow control - dcb.fDtrControl = DTR_CONTROL_ENABLE; // -// dcb.fDtrControl = DTR_CONTROL_DISABLE; // -// dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; // - - bPortReady = SetCommState(hCom, &dcb); - - // Communication timeouts are optional - - bPortReady = GetCommTimeouts (hCom, &CommTimeouts); - - CommTimeouts.ReadIntervalTimeout = 5000; - CommTimeouts.ReadTotalTimeoutConstant = 5000; - CommTimeouts.ReadTotalTimeoutMultiplier = 1000; - CommTimeouts.WriteTotalTimeoutConstant = 5000; - CommTimeouts.WriteTotalTimeoutMultiplier = 1000; - - bPortReady = SetCommTimeouts (hCom, &CommTimeouts); - - return hCom; -} - -char SerialGetc(HANDLE *hCom) -{ - char rxchar; - BOOL bReadRC; - static DWORD iBytesRead; - - bReadRC = ReadFile(*hCom, &rxchar, 1, &iBytesRead, NULL); - - return rxchar; -} - -void SerialPutc(HANDLE *hCom, char txchar) -{ - BOOL bWriteRC; - static DWORD iBytesWritten; - - bWriteRC = WriteFile(*hCom, &txchar, 1, &iBytesWritten,NULL); -} - -char* SerialGets(HANDLE *hCom) -{ - static char rxstring[256]; - char c; - int pos = 0; - - while(pos <= 255) { - c = SerialGetc(hCom); - if(c == '\r') continue; // discard carriage return - rxstring[pos++] = c; - if(c == '\n') break; - } - rxstring[pos] = 0; - - return rxstring; -} - -void SerialPuts(HANDLE *hCom, char *txstring) -{ - BOOL bWriteRC; - static DWORD iBytesWritten; - - bWriteRC = WriteFile(*hCom, txstring, strlen(txstring), &iBytesWritten,NULL); - -} - -void sleep( int _wait) -{ - clock_t goal; - goal = clock() + _wait; - while( goal > clock() ); -} - diff --git a/device/examples/serialcomm/windows/serial.h b/device/examples/serialcomm/windows/serial.h index e939554d..c33d4f12 100755 --- a/device/examples/serialcomm/windows/serial.h +++ b/device/examples/serialcomm/windows/serial.h @@ -1,27 +1,27 @@ -// Flow control flags +#define TIMEOUT -1 +#define SERIAL_ERROR -8 +#define BREAK -16 -#define FC_DTRDSR 0x01 -#define FC_RTSCTS 0x02 -#define FC_XONXOFF 0x04 +#ifdef __cplusplus +extern "C" { +#endif -// ascii definitions +HANDLE SerialInit(char*, DWORD, int, int, char, char, int, int, int, int); -#define ASCII_BEL 0x07 -#define ASCII_BS 0x08 -#define ASCII_LF 0x0A -#define ASCII_CR 0x0D -#define ASCII_XON 0x11 -#define ASCII_XOFF 0x13 +int SerialGetc(HANDLE); +int SerialPutc(HANDLE, char); -HANDLE SerialInit(char*, int); +char SerialGets(char*, int, HANDLE); -char SerialGetc(HANDLE*); +void SerialPuts(HANDLE, char*); -void SerialPutc(HANDLE*, char); +int SerialGetModemStatus(HANDLE, int); -char* SerialGets(HANDLE*); +void SerialClearRxBuffer(HANDLE); -void SerialPuts(HANDLE*, char*); +void SerialClose(HANDLE); -void sleep(int); +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/device/examples/serialcomm/windows/serialcomm.dsp b/device/examples/serialcomm/windows/serialcomm.dsp new file mode 100644 index 00000000..457effda --- /dev/null +++ b/device/examples/serialcomm/windows/serialcomm.dsp @@ -0,0 +1,105 @@ +# Microsoft Developer Studio Project File - Name="serialcomm" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=serialcomm - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "serialcomm.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "serialcomm.mak" CFG="serialcomm - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "serialcomm - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "serialcomm - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "serialcomm - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "serialcomm - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo /o"Debug/test_serialcomm.bsc" +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Debug/test_serialcomm.exe" /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "serialcomm - Win32 Release" +# Name "serialcomm - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\serial.c +# End Source File +# Begin Source File + +SOURCE=.\test_serialcomm.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\serial.h +# End Source File +# End Group +# End Target +# End Project diff --git a/device/examples/serialcomm/windows/serialcomm.dsw b/device/examples/serialcomm/windows/serialcomm.dsw new file mode 100644 index 00000000..68cfd2bd --- /dev/null +++ b/device/examples/serialcomm/windows/serialcomm.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "serialcomm"=.\serialcomm.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/device/examples/serialcomm/windows/test_serialcomm.cpp b/device/examples/serialcomm/windows/test_serialcomm.cpp index fd0fc953..32f409ba 100755 --- a/device/examples/serialcomm/windows/test_serialcomm.cpp +++ b/device/examples/serialcomm/windows/test_serialcomm.cpp @@ -10,12 +10,10 @@ int main(int argc, char* argv[]) { - HANDLE hComPort; + char buf[128]; - int ComPortNumber = 1; - - hComPort = SerialInit("com1", 1200); // 1200 Baud + hComPort = SerialInit("com1", 1200, 8, 1, 'N', 'N', 5000, 5000, 2, 128); if( hComPort == 0) { printf("\n\nError initializing %s!\n", "com1"); @@ -27,7 +25,7 @@ int main(int argc, char* argv[]) // sleep(5000); // read string from RS232 - printf("\nString received: %s\n", SerialGets(&hComPort)); + printf("\nString received: %s\n", SerialGets(buf, sizeof (buf) - 1, hComPort)); CloseHandle(hComPort); -- 2.47.2