Serial Link Communication

New Message Reply Date view Thread view Subject view Author view

Julia Ellery (modellers++at++intersim.co.uk)
Tue, 06 Jan 1998 15:39:16 +0000


Hello

SG used: Onyx RE2
IRIX 6.2

Can someone tell me how to read data via a serial link.

I am trying to read data sent from a PC. To test, I am using a terminal
emulator on the PC and using the Transfers "Send Binary File" menu
option.
I have put some code together as a starting point (copy below) but it
is not working. It gives the following results:

If I use the "Send Text File" option with a file containing a small
string,
then most but not all the characters are received. However, with the
Binary
File, none of the characters received bear any resemblance to the
original data.
I tried a file of 28 charcters from 0 to 28 in sequence and also a file
of 8 characters of value 0x20. In both cases the characters received
were roughly the same (sometimes starting at a different point and
depending
on how many characters were requested to be read) as part of the
following
sequence:

1 2b 20 53 7e 28 20 40 2d 23 59 31 5f d

The terminal transfer on the PC does not think the transfer has been
successful
and does a number of retries. The PC terminal has the following setup:

1. Emulation vt-100
2. Preferences: default
3. Text transfers: standard flow control
4. Communications: Baud = 9600
                   8 data bits
                   1 stop bit
                   no parity
                   Xon/Xoff
                   COM2

The SG terminal 2 is setup to emulate a vt100 at 9600 baud.

The following is the basic code I am using to open and read the COM2
port.
Can someone point out where I am going wrong?

/*----------------------------------------------------------------------------------*/

#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termio.h>
#include <termios.h>

/*----------------------------------------------------------------------------------*/

long Init_port(void)
{
   struct termio tios;
   short st;
   char port_str[100];

   strcpy(port_str, "/dev/ttyd2");

   Port = open(port_str, O_RDWR | O_NONBLOCK);

   if (Port < 0)
   {
      printf("Error Opening communication port\n");
      return FALSE;
   }

   st = ioctl(Port,TCGETA,&tios);
   if (st < 0)
   {
      printf("Error Initialising port TCGETA\n");
      return FALSE;
   }

   tios.c_iflag = IGNBRK|IXON|IXOFF;
   tios.c_oflag = 0;
   tios.c_cflag = B9600|CS8|CREAD|CLOCAL;

   /* Turn off ICANON */
   tios.c_lflag = 0;

   st = ioctl(Port,TCSETAF,&tios);
   if (st < 0)
   {
      printf("Error Initialising port TCSETAF\n");
      return FALSE;
   }
   st = ioctl(Port,TCFLSH,2);
   if (st < 0)
   {
      printf("Error Initialising port TCFLSH\n");
      return FALSE;
   }
   else if( write(Port, "O",1) == 1)
  {
      printf("COM port open OK\n");
      sginap(100);
      return TRUE;
   }
   else
   {
      printf("Can't talk to port \n");
      return FALSE;
   }
}

/*----------------------------------------------------------------------------------*/

long Read_port()
{
   long i, st;
   char str[100];

/*
   st = read(Port, str, 99);
*/
   st = read(Port, str, 8);

if (st > 0)
{
printf("\nRead_port, st = %d", st);
   for (i = 0; i < st; i++)
   {
      printf("<%0x>", str[i]);
   }
   fflush(stdout);
}

    return(0);
}

/*----------------------------------------------------------------------------------*/

main(int argc, char *argv[])
{
   if (!Init_port())
      return;

   while (1)
   {
      Read_port();
   }
}

/*----------------------------------------------------------------------------------*/

Thanks,

Julia Ellery,
Senior Visual Software Engineer,
Intersim Limited, Units 7-8, Thorgate Road, Littlehampton. Sussex. UK
Tel: +44 (0)1903 733428
Fax: +44 (0)1903 730246
email: modellers++at++intersim.co.uk

=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
            Submissions: info-performer++at++sgi.com
        Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:56:31 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.