Solved

RS-232 Port Break Charator Caused

Posted on 1997-09-04
3
254 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 83
How to know only "File created" with EventLog 3 29
sameEnds challenge 3 107
maxBlock challenge 30 101
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now