Solved

RS-232 Port Break Charator Caused

Posted on 1997-09-04
3
316 Views
Last Modified: 2013-12-26
Hi, All,

I am writing a short program which interfaces to the little Motorola 68hc11 processor.  I need to detect break charators (RxD stucked to constant zero) and cause an interrupt signal to the main process.

According to man termio:

   If IGNBRK is set, the break condition is ignored.  Therefore the break
      condition cannot be read by any process.  If IGNBRK is clear and
      BRKINT is set, the break condition flushes both the input and output
      queues and, if the terminal is the controlling terminal of a
      foreground process group, the break condition generates a single
      SIGINT signal to that foreground process group.  If neither IGNBRK nor
      BRKINT is set, a break condition is read as a single \0 character, or


 I put the statement:
      t_ptr.c_iflag = BRKINT
in the following code to enable the interrupt.  

I also use a scope to make sure I indeed put a constant zero (+12v) onto the RxD line.  The problem I am having is that no matter what I do, the break charactor on the RxD line will _never_ cause an interrupt.  Just to verify the interrupt is still working, I use the alarm() function to cause an interrupt every 5 second.  The alarm() function works.  Secondly, if I ran the following program, I can make the SIGINT signal triggered by hitting ctlr-C.  Second ctlr-C will terminate the execution.

I am using a Ultrasparc and runing SunOS 5.5.1.  

Please help and thanks.

Jian Zhang
DSC Communications Corp.
Petaluma, California

Here is the source code:

------------------cut here------------------

#include
#include
#include
#include

#include
#include

#include
#include

unsigned char  bin_wt [2048];
int        fd;

void alarm_hdlr();
void sig_handlr();

main(int argc, char * argv[]) {


  const  baud_rate = B1800;
  const sync_char = 0xff;


  unsigned char in_char;
  int    i, j;

  int    n, wrt_n, rd_n;

  FILE*  file_ptr;

  struct termios t_ptr;

  char* str_line;
  char* str_load;
  char* a_str;

  unsigned char  bin_rd [2048];
  unsigned int srec_len;

  str_line   = (char*)malloc (1024);
  str_load   = (char*)malloc (3000);
  a_str      = (char*)malloc (3000);

  bin_wt [0] = sync_char;
  fd = open("/dev/ttyb", O_RDWR);

  //t_ptr.c_iflag = BRKINT | INPCK;
  t_ptr.c_iflag = BRKINT;
  //t_ptr.c_iflag = PARMRK;
  t_ptr.c_oflag = 0;
  t_ptr.c_cflag = CS8 | CREAD | CLOCAL | CSTOPB;
  t_ptr.c_lflag = 0;
  t_ptr.c_cc[VTIME] = t_ptr.c_cc[VMIN] = 0;

  cfsetispeed(&t_ptr, baud_rate);
  cfsetospeed(&t_ptr, baud_rate);
  tcsetattr(fd, TCSANOW, &t_ptr);

  if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
    printf ("enable signal\n");
    signal(SIGINT, sig_handlr);
    }

  signal(SIGALRM, alarm_hdlr);
  alarm(5);

  while (1) {
    if (read(fd, &in_char, 1)) {
      printf ("received char = %x\n", in_char);
      }
    }

  close(fd);
  fclose(file_ptr);

  exit (0);
  }

void alarm_hdlr() {
  signal(SIGALRM,  alarm_hdlr);
  alarm(5);
  printf ("inside alarm_hdlr\n");
  }

void sig_handlr() {
  printf ("inside sig_handlr().\n");
  write(fd, bin_wt, 1);
  }

0
Comment
Question by:jian_zhang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:jian_zhang
ID: 1294777
Edited text of question
0
 

Accepted Solution

by:
hotlava earned 200 total points
ID: 1294778
There seem to be several things missing from the code.  When changing ioctl flags, one would normally read the existing flags, and just set or clear the particular flag that they aare interested in.  This means that you do not have to know what all of the IO flags do, but just the ones you are interested in.  So my first recommendation is to change the flag setting code to a "get flags", clear IGNBRK and set BRKINT, "set flags".  And my second recommendation is to ensure that you are the controlling terminal of a foreground process group, like the man page says.  To do this is think you would use setpgrp - although I may be wrong here so you'll have to do some reading, but even so, the code you posted appears to make no effort to create a process group, so may be another possible cause of your problems.
0
 

Author Comment

by:jian_zhang
ID: 1294779
Hi, hotlava and other experts,

The above answer did help me to get an interrupt (signal) when a break char is received.  But the interrupt only occurs when the RxD line changes from low->high.  It seams to me that the COM port is waiting for a valid '0x00' with valid stop bit appears on RxD line when it generates the interrupt.  My application requires my code detects a high->low transition on RxD instead.  Any comment on this?

Thanks again.

Jian Zhang
DSC Communications
jzhang@optilink.dsccc.com
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question