Telling apart serial from // port


 
Thread Tools Search this Thread
Top Forums Programming Telling apart serial from // port
# 1  
Old 09-26-2003
Telling apart serial from // port

I'm writing a journal_write() function and I want it to:
- be a possible drop in replacement for write()
- write entries to the journal ;-) Could be a regular file (journal.txt), a serial printer or a // printer.
- handle printer status if needed.
fstat() tells weather or not we're dealing with a regular file. So far so good. Now, how can I tell the difference between a serial and a // port?
Once this is done, how can I get the // printer status the way stty does? (I currently do it using a non-ANSI, non-POSIX devctl() call...)

OS: QNX 6.2.1 on x86

TIA
# 2  
Old 09-26-2003
I don't know QNX, and I'm not sure what you mean by serial or // printer. Nor do I understand why you are taking such an odd approach to this.

I think it would make much more sense to be writing a journal_open() and maybe a journal_close(). A journal_write() might also make sense if you need to greatly assist with a device error such as out-of-paper. But there is a lot of one-time setup stuff for many printers.

Also a journal_open() would make the filename visable to you. With unix, you know that /dev/dsk/c0t6d0s4 is not a line printer. Unix has some naming conversions for devices. They vary from version to version...but each version has a well defined convention. I know that the whole raison d'être of fstat() and fcntrl() was to enable programs to work with files already opened by the shell before the program even started to run. But a program like:
diagnose < /dev/any/device
is not a reasonable extention of this. A system can have many line printers. If your particular line printer has trouble, how would phrase the error message without a filename?

If you want to use your approach anyway, I can think of 2 approaches that might work. The first is to get the major number of the device. You do that looking at the st_dev field in the stat structure. You want to use a macro like this:
major(statbuf.st_dev)
where major is a macro in <sys/sysmacros.h>. You would have to know which major number refers to which driver and there is no portable way to do that...well maybe searching /dev. The second approach is to assume it is a serial device. Try a serial ioctl to it. If the ioctl works, it must be serial.

Quote:
how can I get the // printer status the way stty does?
On unix, stty would only work with a serial port. So at this point, I'm confused, however, to configure a serial port on unix using posix conventions, see "man termios". Here is an example. To configure other devices under unix, you would typically use ioctl() with a request that is documented on the man page for the driver that controls the device.
# 3  
Old 09-29-2003
I meant "serial or parallel printer."
I took this approach to be the least intrusive in the client code. Replacing only 1 call (write) on the client side is better (to me)that replacing 3 calls(open, write, close). But I agree that writing a journal_open() and a journal_close() would allow to determine the kind of devices we're dealing with using the name. Then the journal_write() could take care of the details like paper-out/busy/alarm when appropriate.

I know that this isn't the best place to post QNX related problems, but it's for sure the best place for me to learn a bunch of UNIX related programming basics that are usefull in QNX. I'll try to keep it on the UNIX side!

Thank you for help and your well documented answer!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Cabling and adapters to communicate to service processor serial port from Windows PC with USB port.

Hello, I have an unloaded T5140 machine and want to access the ILOM for the first time and subsequently the network port after that., and then load Solaris 10 the final January 2011 build. The first part is what confuses me -the cabling. I am coming from a Windows machine (w/appropriate... (5 Replies)
Discussion started by: joboy
5 Replies

2. Web Development

Setup Serial Port

I need to set a serial port to 9600 7E1. How do I accomplish this? I've tried every combination, with no luck. (6 Replies)
Discussion started by: Meow613
6 Replies

3. Solaris

How to enable Serial port on ILOM, when Network Port is enabled in parallel

Hi Everyone, In my environment, I have few T5220. On the iLOM Management Card, I have both Network and Serial port are cabled, I don't have any issues while I try to connect using Network Management port, but when I try to connect the serial port for the same server which is actually connected... (3 Replies)
Discussion started by: bobby320
3 Replies

4. Shell Programming and Scripting

Need help with serial port

Hi, I have a external board connected to my serial port. I need to execute "shutdown -r now" command when system boot up. When system boots up it requires a username ans password. Then I need to run my command. I can use rc script but that is rebooting system before it asks for username and... (0 Replies)
Discussion started by: charlie.arya
0 Replies

5. AIX

Serial port in AIX

Hi, How can i configure my modem in AIX thru serial port (sa0-->tty0) I have two port serial card configured as sa0 I created tty1 which port is tty0 and which port is tty1 how can i know?? (1 Reply)
Discussion started by: pchangba
1 Replies

6. Programming

How to tell if a string to serial port has been sent

I have a need to determine when a string has been completely sent via a serial port from a standard 'C' application. The code is as follows: SerialPort_Send = open (pPortString, O_WRONLY | O_NOCTTY | O_NONBLOCK); write (SerialPort_Send, pCommandString, strlen (pCommandString)); ... (2 Replies)
Discussion started by: ExDes
2 Replies

7. Solaris

Serial port not found

Hi, I am working with solaris 9,SUN-Blade-100 and I want to communicate with the Serial port.To check whether the port is working or not.I write code and when I execute the file,then I got the output-- According to this,serial port is not found.can anyone please tell me how to configure the... (1 Reply)
Discussion started by: smartgupta
1 Replies

8. Linux

urgent......Serial port

I think my serial port(on board) is not working ...... because when I am running same code on two machines its working good....but when my system comes into picture ....it doesnt show any output comming from serial port.......... can anybody tell me how to configure my serial port.........or to... (16 Replies)
Discussion started by: arunchaudhary19
16 Replies

9. Solaris

Serial Port Datalogger

Hi, I'm using Solaris workstation with 5.4 OS. I was wondering if there's a way that I could log the data incoming and outgoing on a certain serial port. Thanks in Advance! (1 Reply)
Discussion started by: uryuu
1 Replies

10. Solaris

serial port signal

hi i am using solaris 9 on sparc . i was wondering if there was a command to control my serial interface , as to send a signal periodically every interval of time to the input of a 555 timer . thanks for your help .... (0 Replies)
Discussion started by: ppass
0 Replies
Login or Register to Ask a Question