Serial Ports - locking them, checking if they are open


 
Thread Tools Search this Thread
Top Forums Programming Serial Ports - locking them, checking if they are open
# 1  
Old 02-11-2005
Serial Ports - locking them, checking if they are open

Hi, I'm trying to fix up some serial code that was given to me by a coworker no longer on the project. Problem is, when the program is running and reading the port, I can take away the port by doing a cu command in another terminal window. When I release the cu, the program crashes, I think because it is trying to read a closed port.

I would like to know how to lock the port so the cu will not take it. One of our subcontractors has a program that tells me DEVICE LOCKED if I try the cu trick. I'd like to do that for my port. Does this involve the flock() call?

As a alternative, I'd like to be able to check if the serial port is open before I attempt a read. I'd also like to check if the port is already open before I call my original open. This seems like it would be solved with the stat() call, but I'm not seeing how to make it work.

I appreciate any advice/ideas. FYI, I am working on Solaris 7 and Solaris 8 (have to be compatible with both).

Thanks,
Kate
# 2  
Old 02-14-2005
As I recall, Solaris does enforce mandatory locking.
Here is a sample by diddling the permission bits:
Code:
int fd;
mode_t perms=PERM_FILE;
perms|=S_ISGID;
fd=open("filename",O_CREATE | O_RDWR, perms);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Checking open ports in a system

Hi, There are two servers which needs to be connected via the port number 1521 from a remote server. This is the port config in the first server : L28tstream1 : # netstat -tulpn | grep 1521 tcp 0 0 10.67.26.183:1521 0.0.0.0:* LISTEN ... (2 Replies)
Discussion started by: anaigini45
2 Replies

2. OS X (Apple)

Renaming serial ports in unix

Hello everyone, this is my first post and I am by no means a unix expert, so I hope I explain my issue well. I'm on a mac (mac mini), 10.7. My question is about serial port names. I have an arduino microcontroller plugged in via usb, and every time the computer is shut down it gives the... (0 Replies)
Discussion started by: superliminal
0 Replies

3. HP-UX

Help with serial ports.

Hi, This is my first post here. I would like to ask: how to connect the barcode scanner to the serial port? What are the names in the system (in / dev) and serialport1 serialport0? Please help with this. Regards. (2 Replies)
Discussion started by: ftwojtek
2 Replies

4. AIX

locking down unused or unwanted ports in AIX

We have a system and we have modified the /etc/ind.conf and the /etc/services and the /etc/rc.tcpip file to turn off specific applications. I need to know what is the correct procedure for locking down unused ports that still appear to be in a listen mode even... (1 Reply)
Discussion started by: admaix
1 Replies

5. Programming

Locking issue with serial port

Hi, In my application,I need to monitor the devices connected through serial port in solaris sparc 9 OS.I used c and java code for it and I am able to do the same but the problem comes when I restart the system and the open my application and try to monitor it.but I m unable to monitor the... (2 Replies)
Discussion started by: smartgupta
2 Replies

6. Shell Programming and Scripting

PERL:controlling serial ports ?

Is it possible to write a perl program to controll the serial port? e.g. What iam trying to do, for a challenge is create a box with two lights. red and green, connect to a serial port and have a perl program to give me the options to turn on the red light or green light. Is this possilbe, can... (1 Reply)
Discussion started by: perleo
1 Replies

7. UNIX for Dummies Questions & Answers

Resetting hung serial ports and peripheral devices.

Working in SunOS 2.6 without the GUI, I am trying to find out what command line syntax I can use to reset the serial port. I have also been curious how to reset peripheral devices without having to reboot the machine. If anyone has a cheat sheet for that, that would be great! (1 Reply)
Discussion started by: mcherry
1 Replies

8. Programming

Reading incoming data in serial ports

Hi every body, i have the following problem : I need to read incoming data from a serial port, this port has connected a weigth device to it that send the weigth and i need to read this data to my aplication, i had this problem in Window Enviroment and i resolve with a "C" routine, but in Unix... (1 Reply)
Discussion started by: jricardorm
1 Replies

9. UNIX for Dummies Questions & Answers

Installing a modem on a serial accelerator ports

I had been using a modem installed on a Digi accelerator port to dial in to an SCO open server r5 server. On monday it quit working and I realy don't know how it was installed and configured. I have tested the modem on a PC and it works. The port the modem is connected to is ttyB06 and I have... (1 Reply)
Discussion started by: kikkin
1 Replies

10. UNIX for Dummies Questions & Answers

Serial Ports, wacom tablet under unix

Hi, I'm new to the boards and don't know all that much about unix either. I do have quite a specific question though and i hope someone can help me with it... i'm going crazy...i've been trying to set up a wacom tablet on my unix box. i've don't it before but it was taken away and the os... (3 Replies)
Discussion started by: Salwey
3 Replies
Login or Register to Ask a Question