[comp.windows.ms] Serial port under MS Windows

darcy@druid.uucp (D'Arcy J.M. Cain) (08/10/90)

First of all I am not a Microsoft Windows programmer so apologies if this
seems like a stupid question.  I have to get some software of mine working
under Windows 2.11 and I have been given the following code (more or less)
which is supposed to open and write to a serial port.  Unfortuanately I
can't check anything because neither Microsoft's SDK or Charles Petzold's
book has any discussion about serial communications.  Can anyone tell me
if the following code should work please.

------------------------------ start of code ------------------------------
#include	<windows.h>
#include	<time.h>

static int	iComm;

int		init_com(int com_port)
{
	char		cBuffer[256];
	LPSTR		p;
	DCB			theDCB;

	if (com_port == 0)
		return(CloseComm(iComm));

	lstrcpy(cBuffer, "COM :9600,O,8,1");
	cBuffer[3] = (char)(com_port + '0'

	if(BuildCommDCB(cBuffer, &theDCB) < 0)
		return(1);

	if (SetCommState(&theDCB) < 0)
		return(1);

	if ((p = lstrchr(cBuffer, ':')) != NULL)
		*p = 0;

	if ((iComm = OpenComm(cBuffer, 512, 512)) < 0)
		return(iComm);

	/* the following is just for test purposes.  It should send the */
	/* MODE string out the port.  It doesn't do anything. */
	WriteComm(iComm, cBuffer, 15);

	/* it gets here because the function returns 0 */
	return(0);
}
--------------------------- end of included code --------------------------

I tried putting the SetCommState() call after the open and that didn't
seem to help.  The port I am testing is *not* the mouse port.

-- 
D'Arcy J.M. Cain (darcy@druid)     |
D'Arcy Cain Consulting             |   MS-DOS:  The Andrew Dice Clay
West Hill, Ontario, Canada         |   of operating systems.
+ 416 281 6094                     |