Re: How do I monitor the serial CTS line via C programmatically?

2003-01-16 Thread Giorgos Keramidas
On 2003-01-16 15:44, Paul Hamilton <[EMAIL PROTECTED]> wrote:
> Thanks Giorgos!
>
> I needed to know the function used to access the Serial ports under FreeBSD.
> Your program compiles, but generates the following error msg when run:
>
> test_prog: ioctl: Inappropriate ioctl for device
>
> Thanks to the ioctl 'tip', I researched around, and found that the
> serial port needed opening, so this is the finished code (just in
> case someone else needs it):

Ah, of course.  When I tested it, I used:

% ./a.out < /dev/cuaa1

so the shell did the open() for me :)

You're right, of course...

> [snip C source]


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



RE: How do I monitor the serial CTS line via C programmatically?

2003-01-15 Thread Paul Hamilton
Thanks Giorgos!

I needed to know the function used to access the Serial ports under FreeBSD.

Your program compiles, but generates the following error msg when run:


test_prog: ioctl: Inappropriate ioctl for device

Thanks to the ioctl 'tip', I researched around, and found that the serial
port needed opening, so this is the finished code (just in case someone else
needs it):


#include 
#include 
#include 
#include  /*Originally it was termio.h*/
#include 
#include 

int
main(void)
{
int bits;
int last;
int dcf_dev;

if((dcf_dev = open("/dev/cuaa1", O_RDWR|O_NOCTTY)) < 0)
{
perror("open /dev/cuaa0");
return (-1);
}


if (ioctl(dcf_dev, TIOCMGET, &bits) == -1)
err(1, "ioctl");
last = bits & TIOCM_CTS;
printf("CTS %s.\n", last ? "on" : "off");

while (1) {
if (ioctl(dcf_dev, TIOCMGET, &bits) == -1)
err(1, "ioctl");
if ((last ^ (bits & TIOCM_CTS)) != 0) {
last = bits & TIOCM_CTS;
printf("CTS %s.\n", last ? "on" : "off");
}
usleep(10);
}

return (0);
}

Brilliant!!  :-)

Thanks for that!

Cheers,

Paul Hamilton

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Giorgos
Keramidas
Sent: Wednesday, 15 January 2003 7:21 PM
To: Paul Hamilton
Cc: [EMAIL PROTECTED]
Subject: Re: How do I monitor the serial CTS line via C
programmatically?


On 2003-01-15 18:26, [EMAIL PROTECTED] (Paul Hamilton) wrote:
> I have been trying to monitor the serial CTS line.  I would like to
> log the fact that the CTS has changed state (active/non-active).
>
> I have been trying to adapt some Linux programs, but am having
> problems with adapting the POSIX TIOCMGET function.
>
> Is there a FreeBSD way?

You'd have to poll using ioctl(fd, TIOCMGET, &int) and detect CTS
changes by checking the TIOCM_CTS bit in the returned value.  The
following (untested) sample program should be easy to adapt to your
needs.  When TIOCM_CTS changes from on to off or vice versa, the
program should print the change.

#include 

#include 
#include 

int
main(void)
{
int bits;
int last;

if (ioctl(0, TIOCMGET, &bits) == -1)
err(1, "ioctl");
last = bits & TIOCM_CTS;
printf("CTS %s.\n", last ? "on" : "off");

while (1) {
if (ioctl(0, TIOCMGET, &bits) == -1)
err(1, "ioctl");
if ((last ^ (bits & TIOCM_CTS)) != 0) {
last = bits & TIOCM_CTS;
printf("CTS %s.\n", last ? "on" : "off");
}
usleep(10);
}

return (0);
}


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How do I monitor the serial CTS line via C programmatically?

2003-01-15 Thread Giorgos Keramidas
On 2003-01-15 18:26, [EMAIL PROTECTED] (Paul Hamilton) wrote:
> I have been trying to monitor the serial CTS line.  I would like to
> log the fact that the CTS has changed state (active/non-active).
>
> I have been trying to adapt some Linux programs, but am having
> problems with adapting the POSIX TIOCMGET function.
>
> Is there a FreeBSD way?

You'd have to poll using ioctl(fd, TIOCMGET, &int) and detect CTS
changes by checking the TIOCM_CTS bit in the returned value.  The
following (untested) sample program should be easy to adapt to your
needs.  When TIOCM_CTS changes from on to off or vice versa, the
program should print the change.

#include 

#include 
#include 

int
main(void)
{
int bits;
int last;

if (ioctl(0, TIOCMGET, &bits) == -1)
err(1, "ioctl");
last = bits & TIOCM_CTS;
printf("CTS %s.\n", last ? "on" : "off");

while (1) {
if (ioctl(0, TIOCMGET, &bits) == -1)
err(1, "ioctl");
if ((last ^ (bits & TIOCM_CTS)) != 0) {
last = bits & TIOCM_CTS;
printf("CTS %s.\n", last ? "on" : "off");
}
usleep(10);
}

return (0);
}


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



How do I monitor the serial CTS line via C programmatically?

2003-01-15 Thread Paul Hamilton
Hi,

I have been trying to monitor the serial CTS line.  I would like to log the
fact that the CTS has changed state (active/non-active).

I have been trying to adapt some Linux programs, but am having problems with
adapting the POSIX TIOCMGET function.

Is there a FreeBSD way?

Cheers,

Paul Hamilton



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message