//+--------------------------------------------------------------------------- // // hello_win_GUI_serial.c - Windows GUI 'Hello World!' Example modified to open serial port which is looped back. // // https://stackoverflow.com/questions/12537456/how-to-append-text-to-a-textbox+--------------------------------------------------------------------------- /* usage ..\tcc hello_win_GUI_serial.c hello_win_GUI_serial.exe * I need a gui with a few buttons and status. I need a structure to act as the interface. I need a funtion to look at the received strings and convert to an event. Buttons: quit hangup dial send Status: modem connection incoming text outgoing text Interface: use MicroCip flags. send available */ /* interface */ struct interfaceT { int flag1; int flag2; int flag3; int leds; // some LED for status and example. } io ; /******************************************** * Sec 4.0 Global Vars ********************************************/ int fd; // File descriptor of port we will talk to #define MAX_BUFFER 512 char serialBuffer[ MAX_BUFFER]; // Serial buffer sto store data for I/O char serialBufferTx[MAX_BUFFER]; // Serial buffer sto store data for I/O char serialBufferRx[MAX_BUFFER]; // Serial buffer sto store data for I/O char serialBufferStatus[MAX_BUFFER]; // Serial buffer sto store data for I/O char * serialBufferP ; /* used to append more text onto buffer */ char * statusStringP ; /* used to point to a status string */ int finished; #include #include /******************************************** * Sec 4.0 Modem Prototypes ********************************************/ void modemLogTime( void ); HANDLE modem_open (int io_port, const long int BaudRate, const char parity, const char data); void modemInit( void ); void modem_terminate( void ); void writeBytes(int descriptor, int count); void readBytes(int descriptor, int count); void modemWriteBytes( char* modemCmdStr ); void modemReadBytes( int count ); void modemResetRxBuffer( void ); char * modemRxStr( char * wantStr ); #define RS232_STRLEN_DEVICE 11 #define DELAY ; #ifdef comment #define DELAYM delay_ms( 1 ); #define DELAYL delay_ms( 100 ); #endif #define APPNAME "HELLO_WIN" #define APPNAME2 "HELLO_WIN - 2" #define BUFFERLEN 200 #define BTN_START 100 #define BTN_STOP 101 #define BTN_PLUS 102 #define BTN_QUIT 103 #define BTN_HANGUP 104 #define BTN_DIAL 105 #define BTN_SEND 106 #define IDC_EDIT1 110 #define IDC_EDIT2 111 #define IDC_EDIT3 112 #define ID_EDITCHILD 113 #define IDT_TIMER1 1 #define IDT_TIMER2 2 char szAppName[] = APPNAME; // The name of this application char szAppName2[] = APPNAME2; // The name of this application char szTitle[] = APPNAME; // The title bar text char szTitle2[] = APPNAME2; // The title bar text HANDLE hCom; char buffer[ BUFFERLEN+1 ]; const char *pWindowText; static HWND hWndEdit1; static HWND hWndEdit2; static HWND hWndEdit3; static HWND hWndEdit4; static HWND hWndEdit5; static HWND hWndEdit6; SCROLLINFO sb1; LPSTR lpString; HPEN hPausePen; HPEN hRedPen; HPEN hGreenPen; void CenterWindow(HWND hWnd); //+--------------------------------------------------------------------------- // // Function: WndProc // // Synopsis: very unusual type of function - gets called by system to // process windows messages. // // Arguments: same as always. //---------------------------------------------------------------------------- LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { // ----------------------- first and last case WM_CREATE: CenterWindow(hwnd); hRedPen = CreatePen(PS_SOLID,4,RGB(255,32,32)); hGreenPen = CreatePen(PS_SOLID,4,RGB(32,255,32)); break; case WM_DESTROY: PostQuitMessage(0); break; // ----------------------- get out of it... case WM_RBUTTONUP: DestroyWindow(hwnd); break; case WM_KEYDOWN: if (VK_ESCAPE == wParam) DestroyWindow(hwnd); if (wParam == 'G'){ pWindowText = "You pressed G"; io.flag1 = 1; io.flag2 = 1; InvalidateRect(hwnd,NULL,TRUE); } if (wParam == 'Z'){ io.flag1 = 0; io.flag2 = 0; pWindowText = "You pressed Z"; InvalidateRect(hwnd,NULL,TRUE); } if (wParam == 'a'){ pWindowText = "You pressed a"; InvalidateRect(hwnd,NULL,TRUE); GetWindowTextA(hWndEdit1, buffer,BUFFERLEN); SetWindowTextA(hWndEdit2, buffer ); } break; case WM_COMMAND: if ( LOWORD( wParam ) == BTN_QUIT ){ io.flag1 = 0; io.flag2 = 0; } if ( LOWORD( wParam ) == BTN_HANGUP ){ io.flag1 = 0; io.flag2 = 1; } if ( LOWORD( wParam ) == BTN_DIAL ){ io.flag1 = 1; io.flag2 = 0; modemWriteBytes( "hello" ); SetTimer(hwnd, // handle to main window IDT_TIMER1, // timer identifier 500, // 0.5 second interval (TIMERPROC) NULL); // no timer callback SendMessage(hWndEdit1,EM_SETSEL,0,-1); //no difference between passing 0 or -1 SendMessage(hWndEdit1,EM_REPLACESEL,TRUE,(LPARAM)"Dial"); } if ( LOWORD( wParam ) == BTN_SEND ){ io.flag1 = 1; io.flag2 = 1; modemWriteBytes( "SEND..." ); } //pWindowText = "You pressed the button"; //InvalidateRect(hwnd,NULL,TRUE); if ( LOWORD( wParam ) == BTN_START ){ pWindowText = "You pressed the START button"; // https://docs.microsoft.com/en-us/windows/desktop/Controls/em-setsel SendMessage(hWndEdit1,EM_SETSEL,0,-1); //no difference between passing 0 or -1 SendMessage(hWndEdit1,EM_REPLACESEL,TRUE,(LPARAM)"===="); SendMessage(hWndEdit4,EM_SETSEL,2,4); //no difference between passing 0 or -1 SendMessage(hWndEdit4,EM_REPLACESEL,TRUE,(LPARAM)"hello"); //InvalidateRect(hwnd,NULL,TRUE); hPausePen = CreatePen(PS_SOLID,4,RGB(32,255,32)); io.flag1 = 0; io.flag2 = 1; } if ( LOWORD( wParam ) == BTN_STOP ){ pWindowText = "You pressed the STOP button"; //InvalidateRect(hwnd,NULL,TRUE); hPausePen = CreatePen(PS_SOLID,4,RGB(255,32,32)); GetWindowTextA(hWndEdit1, buffer,BUFFERLEN); SetWindowTextA(hWndEdit2, buffer ); /* NOT WORKING OR COMPLETE https://docs.microsoft.com/en-gb/windows/desktop/api/winuser/ns-winuser-tagscrollinfo SCROLLINFO sb1; GetScrollInfo( hWndEdit5, SB_CTL, &sb1 ); sb1.nPos += 5; SetScrollInfo( hWndEdit5, SB_CTL, &sb1, TRUE ); */ io.flag1 = 1; io.flag2 = 0; } InvalidateRect(hwnd,NULL,TRUE); break; // https://stackoverflow.com/questions/20640330/winapi-bn-clicked-how-to-identify-which-button-was-clicked // #define LINE(b,x1,y1,x2,y2) { SelectObject(hDC,b & New ? hUsePen : hOffPen);MoveToEx(hDC,x1,y1,(LPPOINT) NULL );LineTo(hDC,x2,y2); } case WM_TIMER: switch (wParam) { case IDT_TIMER1: modemReadBytes( 20 ); SendMessage(hWndEdit4,EM_SETSEL,0,-1); //no difference between passing 0 or -1 SendMessage(hWndEdit4,EM_REPLACESEL,TRUE,(LPARAM) "...hello... " ); SendMessage(hWndEdit4,EM_REPLACESEL,TRUE,(LPARAM) serialBuffer ); // pWindowText = pT2; // GetCursorPos(&ptNow); //io.flag1 = 0; //io.flag2 = 0; SendMessage(hWndEdit1,EM_SETSEL,0,-1); //no difference between passing 0 or -1 SendMessage(hWndEdit1,EM_REPLACESEL,TRUE,(LPARAM)"timed out"); InvalidateRect(hwnd,NULL,TRUE); if ( modemRxStr( "SEND" ) ) { SendMessage(hWndEdit1,EM_SETSEL,0,-1); //no difference between passing 0 or -1 SendMessage(hWndEdit1,EM_REPLACESEL,TRUE,(LPARAM)" seen SEND ...."); modemResetRxBuffer( ); io.leds = 1; } if ( modemRxStr( "hello" ) ) { SendMessage(hWndEdit1,EM_SETSEL,0,-1); //no difference between passing 0 or -1 SendMessage(hWndEdit1,EM_REPLACESEL,TRUE,(LPARAM)" seen hello ...."); modemResetRxBuffer( ); io.leds = 2; } modemLogTime(); return 0; case IDT_TIMER2: // process the five-minute timer //break; return 0; } break; // ----------------------- display our minimal info case WM_PAINT: { PAINTSTRUCT ps; HDC hdc; RECT rc; int xpos, ypos; int count; int leds; hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rc); ypos = rc.top +5; if ( io.flag1 ) { SelectObject(hdc, hGreenPen ); } else { SelectObject(hdc, hRedPen ); } MoveToEx( hdc,rc.left+10, ypos ,(LPPOINT) NULL ); LineTo( hdc,rc.left+20, ypos ); if ( io.flag2 ) { SelectObject(hdc, hGreenPen ); } else { SelectObject(hdc, hRedPen ); } MoveToEx( hdc,rc.left+30, ypos ,(LPPOINT) NULL ); LineTo( hdc,rc.left+40, ypos ); leds = io.leds; for ( count = 0 ; count < 8 ; count++ ){ if ( ( leds & 1 ) > 0 ) { SelectObject(hdc, hGreenPen ); } else { SelectObject(hdc, hRedPen ); } MoveToEx( hdc,rc.left+70+ count * 10, ypos ,(LPPOINT) NULL ); LineTo( hdc,rc.left+70+ count * 10, ypos+4 ); leds = leds / 2; } ypos = rc.bottom - ( rc.bottom - rc.top )/4; SelectObject(hdc, hPausePen ); MoveToEx( hdc,rc.left, ypos ,(LPPOINT) NULL ); LineTo( hdc,rc.right, ypos ); /* SetTextColor(hdc, RGB(240,240,96)); SetBkMode(hdc, TRANSPARENT); DrawText(hdc, pWindowText, -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER); */ // test if modem COM port found and report. if ((int)hCom <= 0){ SetTextColor(hdc, RGB(240,0,0)); DrawText(hdc, " No modem connected ", -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER); } else { SetTextColor(hdc, RGB(240,240,96)); SetBkMode(hdc, TRANSPARENT); DrawText(hdc, pWindowText, -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER); } EndPaint(hwnd, &ps); break; } // ----------------------- let windows do all other stuff default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; } //+--------------------------------------------------------------------------- // // Function: WinMain // // Synopsis: standard entrypoint for GUI Win32 apps // //---------------------------------------------------------------------------- int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG msg; WNDCLASS wc; HWND hwnd; HWND hwnd2; /* HWND hWndEdit1; HWND hWndEdit2; HWND hWndEdit3; */ HWND hWndButton1; HWND hWndButton2; /* Buttons: quit hangup dial send */ HWND hWndButtonQuit; HWND hWndButtonHangup; HWND hWndButtonDial; HWND hWndButtonSend; modemInit( ); pWindowText = lpCmdLine[0] ? lpCmdLine : "Hello Windows! - doug "; // Fill in window class structure with parameters that describe // the main window. ZeroMemory(&wc, sizeof wc); wc.hInstance = hInstance; wc.lpszClassName = szAppName; wc.lpfnWndProc = (WNDPROC)WndProc; wc.style = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW; // wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // wc.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH); wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wc.hIcon = LoadIcon( NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); if (FALSE == RegisterClass(&wc)) return 0; hPausePen = CreatePen(PS_SOLID,4,RGB(128,128,128)); // create the browser hwnd = CreateWindow( szAppName, szTitle, WS_OVERLAPPEDWINDOW|WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 360,//CW_USEDEFAULT, 440,//CW_USEDEFAULT, 0, 0, hInstance, 0); hWndEdit1 = CreateWindow(TEXT("Edit"), TEXT("test"), WS_CHILD | WS_VISIBLE | WS_BORDER, 100, 10, 140, 20, hwnd, NULL, NULL, NULL); hWndEdit2 = CreateWindow(TEXT("Edit"), TEXT("test"), WS_CHILD | WS_VISIBLE | WS_BORDER, 100, 30, 140, 20, hwnd, NULL, NULL, NULL); hWndEdit3 = CreateWindow(TEXT("Edit"), TEXT("start"), WS_CHILD | WS_VISIBLE | WS_BORDER, 100, 50, 140, 20, hwnd, ( HMENU )BTN_PLUS, NULL, NULL); hWndButton1 = CreateWindow(TEXT("Button"), TEXT("start"), WS_CHILD | WS_VISIBLE | WS_BORDER , 100, 70, 70, 20, hwnd, ( HMENU )BTN_START, NULL, NULL); hWndButton2 = CreateWindow(TEXT("Button"), TEXT("stop"), WS_CHILD | WS_VISIBLE | WS_BORDER , 180, 70, 70, 20, hwnd, ( HMENU )BTN_STOP, NULL, NULL); /* HWND hWndButtonQuit; HWND hWndButtonHangup; HWND hWndButtonDial; HWND hWndButtonSend; */ hWndButtonQuit = CreateWindow(TEXT("Button"), TEXT("Quit"), WS_CHILD | WS_VISIBLE | WS_BORDER , 10, 10, 70, 20, hwnd, ( HMENU )BTN_QUIT, NULL, NULL); hWndButtonHangup = CreateWindow(TEXT("Button"), TEXT("Hangup"), WS_CHILD | WS_VISIBLE | WS_BORDER , 10, 30, 70, 20, hwnd, ( HMENU )BTN_HANGUP, NULL, NULL); hWndButtonDial = CreateWindow(TEXT("Button"), TEXT("Dial"), WS_CHILD | WS_VISIBLE | WS_BORDER , 10, 50, 70, 20, hwnd, ( HMENU )BTN_DIAL, NULL, NULL); hWndButtonSend = CreateWindow(TEXT("Button"), TEXT("Send"), WS_CHILD | WS_VISIBLE | WS_BORDER , 10, 70, 70, 20, hwnd, ( HMENU )BTN_SEND, NULL, NULL); // hInst hWndEdit4 = CreateWindow(TEXT("EDIT"), TEXT("Edit\n4\ntxt"), // WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL | ES_WANTRETURN, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL, 10, 100, 200, 90, hwnd, (HMENU)IDC_EDIT1, // edit control ID (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), 0); hWndEdit5 = CreateWindow(TEXT("ScrollBar"), TEXT("Edit\n5\ntxt"), // WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL | ES_WANTRETURN, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL, 10, 210, 200, 20, hwnd, (HMENU)IDC_EDIT2, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), 0); hWndEdit6 = CreateWindow(TEXT("Static"), TEXT("Edit\n5\ntxt"), // WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL | ES_WANTRETURN, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL, 10, 240, 200, 50, hwnd, (HMENU)IDC_EDIT3, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), 0); /* Class Description Button The class for a button. ComboBox The class for a combo box. Edit The class for an edit control. ListBox The class for a list box. MDIClient The class for an MDI client window. ScrollBar The class for a scroll bar. Static The class for a static control. */ /* ShowWindow(hWndEdit1,nCmdShow); ShowWindow(hWndEdit2,nCmdShow); ShowWindow(hWndEdit3,nCmdShow); */ /* https://docs.microsoft.com/en-us/windows/desktop/controls/create-a-command-link */ if ( NULL == hwnd ) return 0; /* if ( NULL == hwnd2 ) return 0; */ if ( hWndEdit1 == NULL ) return 0; if ( hWndEdit2 == NULL ) return 0; if ( hWndEdit3 == NULL ) return 0; // Main message loop: while (GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } modem_terminate( ); return msg.wParam; } //+--------------------------------------------------------------------------- //+--------------------------------------------------------------------------- void CenterWindow(HWND hwnd_self) { HWND hwnd_parent; RECT rw_self, rc_parent, rw_parent; int xpos, ypos; hwnd_parent = GetParent(hwnd_self); if (NULL == hwnd_parent) hwnd_parent = GetDesktopWindow(); GetWindowRect(hwnd_parent, &rw_parent); GetClientRect(hwnd_parent, &rc_parent); GetWindowRect(hwnd_self, &rw_self); xpos = rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2; ypos = rw_parent.top + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2; SetWindowPos( hwnd_self, NULL, xpos, ypos, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE ); } //+--------------------------------------------------------------------------- /****************************************************** * SEC 4.0 Modem interface ******************************************************/ HANDLE modem_open (int io_port, const long int BaudRate, const char parity, const char data) { // HANDLE hCom; OVERLAPPED o; BOOL fSuccess; DWORD dwEvtMask; BOOL bPortReady; DCB dcb; COMMTIMEOUTS CommTimeouts; /* meh, Windows CE is special and can't handle URN path, just COM1: format snprintf(ret, RS232_STRLEN_DEVICE, "\\\\.\\COM%d", io_port); */ char ComPortName[ RS232_STRLEN_DEVICE ]; /* URN support "\\.\COM255 */ snprintf(ComPortName, RS232_STRLEN_DEVICE , "\\\\.\\COM%d", io_port); printf( "Using com port:%s",ComPortName); sleep(1000); hCom = CreateFile(ComPortName, FILE_FLAG_OVERLAPPED | GENERIC_READ | GENERIC_WRITE, 3, // 0 - exclusive access NULL, // no security OPEN_EXISTING, 0, // no overlapped I/O NULL); // null template if ((int)hCom <= 0) { printf("serial port COM%d connect fail %s error %d\n\r", io_port, ComPortName, GetLastError()); return 0; } //else printf(" serial port COM%d connect OK \n\r", io_port); bPortReady = SetupComm(hCom, 128, 128); // set buffer sizes if (!bPortReady ) { printf("serial port COM%d SetupComm fail %d\n\r", io_port, GetLastError()); return 0; } //else printf(" serial port COM%d connect OK \n\r", io_port); // Set the event mask. fSuccess = SetCommMask(hCom, EV_CTS | EV_DSR); if (!fSuccess) { // Handle the error. printf("SetCommMask failed with error %d.\n", GetLastError()); return; } // Create an event object for use by WaitCommEvent. o.hEvent = CreateEvent( NULL, // default security attributes TRUE, // manual-reset event FALSE, // not signaled NULL // no name ); // Initialize the rest of the OVERLAPPED structure to zero. o.Internal = 0; o.InternalHigh = 0; o.Offset = 0; o.OffsetHigh = 0; bPortReady = GetCommState(hCom, &dcb); if (!bPortReady ) { printf("serial port COM%d GetCommState fail %d\n\r", io_port, GetLastError()); return 0; } // else printf(" serial port COM%d connect OK \n\r", io_port); dcb.BaudRate = BaudRate; if( data == '7') dcb.ByteSize = 7; else dcb.ByteSize = 8; if( parity == 'E') dcb.Parity = EVENPARITY; if( parity == 'O') dcb.Parity = ODDPARITY; else dcb.Parity = NOPARITY; 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 = FALSE; // turn off CTS flow control dcb.fRtsControl = FALSE; // RTS_CONTROL_HANDSHAKE; // // set DSRDTR dcb.fOutxDsrFlow = FALSE; // turn off DSR flow control //dcb.fDtrControl = DTR_CONTROL_ENABLE; // DTR handshake dcb.fDtrControl = DTR_CONTROL_DISABLE; // // dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; // bPortReady = SetCommState(hCom, &dcb); if (!bPortReady ) { printf("serial port COM%d SetCommState fail %d\n\r", io_port, GetLastError()); return 0; } // Communication timeouts //COMMTIMEOUTS CommTimeouts; bPortReady = GetCommTimeouts (hCom, &CommTimeouts); CommTimeouts.ReadIntervalTimeout = 500 ; CommTimeouts.ReadTotalTimeoutConstant = 500 ; CommTimeouts.ReadTotalTimeoutMultiplier = 1 ; CommTimeouts.WriteTotalTimeoutConstant = 5 ; CommTimeouts.WriteTotalTimeoutMultiplier = 1 ; bPortReady = SetCommTimeouts (hCom, &CommTimeouts); if (!bPortReady ) { printf("serial port COM%d SetCommTimeouts fail %d\n\r", io_port, GetLastError()); return 0; } else { printf(" serial port COM%d connect OK \n\r", io_port); } return (hCom); } void modemInit( void ){ /* define to select config */ #define MODEM_USB 1 #ifdef MODEM_USB #define COM_BAUD 19200 #define COM_PORT 13 // ////////// Modify as required. #endif //HANDLE hCom; //handle for serial port I/O //OVERLAPPED o; //BOOL fSuccess; //DWORD dwEvtMask; /* char buff[100]; */ int io_port = COM_PORT; // clock_t timeout; //*************************************************** if(!modem_open( io_port , COM_BAUD , '8', 'N')) { //exit(1); } modemResetRxBuffer( ); } void modem_terminate( void ) { CloseHandle(hCom); } /******************************************** * Sec 7.0 functions - modem ********************************************/ void writeBytes(int descriptor, int count) { BOOL bWriteRC; static DWORD iBytesWritten; if ((int)hCom > 0){ bWriteRC = WriteFile(hCom, serialBufferTx, count, &iBytesWritten,NULL); } return; /* clear buffer after sending */ serialBufferTx[ 0 ] = '\0'; } void readBytes(int descriptor, int count) { /* for now reset if not enough space */ // printf( "\n readBuffer: %p %p \n%s\n%s\n", serialBuffer, serialBufferP, serialBuffer, serialBufferP ); /* for now reset is not enough space */ if ( ( serialBufferP + count ) > ( serialBuffer + MAX_BUFFER ) ){ serialBufferP = serialBuffer; printf("\nBuffer wrapped...\n"); } /* zero buffer */ serialBufferP[ 0 ] = '\0'; serialBufferP[ 1 ] = '_'; char rxchar; BOOL bReadRC; static DWORD iBytesRead; if ((int)hCom > 0){ bReadRC = ReadFile(hCom, serialBufferP, count, &iBytesRead, NULL); if( iBytesRead >0 ){ serialBufferP[ iBytesRead ] = '\0'; serialBufferP[ iBytesRead+1 ] = '\0'; serialBufferP += iBytesRead; } } } void modemWriteBytes( char* modemCmdStr ){ snprintf(serialBufferTx,99, "%s",modemCmdStr ); snprintf(serialBufferStatus,99, "%s",modemCmdStr ); printf( "\n:%d:%s:\n", strlen( serialBufferTx ),serialBufferTx ); writeBytes(fd, strlen( serialBufferTx ) ); } void modemReadBytes( int count ){ readBytes(fd, count ); printf("\n:%s", serialBuffer ); } void modemResetRxBuffer( void ){ //modemLogRxBuffer( -1 ); /* zero the rx buffer */ serialBufferP = serialBuffer; serialBufferP[0] = '\0'; } char * modemRxStr( char * wantStr ){ return strstr(serialBuffer, wantStr ); } void modemLogTime( void ){ time_t now; FILE * opFile; /* Get the current time for the log */ time( &now ); opFile = fopen("th_log.js.txt","a+"); if( opFile ) { fprintf( opFile, "\nTS%s", ctime( &now ) ); fclose(opFile); opFile=0; } } /* * * * * I want a function to send modemWriteBytes( "\n\rATDT18000870\n\r" ); */