Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I know whether my device is attached to tty?

Posted on 1997-08-20
6
Medium Priority
?
395 Views
Last Modified: 2013-12-26
I'm using AIX Ver 4.1 on IBM server.
In a C program, how do I know whether my device is attached to tty?  My device is asynchronous.

If my device is not attached, my program will hang on the following sentence : read(port, buf, 22);

I've tried using the following sentences but to no avail:
      port = open(PORT, O_RDWR | O_NODELAY);
and
     port = open(PORT, O_RDWR | O_NONBLOCK);


Thanks!


0
Comment
Question by:Rita060297
[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
6 Comments
 
LVL 4

Accepted Solution

by:
rembo earned 60 total points
ID: 1294491


What sort of device is it?  Take a look at the man page
for the specific device and there should be an ioctl()
that you can use to determine device readiness.  The open()
system call often just sets a flag and never accesses
the device.  
0
 

Author Comment

by:Rita060297
ID: 1294492
The device is a digital clock which will send me the current time when
I send it a certain character.

I've tried ioctl with FIONREAD but I receive 0 for the number of bytes available to be read on the file descriptor when device is attached and device not attached.

Are there any alternatives?
0
 
LVL 84

Expert Comment

by:ozo
ID: 1294493
So it's a tty device?
Can you try an ioctl TIOCMGET?
Can you do a select with a timeout?

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:aditya070797
ID: 1294494
I don't understand the question completely, but I think you can
try using:
----------------------------------
struct termios *termios_ptr;
...
rv = tcgetattr(port, termios_ptr);
----------------------------------
If you get an error (rv == -1) and errno is set to ENOTTY,
then the port is not a tty.
0
 

Author Comment

by:Rita060297
ID: 1294495
I tried ioctl(port, TIOCMGET, &nbyte) and received the following results :

nbyte = 70 when device attached to port
nbyte = 6 when device not attached to port

I've found out that TIOCMGET defines the following :
Gets all modem bits.  The argument to this command is a pointer to an
integer where the current state of the modem status lines is stored.
Which modem status and modem control lines are supported depends on the capabilities of the hardware and the hardware's device driver.

Question :
(1) How do I know what 70 or 6 means?
(2) Can I use 70 and 6 as a guide for deteching the attached or non-attached device?  It seems to be consistent during my numerous testing.


0
 
LVL 84

Expert Comment

by:ozo
ID: 1294496
You should be able to find the definition of the bits in /usr/include/sys/termios.h
It looks like 6 is DTR+RTS, and 0106 is DTR+RTS+CD (carrier detect)


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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

604 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