🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.sgi.hardware
5 messages
5 total messages Started by Dave Helfrick. Fri, 26 Jan 1996 22:34
Help with serial/tty2 communication (write ok, read NOT).
#131
Author: 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
Re: Help with serial/tty2 communication (write ok, read NOT).
#132
Author: Tom Benoist
Date: Sun, 28 Jan 1996 06:45
34 lines
1426 bytes
Its pretty difficult to see what your doing wrong since,
1. you didnt show your ioctl setup.
2. You didnt mention if you understood the implications of O_NONBLOCK
   (ie...your reads return FALSE until a byte is available)

In any case, the following works for most applications.....

-Tom



    int port;
    struct termio t;


    port = open("/dev/ttyd2", O_RDWR | O_NDELAY, 0666);
    t.c_iflag = IGNBRK;
    t.c_oflag = 0;

    t.c_cflag = B38400 | CS8 | CREAD | CLOCAL;
    t.c_lflag = 0;

    t.c_cc[VMIN] = 1;
    t.c_cc[VTIME] = 1;

    t.c_iflag &=~(IXON | IXOFF | IXANY);

    ioctl(port, TCSETAW, &t);


-- 
_____________________________________________________________________
Tom Benoist                                        Email: ben@ifx.com 
Interactive Effects                      Amazon http://www.ifx.com/ie
Re: Help with serial/tty2 communication (write ok, read NOT).
#133
Author: Michael Sweet
Date: Mon, 29 Jan 1996 17:25
23 lines
1506 bytes
Dave Helfrick. (helfrick@cs.umbc.edu) wrote:


: 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.

You probably need to set the 'CREAD' bit in the termios 'l_flag' structure
(I think that's the one.  From memory...).

I started woring on some UNIX serial I/O pages a long while ago, but haven't
quite finished them up... no free time! :(  Anyways, the current pages can
be accessed by your favorite web browser at http://www.easysw.com/~mike/serial.

--
______________________________________________________________________________

 Mike Sweet                  2D & 3D Software for      Easy Software Products
 (301) 994-0377             Silicon Graphics, Inc.      20778 Wolftrap Street
 mike@easysw.com                 Workstations       Lexington Park, MD  20653
                             http://www.easysw.com
______________________________________________________________________________
Re: Help with serial/tty2 communication (write ok, read NOT).
#135
Author: Troy Stephen
Date: Mon, 12 Feb 1996 06:06
84 lines
3097 bytes

Hi guys,

I have a similar problem, and thought it might as well continue on this thread.

I am using a configuration almost exactly the same as the one you have
suggested below.  The only differences being:
    
 port = open("/dev/ttyd2", O_RDWR);

 t.c_cc[VMIN] = 27;
 t.c_cc[VTIME] = 0;

I'm reading 27 byte packets and I want the read to block until it gets
a complete packet.  I think the man page mentions that with this
configuration, it is possible for the read to block indefinitely,
however I haven't witnessed this yet.  What I am seeing though, is that
sometimes the read returns prematurely without all 27 bytes, and I need
to send it back to get the rest. Why is this so?  What could be causing
it to return early?

Also, I am a bit concerned about the reliability of the serial ports at
high baud rates, especially when the man page for SERIAL(7) says:

"...Each line may be independently set to run at any of several speeds,
as high as 19,200 or even 38,400 bps."

What are people's experience with this?  I need to run at 38.4kbaud and
my application needs to read the 27 byte packets at 60hz.  What are my
chances of getting this to work reliably?


Regards,
Troy Stephen
troys@wormald.com.au

PS. I'm using a deskside ONYX with IRIX 5.2



In article <4ef62p$8t2@ni1.ni.net> Tom Benoist <ben@ifx.com> writes:

> From: Tom Benoist <ben@ifx.com>
> Newsgroups: comp.sys.sgi.hardware,comp.lang.c++
> Date: 28 Jan 1996 06:45:45 GMT
> Organization: Interactive Effects
> X-URL: news:4ebkuaINNdqp@retriever.cs.umbc.edu
> 
> Its pretty difficult to see what your doing wrong since,
> 1. you didnt show your ioctl setup.
> 2. You didnt mention if you understood the implications of O_NONBLOCK
>    (ie...your reads return FALSE until a byte is available)
> 
> In any case, the following works for most applications.....
> 
> -Tom
> 
> 
> 
>     int port;
>     struct termio t;
> 
> 
>     port = open("/dev/ttyd2", O_RDWR | O_NDELAY, 0666);
>     t.c_iflag = IGNBRK;
>     t.c_oflag = 0;
> 
>     t.c_cflag = B38400 | CS8 | CREAD | CLOCAL;
>     t.c_lflag = 0;
> 
>     t.c_cc[VMIN] = 1;
>     t.c_cc[VTIME] = 1;
> 
>     t.c_iflag &=~(IXON | IXOFF | IXANY);
> 
>     ioctl(port, TCSETAW, &t);
> 
> 
> -- 
> _____________________________________________________________________
> Tom Benoist                                        Email: ben@ifx.com 
> Interactive Effects                      Amazon http://www.ifx.com/ie
> 
Re: Help with serial/tty2 communication (write ok, read NOT).
#134
Author: Scott Henry
Date: Mon, 12 Feb 1996 18:09
27 lines
1901 bytes
In article <TROYS.96Feb12160640@donald.wormald.com.au> troys@donald.wormald.com.au (Troy Stephen) writes:

> I have a similar problem, and thought it might as well continue on this thread.

> Also, I am a bit concerned about the reliability of the serial ports at
> high baud rates, especially when the man page for SERIAL(7) says:

> "...Each line may be independently set to run at any of several speeds,
> as high as 19,200 or even 38,400 bps."

> What are people's experience with this?  I need to run at 38.4kbaud and
> my application needs to read the 27 byte packets at 60hz.  What are my
> chances of getting this to work reliably?

Methinks the man page needs to be updated...  38400 works perfectly
fine on R3k Indigos and more recent machines.  You *may* need to
worry about flow control (I don't know how big the serial buffer
is), but people get away with modem cables missing RTS on 1500 byte
PPP/SLIP packets at 38400, so you are probably OK.

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Scott Henry <scotth@sgi.com> / Help! My disclaimer is missing!
 Networking Services,        / GIGO *really* means: Garbage in, Gospel Out
 Silicon Graphics, Inc      / 
  <a href="http://reality.sgi.com/employees/scotth/">home page</a>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads