Solved

RS-232 Port Break Charator Caused

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
windows 10 how make picture as desktop background 2 65
Smart Camera scanning and reading information 3 114
post4 challenge 28 104
How to convert MFC::CString to UTF8 wchar_t* 10 286
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 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