Searching \ for '[EE] Interrupt on RX for PCs' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/microchip/ints.htm?key=interrupt
Search entire site for: 'Interrupt on RX for PCs'.

Exact match. Not showing close matches.
PICList Thread
'[EE] Interrupt on RX for PCs'
2009\05\19@015732 by solarwind

picon face
Hey all, does anyone know how to write an ISR in C for an interrupt on
RX for the PC's UART? Windows or Linux, I don't care. I just need the
PC to act as another node in my token RS485 network so I can debug
things and get the protocol working properly.

-- [ solarwind ] -- http://solar-blogg.blogspot.com/

2009\05\19@083333 by Harold Hallikainen

face
flavicon
face

> Hey all, does anyone know how to write an ISR in C for an interrupt on
> RX for the PC's UART? Windows or Linux, I don't care. I just need the
> PC to act as another node in my token RS485 network so I can debug
> things and get the protocol working properly.

Don't know how to do what you've asked, but, based on a suggestion from
here, I'm using RealTerm (http://realterm.sourceforge.net/) to debug a 485
bus. It can do a hex display and hex capture to a file. I used the hex
capture to a text file, then had a macro in Open Office insert crlf at the
beginning of each packet (based on start of packet aa55). This is a master
slave system, so I also had the macro break the text into request/response
pairs based on the addresses following the aa55.

Harold

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

2009\05\19@083759 by Michael Rigby-Jones

flavicon
face


> -----Original Message-----
> From: spam_OUTpiclist-bouncesTakeThisOuTspammit.edu [.....piclist-bouncesKILLspamspam@spam@mit.edu] On
Behalf
> Of solarwind
> Sent: 19 May 2009 06:57
> To: Microcontroller discussion list - Public.
> Subject: [EE] Interrupt on RX for PCs
>
> Hey all, does anyone know how to write an ISR in C for an interrupt on
> RX for the PC's UART? Windows or Linux, I don't care. I just need the
> PC to act as another node in my token RS485 network so I can debug
> things and get the protocol working properly.

You don't generally write interrupt handlers under Windows, servicing
the UART interrupt and putting received data into a buffer or
transmitting data from a buffer is already handled by the operating
system.  It's a completely different way of working to using a small
micro, and quite hard to get your head around it if you've not done much
Win32 programming.

To get something working quickly, choose one of the rapid development
languages that include a COM control, e.g. VB, Delphi or even C++
builder if you can pick up a copy.

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

2009\05\19@090338 by Ruben Jönsson

flavicon
face
If you are willing to try C# on windows you can download the C# express version
for free which includes a class for the serial port that works well.

One thing you must be aware of is that windows is not a real time os which you
will notice if you are going to control the RS485 transmitter with DTR or RTS
(half duplex). There is no signal (event) from the UART that tells your program
when the whole packet is sent and when you must switch off the transmitter. I
have done this using the multimedia timers but still have to add around 50ms
before a node replies to a command from the PC otherwise the node may reply
before the PC has had time to disable its transmitter (collision!!!) and the PC
will never see the reply.

However, if you build a bus with dominant/recessive states the bus turnarounds
will be handled for you automatically plus it will make collision detection
work (on the PC also).

I hav also written an ISR in C for DOS applications. It doesn't behave quite
well under windows though. I can send you the code for it if you like.

/Ruben


> Hey all, does anyone know how to write an ISR in C for an interrupt on
> RX for the PC's UART? Windows or Linux, I don't care. I just need the
> PC to act as another node in my token RS485 network so I can debug
> things and get the protocol working properly.
>
> -- [ solarwind ] -- http://solar-blogg.blogspot.com/
==============================
Ruben Jönsson
AB Liros Electronic
Box 9124, 200 39 Malmö, Sweden
TEL INT +46 40142078
FAX INT +46 40947388
rubenspamKILLspampp.sbbs.se
==============================

2009\05\19@105016 by Bob Ammerman

picon face
Solarwind wrote:
>> Hey all, does anyone know how to write an ISR in C for an interrupt on
>> RX for the PC's UART? Windows or Linux, I don't care. I just need the
>> PC to act as another node in my token RS485 network so I can debug
>> things and get the protocol working properly.

Serial ports don't work that way on PC's. You don't have control at that
low a level. Windows has a specialized API to read and write to serial
ports. In Linux you should be able to open the port as a regular file using
its pathname "/dev/xxxx".

-- Bob Ammerman
RAm Systems

2009\05\19@110900 by Harold Hallikainen

face
flavicon
face

> Solarwind wrote:
>>> Hey all, does anyone know how to write an ISR in C for an interrupt on
>>> RX for the PC's UART? Windows or Linux, I don't care. I just need the
>>> PC to act as another node in my token RS485 network so I can debug
>>> things and get the protocol working properly.
>
> Serial ports don't work that way on PC's. You don't have control at that
> low a level. Windows has a specialized API to read and write to serial
> ports. In Linux you should be able to open the port as a regular file
> using
> its pathname "/dev/xxxx".
>
> -- Bob Ammerman
> RAm Systems

It seems like you'd have to be the root user to get direct access to
hardware under Linux, wouldn't you? I've had trouble trying to access my
cellphone as a USB modem as a regular user.

Another approach would be to write something under DOS, where you have
direct access to hardware. Also, if this is all the PC program is doing,
it seems that polling could be fast enough, instead of having to deal with
interrupts. Finally, for debug, I'd use realterm instead of trying to
write anything.

Harold



--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

2009\05\19@122945 by John Coppens

flavicon
face
On Tue, 19 May 2009 08:17:53 -0700 (PDT)
"Harold Hallikainen" <.....haroldKILLspamspam.....hallikainen.org> wrote:

> It seems like you'd have to be the root user to get direct access to
> hardware under Linux, wouldn't you? I've had trouble trying to access my
> cellphone as a USB modem as a regular user.

You don't need (and probably don't even want) direct access.

Normal I/O is already buffered and interrupt served under Linux. So, you
can use a library like GIOChannel to install a high-level 'handler on
reception' in a C program, which can react on characters o complete
lines. Works very well. It's also possible to generate calls to another
function when 'ready to transmit', or if errors appear (format/overrun
errors and such).

John

2009\05\19@125442 by Mark Rages

face picon face
On Tue, May 19, 2009 at 12:56 AM, solarwind <EraseMEx.solarwind.xspam_OUTspamTakeThisOuTgmail.com> wrote:

> Hey all, does anyone know how to write an ISR in C for an interrupt on
> RX for the PC's UART? Windows or Linux, I don't care. I just need the
> PC to act as another node in my token RS485 network so I can debug
> things and get the protocol working properly.
>


Interrupts are called "signals" in POSIX-speak.

Here is an example program that receives characters on a serial port.
http://vivara.net/software/o_async.c

Compile it with "gcc o_async.c" and run it "./a.out /dev/ttyS0" for
example.  Connect a loopback jumper to the serial port (bridge pins 2 & 3).

In the mainloop, it just sleeps and occasionally writes a character to the
serial port.  In the interrupt (signal) service routine, it prints the
characters received from the serial port.

(It's not recommended to print stuff from a signal handler, but I do it in
this toy example.  It would be better to add characters to a buffer and set
a flag for the mainloop to check the buffer.)

Regards,
Mark
markrages@gmail
--
Mark Rages, Engineer
Midwest Telecine LLC
markragesspamspam_OUTmidwesttelecine.com

2009\05\19@130010 by Mark Rages

face picon face
On Tue, May 19, 2009 at 10:17 AM, Harold Hallikainen <@spam@haroldKILLspamspamhallikainen.org
{Quote hidden}

This is somewhat distribution dependent.  In Ubuntu, members of the
"dialout" group can access serial ports.  So, add your user to "dialout" in
/etc/group and stop taking the name of root in vain...

You could also add a udev rule to make a certain device only accessible to a
certain user.  But udev is Linux-specific AFAIK, and one of the subsystems
that seems to get completely rearranged every few years.

Regards,
Mark
markrages@gmail
--
Mark Rages, Engineer
Midwest Telecine LLC
KILLspammarkragesKILLspamspammidwesttelecine.com

2009\05\19@131242 by Peter Onion

flavicon
face
On Tue, 2009-05-19 at 12:00 -0500, Mark Rages wrote:

>
> This is somewhat distribution dependent.  In Ubuntu, members of the
> "dialout" group can access serial ports.
It gives them access to the serial port device in /dev which is not what
was being asked about.

PeterO


2009\05\19@135307 by Mark Rages

face picon face
On Tue, May 19, 2009 at 12:12 PM, Peter Onion <RemoveMEPeter.OnionTakeThisOuTspambtinternet.com>wrote:

> On Tue, 2009-05-19 at 12:00 -0500, Mark Rages wrote:
>
> >
> > This is somewhat distribution dependent.  In Ubuntu, members of the
> > "dialout" group can access serial ports.
> It gives them access to the serial port device in /dev which is not what
> was being asked about.
>
> PeterO
>

Low-level access is through the /dev file, no?  Did you see my example code?

--
Mark Rages, Engineer
Midwest Telecine LLC
spamBeGonemarkragesspamBeGonespammidwesttelecine.com

2009\05\19@140536 by Herbert Graf

picon face
On Tue, 2009-05-19 at 01:56 -0400, solarwind wrote:

> Hey all, does anyone know how to write an ISR in C for an interrupt on
> RX for the PC's UART? Windows or Linux, I don't care. I just need the
> PC to act as another node in my token RS485 network so I can debug
> things and get the protocol working properly.


ISR? That's from the days when OS's didn't properly support the UART
(i.e. DOS).

These days you use the OS to do the dirty work.

For example, this is a section of code (compiled under Ubuntu but should
be rather portable)
that opens a serial port and reads and writes from it,
you can use it as a template (this code is NOT complete, I've removed
non relevant bits to save space):

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

#define BAUDRATE B38400          
/* change this definition for the correct port */
#define MODEMDEVICE "/dev/ttyS0"
#define _POSIX_SOURCE 1 /* POSIX compliant source */

#define LINE_BUFFER_SIZE 160

FILE *mail_message;


int main ()
{
       char line_buffer [LINE_BUFFER_SIZE+1];
       int line_buffer_index = 0;
       char char_buf;
       int fd;
       ssize_t returned_bytes;
       int i;
       
       line_buffer [LINE_BUFFER_SIZE] = 0;
       mail_message = NULL;        

       struct termios oldtio,newtio;
       
       fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
       if (fd <0)
       {
                       perror(MODEMDEVICE);
                       exit(-1);
       }
       else
               printf("Open port OK.\n");
       
       tcgetattr(fd,&oldtio); /* save current serial port settings */
       bzero(&newtio, sizeof(newtio)); /* clear struct for new port settings
*/
       
       newtio.c_cflag = CS8 | CLOCAL | CREAD;
       
       newtio.c_iflag = IGNPAR | ICRNL;
       
       /*Raw output.*/
       newtio.c_oflag = 0;
       
       /*ICANON  : enable canonical input
       disable all echo functionality, and don't send signals to calling
program*/
       newtio.c_lflag = ICANON;
       
       /*initialize all control characters
       default values can be found in /usr/include/termios.h, and are given
       in the comments, but we don't need them here*/
       newtio.c_cc[VINTR]    = 0;     /* Ctrl-c */
       newtio.c_cc[VQUIT]    = 0;     /* Ctrl-\ */
       newtio.c_cc[VERASE]   = 0;     /* del */
       newtio.c_cc[VKILL]    = 0;     /* @ */
       newtio.c_cc[VEOF]     = 4;     /* Ctrl-d */
       newtio.c_cc[VTIME]    = 0;     /* inter-character timer unused */
       newtio.c_cc[VMIN]     = 1;     /* blocking read until 1 character
       arrives */
       newtio.c_cc[VSWTC]    = 0;     /* '\0' */
       newtio.c_cc[VSTART]   = 0;     /* Ctrl-q */
       newtio.c_cc[VSTOP]    = 0;     /* Ctrl-s */
       newtio.c_cc[VSUSP]    = 0;     /* Ctrl-z */
       newtio.c_cc[VEOL]     = 0;     /* '\0' */
       newtio.c_cc[VREPRINT] = 0;     /* Ctrl-r */
       newtio.c_cc[VDISCARD] = 0;     /* Ctrl-u */
       newtio.c_cc[VWERASE]  = 0;     /* Ctrl-w */
       newtio.c_cc[VLNEXT]   = 0;     /* Ctrl-v */
       newtio.c_cc[VEOL2]    = 0;     /* '\0' */
       
       tcflush(fd, TCIFLUSH);
       tcsetattr(fd,TCSANOW,&newtio);
       
       write(fd, "ATZ\r", 4);
       printf ("Sent reset\n");
       system ("sleep 1");
       write(fd, "AT#CID=1\r", 9);
       printf("Sent CID set\n");
       system ("sleep 1");
       while (1)
       {
               returned_bytes = read (fd, &char_buf, 1);
               if (isASCII(char_buf))
                       printf ("Returned byte: %c %d\n", char_buf, char_buf);
               else
                       printf ("Returned byte: . %d\n", char_buf);
               if (line_buffer_index != LINE_BUFFER_SIZE)
                       line_buffer[line_buffer_index++] = char_buf;
               else
               {
                       printf ("Warning: Line buffer overflow, reseting index!\n");
                       line_buffer_index = 0;
                       line_buffer[line_buffer_index++] = char_buf;
               }
               
       }
}

TTYL

More... (looser matching)
- Last day of these posts
- In 2009 , 2010 only
- Today
- New search...