Windows
You work with COM, like with file :
---------------------------------------------------------------
HANDLE COMport;
COMport=CreateFile("COM4", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
---------------------------------------------------------------
WriteFile(COMport, &buf_to_send, packetsize, &bc, NULL); // send data
unsigned char buf_to_send [8]; //data
int packetsize; //number of bytes to write
DWORD bc; it is empty, no assignments
---------------------------------------------------------------
ReadFile(COMport, &buffer_rd, blocksize, &bc, NULL); // receive data
---------------------------------------------------------------
Also you need to specify structures DCB, COMMTIMEOUTS , to determine parameters of COM behaviour.
functions for work with structures : GetCommState, SetCommState, GetCommTimeouts, SetCommTimeouts.
for additional tuning : SetupComm, PurgeComm
About all these functions you could fully acquainted at msdn.com