I have a program that will be communicating with multiple COM ports. As of now I have all the code in one file and it is semi messy. How could I organize it in a way where all the serial connections and connection parameters are set up somewhere else allowing me to just read or write to the port in the main file.
Here is an example of configuration I mean
HANDLE hSerial = CreateFile("COM3",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
DCB dcbSerialParams = {0};
dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
dcbSerialParams.BaudRate=CBR_9600;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;
HANDLE hSerial = CreateFile("COM3",GENERIC_READ|GENERIC_WRITE,.......The only thing that is unique to each com port is the name “com3” so this is all you need to supply to the function. The handle returned by Createfile completely identifies the open port, it’s the only thing you need to read/write the port and close it when you have finished.
So learn about functions and pass in the name of the port and return the handle