0
Can somebody getme a code to send and receive data to serial port? C++
I need a simple program on c++ i need send a bit and receive one. Is for connect a pc to microcontroler pic16f84a.
10 odpowiedzi
+ 3
//Do you have your attempts?? please attach then
+ 3
Yes, you can use that code for opening comport on Windows. but you must append a check of serialHandle for successful opening.
Use WriteFile function to write number to comport and
ReadFile to read number.
+ 2
The code is platform specific.
The general algorithm is as follows:
1. Get handle by Opening the com port as regular file using its OS-specific name (COM1 on windows or /dev/ttyS1 on linux...).
2. Setup com port (baudrate, parity...) by calling OS-specific API on the handle.
3. Read and write to comport handle using file read/write functions.
4. Close the handle.
Usually work with comport is performed in a separate thread
+ 2
A web search may give you a solution.
0
No man
0
I dont have then
0
Could i use this code?
#include <windows.h> /* ... */ // Open serial port HANDLE serialHandle;
serialHandle = CreateFile("\\\\.\\COM1", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
// Do some basic settings DCB serialParams = { 0 };
serialParams.DCBlength = sizeof(serialParams);
GetCommState(serialHandle, &serialParams);
serialParams.BaudRate = baudrate;
serialParams.ByteSize = byteSize;
serialParams.StopBits = stopBits;
serialParams.Parity = parity; SetCommState(serialHandle, &serialParams);
0
For example I need send number one and receive 2
0
Helpme please
0
I need to open the serial or com port and send a number one and then receive a number 2 from that same port