6 years, 8 months ago.  This question has been closed. Reason: Duplicate question

Communicate with programming languages running on the host PC that can communicate with a serialport

I want to send a serial string with a c ++ program, after that, this string must be received by the loaded program on the mbed lpc1768 and print this string. This is the program to send the string to mbed lpc1768:

  1. include "windows.h"
  1. include "string.h"
  1. include <iostream>
  1. include <tchar.h>
  1. include <stdint.h>

using namespace std;

HANDLE SerialPort;

char stringa[200]; stringa di ingresso void Insert() { printf("\nInserire stringa: "); scanf("%s", stringa); printf("\nStringa inserita con successo\n"); } int Open () { DCB dcb; BOOL fSuccess; TCHAR *pcCommPort=TEXT((TCHAR*)"COM4"); SerialPort=CreateFile(pcCommPort,GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (SerialPort == INVALID_HANDLE_VALUE){ printf("CreateFile failed with error %d.\n", GetLastError()); return (1); } SecureZeroMemory(&dcb, sizeof(DCB)); dcb.DCBlength = sizeof(DCB); fSuccess = GetCommState(SerialPort, &dcb); if (!fSuccess) { printf ("GetCommState failed with error %d.\n", GetLastError()); return(2); } 115200 bps, 8 data bits, no parity, and 1 stop bit. dcb.BaudRate = CBR_115200; baud rate dcb.ByteSize = 8; data size, xmit and rcv dcb.Parity = NOPARITY; parity bit dcb.StopBits = ONESTOPBIT; stop bit fSuccess = SetCommState(SerialPort, &dcb); if (!fSuccess) { printf ("SetCommState failed with error %d.\n", GetLastError()); return(3); } fSuccess = GetCommState(SerialPort, &dcb); if (!fSuccess) { printf ("GetCommState failed with error %d.\n", GetLastError()); return(2); } printf (TEXT("Serial port %s successfully reconfigured.\n"),pcCommPort); return(0); } void Write() { BOOL write; DWORD written=0; count=strlen(stringa); write=WriteFile(SerialPort, stringa, count, &written, NULL); if(write){ cout<<"\n\n"<<written; } } int main() { Open(); Insert(); Write(); }

Now how do I read the string through a program loaded on the mbed lpc1768?