ts-7000
[Top] [All Lists]

[ts-7000] Re: Serial port example for TS7800

To:
Subject: [ts-7000] Re: Serial port example for TS7800
From: "JD" <>
Date: Tue, 18 Dec 2007 17:50:57 -0000
Looking further, it is failing on the tcgetattr, which in turn fails the setattr.


The test code is:

/* simple test of each of the 8 serial ports  on the TS7800 
 * John Donoghue <>
 * 18 Dec 2007
 */

#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>

/*------------------------------------------------------------*/
FILE UART_init(uint8_t portuint32_t baudrate)
{
  int hCom  = -1;
  struct termios options;
  char buffer[100];

  
switch(baudrate)
  {
    case 50:
      baudrate B50;
      break;
    case 75:
      baudrate B75;
      break;
    case 110:
      baudrate B110;
      break;
    case 134:
      baudrate B134;
      break;
    case 150:
      baudrate B150;
      break;
    case 200:
      baudrate B200;
      break;
    case 300:
      baudrate B300;
      break;
    case 600:
      baudrate B600;
      break;
    case 1200:
      baudrate B1200;
      break;
    case 1800:
      baudrate B1800;
      break;
    case 4800:
      baudrate B2400;
      break;
    case 9600:
      baudrate B9600;
      break;
    case 19200:
      baudrate B19200;
      break;
    case 38400:
      baudrate B38400;
      break;
    case 57600:
      baudrate B57600;
      break;
    case 115200:
      baudrate B115200;
      break;
    case 230400:
      baudrate B230400;
      break;
    default:
      baudrate B38400;
      break;
  }

  
sprintf(buffer,"/dev/ttyS%d", (port));

  
printf("try open %d : '%s'\r\n", (int)portbuffer);

  
hCom open(bufferO_RDWR O_NOCTTY /*| O_NDELAY*/); 
  if (hCom 0
  {
    fprintf(stderr,"OpenSerial: Couldnt open %s:"buffer);
    fflush(stderr);
    perror(NULL);
    return NULL;
  }    
  /* save current serial port settings */
  
if(tcgetattr(hCom,&options) != 0)
  {
    perror("OpenSerial: tcgetattr: ");
  }

  
cfsetispeed(&optionsbaudrate);
  cfsetospeed(&optionsbaudrate);

  
options.c_cflag &= ~PARENB/* no parity */
  
options.c_cflag &= ~CSTOPB/* 1 stop bit */

  
options.c_cflag &= ~CSIZE/* mask out all size bits */
  
options.c_cflag |= CS8;    /* 8 bits */

  
options.c_cflag |= (CLOCAL CREAD); /* enable recieve and local control*/

  
options.c_iflag &= ~CRTSCTS/* No RTS/CTS */

  
options.c_iflag &= ~(IXON IXOFF IXANY); /* No Xon/Xoff */

  
options.c_oflag &= ~OPOST/* no output processing  */
  
options.c_oflag &= ~ONLCR/* dont convert linefeeds */

  
options.c_lflag &= ~(ICANON|ECHOE|ECHO|ISIG); /* not line oriented */

  
options.c_cc[VTIME]    = 1000;  
  options.c_cc[VMIN]     = 1;   /* dont wait for a byte */
    
  
tcflush(hComTCIFLUSH);

  
if(tcsetattr(hCom,TCSANOW,&options)!=0)
  {
    perror("OpenSerial: tcsetattr");
    close(hCom);
    return NULL;
  }

  
return fdopen(hCom"r+");
}

/*------------------------------------------------------------*/
int main()
{
  int i;
  FILE com;

  
for(i=0;i<10;i++)
  {
    sleep(1);
    printf("Open port %d \r\n"i);
    com UART_init(i9600);
    if(com)
    {
      fprintf(com"Com port %d\r\n"i);
      fflush(com);
      fclose(com);
    }
  }
  return 0;
}

__._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: =Email Delivery: Digest | m("yahoogroups.com?subject","ts-7000-fullfeatured");=Change Delivery Format: Fully Featured">Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | =Unsubscribe

__,_._,___
<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU