Writing bits to COM port in Windows - equivalent to INPORTB function
<p>I am writing a program to control a relay switch connected thru the serial (RS-232) COM1 port. The device I am using has contains two relay switches. These are either 'open' or 'closed'.</p>

<p>By default, both relays are open. The number 1 relay is closed by setting bit 1 in the modem control register. Number 2 relay is closed by setting bit 0 in the modem control register.</p>

<p>In C, this can be achieved as follows:</p>

<pre><code>x = inportb(0x3FC);
x=x &amp; ~2; //Set bit 1 to zero
x=x | 2;        //Set bit 1 to one
x=x &amp; ~1; //Set bit 0 to zero
x=x | 1;        //Set bit 0 to one
</code></pre>

<p>C++ however, does not make COM port access so easy (or so I am led to believe). I currently have the following code, which successfully opens and closes the COM port so that it can be communicated with in C++ and Windows:</p>

<pre><code>#include &lt;windows.h&gt;

//Initialise Windows module
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
LPSTR lpszArgument, int nFunsterStil)

{
 //Define the serial port precedure
 HANDLE hSerial;

 //Initialise relay
 hSerial = CreateFile("COM1",GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

 //SOME CODE MUST GO HERE

 //Deactivate relay
 CloseHandle(hSerial);

 return 0;
}
</code></pre>

<p>However, I am at a loss as to how to 'set bits'. I'm still very new to C++. Any help would be gratefully appreciated.</p>
