🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sgi.hardware
Article #131

Help with serial/tty2 communication (write ok, read NOT).

#131
From: Dave Helfrick.
Date: Fri, 26 Jan 1996 22:34
82 lines
2552 bytes

I am running on an Impact, and am trying to write a C++ class
(wrapper for C code) to communicate with a serial port.

I can write ok, but reading is not working.

Here is the read and write methods, plus the constructor...
CONSTRUCTOR...............
HtRawSerial::HtRawSerial(char *portName, int baudRate)
{
	_goodOpen = TRUE;
	_goodClose = FALSE;

	if ((TTyfd = open(portName, (O_RDWR | O_NONBLOCK))) < 0)
	  //	if ((TTyfd = open(portName, (O_RDWR | O_NDELAY))) < 0)
	{
#		ifndef FOR_PERFORMER
			cout << "*** Unable to open" << portName << endl;
#		else
			printf("*** Unable to open '%s'.\n", portName);
#		endif
		_goodOpen = FALSE;
	}

	// Initialize the serial port I/O control structures.
	if (!ioctl_get(TTyfd, &OldTermIO))
	{
		printf("***Failed to get old terminal\n");
		_goodOpen = FALSE;
	}

	if (!ioctl_get(TTyfd, &NewTermIO))
	{
		printf("***Failed to get new terminal\n");
		_goodOpen = FALSE;
	}

	ioctl_prep_init_raw(&NewTermIO);
	ioctl_prep_baud(&NewTermIO, baudRate);

	/*
	* Configure the serial port and console.
	*/
	if (!ioctl_set(TTyfd, &NewTermIO))
	{
		printf("***Failed ioctl_set(TTyfd, &NewTermIO)\n");
		_goodOpen = FALSE;
	}
	//	openFlag = _goodOpen;
}
-------------------------------------------------
WRITE.....................................
/*^============================================================================
  RETURNS:       TRUE if successful, FALSE otherwise.
  PARAMETERS:    The character you are writing
=*^=============*/
int HtRawSerial::writeByte(unsigned char &byte)
{
	if (write(TTyfd, &byte, 1) > 0)
		return(TRUE);
	return(FALSE);
}

------------------------------------------------------
READ  <THIS IS WHAT DOES NOT WORK!!!!!!!!!>
/*^============================================================================
  RETURNS:       TRUE if successful, FALSE otherwise.
  PARAMETERS:    The character you are reading
=*^=============*/
int HtRawSerial::readByte(unsigned char &byte)
{
	if (read(TTyfd, &byte, 1) > 0)
		return(TRUE);
	return(FALSE);
}



-- 
				- Dave
helfrick@cs.umbc.edu
Technical Details
Message-ID: <4ebkuaINNdqp@retriever.cs.umbc.edu>
Path: arc1-ca.pugleaf.net!news.umbc.edu!nobody

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.umbc.edu!nobody
From: helfrick@cs.umbc.edu (Dave Helfrick.)
Newsgroups: comp.sys.sgi.hardware,comp.lang.c++
Subject: Help with serial/tty2 communication (write ok, read NOT).
Date: 26 Jan 1996 17:34:50 -0500
Organization: University of Maryland Baltimore County
Distribution: na
Message-ID: <4ebkuaINNdqp@retriever.cs.umbc.edu>
NNTP-Posting-Host: retriever.cs.umbc.edu
NNTP-Posting-User: helfrick