SSV Logo

DIL/NetPC ADNP/1486


In-deep

Download
Serial2.c
Serial HOWTO

Contact us
Sales
Support


Back to Top Page


DNP/EVA2: Using the COM3 Port from Linux

The following C source codes is a simple example for using the DNP/EVA2 COM3 serial port from Linux. The Linux device name for this port is /dev/ttyS2. Please note: The ADNP/1486 needs a BIOS with COM3 support for running this sample code on a DNP/EVA2.

// SERIAL2.C
// Test program for DNP/EVA2-COM3-Port (/dev/ttyS2)
// Vers. 1.01 / 20-Jan-2002 / kdw@ist1.de

#include ‹sys/types.h›
#include ‹sys/stat.h›
#include ‹fcntl.h›
#include ‹termios.h›
#include ‹stdio.h›
#include ‹string.h›

#define LINESPEED B115200

int main (void)
{
   int fd,                                // Handle for POSIX I/O
       i;
   struct termios otios, ntios;           // Terminal I/O structures
   char buf[255];                         // Buffer

   // Open /dev/ttyS2 (COM3 port of DNP/EVA2)...

   fd= open ("/dev/ttyS2", O_RDWR | O_NOCTTY );
   if (fd < 0) {
      perror ("/dev/ttyS2");
      exit (-1);
   }

   // Save current /dev/ttyS2 setup

   tcgetattr (fd, &otios);

   // Define new setup for /dev/ttyS2...

   bzero (&ntios, sizeof (ntios));
   ntios.c_cflag= LINESPEED | CRTSCTS | CS8 | CLOCAL | CREAD;
   ntios.c_cc[VTIME]= 0;      // No timeouts
   ntios.c_cc[VMIN]= 1;       // Wait for one char (and not more)

   // Write new setup to /dev/ttyS2...

   tcflush (fd, TCIFLUSH);
   tcsetattr (fd, TCSANOW, &ntios);

   // Send sign-in message to terminal program on /dev/ttyS2

   sprintf (buf, "Test Program for DNP/EVA2 COM3 (/dev/ttyS2)\n\r\n\r");
   write (fd, buf, strlen (buf));

   // Wait for char from /dev/ttyS2. Display all char's.

   while (1) {
      i= read (fd, buf, 255);              // Receive from /dev/ttyS2
      buf[i]= 0;
      printf ("%s", buf);
      fflush (stdout);
      write (fd, buf, strlen (buf));       // Send echo over /dev/ttyS2

      // Make new line if necessary

      if (buf[0] == '\r') {
         printf ("\n");
         sprintf (buf, "\n");
         write (fd, buf, strlen (buf));
      }
   }

   // Restore old setup for /dev/ttyS2...

   tcsetattr (fd, TCSANOW, &otios);
   exit (1);
}
      

SSV EMBEDDED SYSTEMS. Board Level Products. File: dnp0021.htm, Last Update: 07.Jan.2012
Copyight (c) 1996 - 2012 SSV and KDW. All rights reserved. webmaster@ist1.de