473,382 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

lock access to serial port

hello group,

how to get ttyS0 serial port for exclusive access? I have a python
script that uses this device with AT commands. I need that two
instances can call simultaneosuly this python script but only one of
them gets the device. I tried fcntl.flock, it was just ignored, put
writtable file LCK..ttyS0 in /var/lock, tried ioctl (but I may not
know what are appropriate arguments), googled half a day for various
phrases, error messages etc....without success.

please help,

Andra
Mar 18 '08 #1
5 5582
kk******@gmail.com wrote:
hello group,

how to get ttyS0 serial port for exclusive access? I have a python
script that uses this device with AT commands. I need that two
instances can call simultaneosuly this python script but only one of
them gets the device. I tried fcntl.flock, it was just ignored, put
writtable file LCK..ttyS0 in /var/lock, tried ioctl (but I may not
know what are appropriate arguments), googled half a day for various
phrases, error messages etc....without success.

please help,

Andra
not sure if I understand you well, but how about a server application which
accepts 2 clients which can send messages which are output on the serial
device? The serial device access protected with a mutex while receiving
messages done in 2 threads or something.
taco
Mar 19 '08 #2
not the goal setup but the way I tried it out - a webpage to send an
sms to mobile phone. This is an php what calls a python script. A
python script opens serial device, checks for gsm network, sends a
message - on all the way I try to make sure that appropriate answers
are received from the gsm device so that I know that all is going well
(and if not - cancel it with error message).

Testing it with sending an sms from two open webpages, I normally got
that one message was sent and for the other I received "try once more,
happened that and that". But I got also an inadmissible situation -
the received sms contained also unwanted text. As far as I can realize
how to deal with it is not allowing writing to the device for two
processes simultaneously.
Andra
On 19 Marts, 11:00, taco <trala...@joepie.nlwrote:
kkadr...@gmail.com wrote:
hello group,
how to get ttyS0 serial port for exclusive access? I have a python
script that uses this device with AT commands. I need that two
instances can call simultaneosuly this python script but only one of
them gets the device. I tried fcntl.flock, it was just ignored, put
writtable file LCK..ttyS0 in /var/lock, tried ioctl (but I may not
know what are appropriate arguments), googled half a day for various
phrases, error messages etc....without success.
please help,
Andra

not sure if I understand you well, but how about a server application which
accepts 2 clients which can send messages which are output on the serial
device? The serial device access protected with a mutex while receiving
messages done in 2 threads or something.
taco
Mar 19 '08 #3
On 2008-03-18, kk******@gmail.com <kk******@gmail.comwrote:
how to get ttyS0 serial port for exclusive access? I have a python
script that uses this device with AT commands. I need that two
instances can call simultaneosuly this python script but only one of
them gets the device. I tried fcntl.flock, it was just ignored, put
writtable file LCK..ttyS0 in /var/lock,
Using a lock file is the traditional method of providing
mutually exclusive access to a serial port.
tried ioctl (but I may not know what are appropriate
arguments), googled half a day for various phrases, error
messages etc....without success.
It's unclear what "without success" means. Lockfiles have been
used for decades, and they work fine as long as all of the
applications follow the rules.

--
Grant

Mar 19 '08 #4
hmm, now it seems I get to the locking
try:
ser = serial.Serial(dev, 19200, rtscts=1, timeout=1)
if ser.isOpen():
try:
fcntl.lockf(ser,fcntl.LOCK_EX)
but get into some weirdness - trying to lock does not time out! The
script stops at this line and waits ?for ever? (it waits for 15
minutes at least, that I have tried).

Andra

not the goal setup but the way I tried it out - a webpage to send an
sms to mobile phone. This is an php what calls a python script. A
python script opens serial device, checks for gsm network, sends a
message - on all the way I try to make sure that appropriate answers
are received from the gsm device so that I know that all is going well
(and if not - cancel it with error message).

Testing it with sending an sms from two open webpages, I normally got
that one message was sent and for the other I received "try once more,
happened that and that". But I got also an inadmissible situation -
the received sms contained also unwanted text. As far as I can realize
how to deal with it is not allowing writing to the device for two
processes simultaneously.

Andra

On 19 Marts, 11:00, taco <trala...@joepie.nlwrote:
kkadr...@gmail.com wrote:
hello group,
how to get ttyS0 serial port for exclusive access? I have a python
script that uses this device with AT commands. I need that two
instances can call simultaneosuly this python script but only one of
them gets the device. I tried fcntl.flock, it was just ignored, put
writtable file LCK..ttyS0 in /var/lock, tried ioctl (but I may not
know what are appropriate arguments), googled half a day for various
phrases, error messages etc....without success.
please help,
Andra
not sure if I understand you well, but how about a server application which
accepts 2 clients which can send messages which are output on the serial
device? The serial device access protected with a mutex while receiving
messages done in 2 threads or something.
taco
Mar 19 '08 #5
I tried ready-made commands for file locking, and turned to that LCK
file just in case some permissions are wrong and that's the reason the
commands fail.

On 19 Marts, 15:43, Grant Edwards <gra...@visi.comwrote:
On 2008-03-18, kkadr...@gmail.com <kkadr...@gmail.comwrote:
how to get ttyS0 serial port for exclusive access? I have a python
script that uses this device with AT commands. I need that two
instances can call simultaneosuly this python script but only one of
them gets the device. I tried fcntl.flock, it was just ignored, put
writtable file LCK..ttyS0 in /var/lock,

Using a lock file is the traditional method of providing
mutually exclusive access to a serial port.
tried ioctl (but I may not know what are appropriate
arguments), googled half a day for various phrases, error
messages etc....without success.

It's unclear what "without success" means. *Lockfiles have been
used for decades, and they work fine as long as all of the
applications follow the rules.

--
Grant
Mar 19 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Chris | last post by:
Here's the situation: I work at a scientific institution and I have a portable electronic device which is used to take measurements. The device produces a very small amount of numerical data,...
2
by: willie | last post by:
Hi, I'm writing a program which requires the use of three serial ports and one parallel port. My application has a scanning devices on each port, which I can access fine with pyserial. ...
13
by: Al the programmer | last post by:
I need to access the serial ports on my webserver from an asp.net page. I have no problem accessing the serial ports from a windows form application, but the code doesn't work in asp.net. I have...
12
by: david.brown.0 | last post by:
I'm trying to make a Java program access a parallel port. Java's comm API does not provide me with the control I need. I need to be able to write to the data and control pins and read the status...
4
by: Frank | last post by:
Hello, how to get information about all serial ports in the PC? I use the following code, but i got only the data of the FIRST serial port. All other serial port information are not available...
5
by: Lee | last post by:
I am getting this error trying to run a win forms .net app using the .net 2.0 serial port control. This occurs when the app tries to open the port. I knwo this is some type of security access...
38
by: shussai2 | last post by:
Hi, I am trying to access Serial Port in XP. I am using Dev-C++ IDE that uses Mingw as a compiler. I just want to know how I can open up serial port on COM1 and write some data. I have searched...
1
by: RFOG | last post by:
Hello all. I'm developing a mixed Windows CE 5 and PC system APP that uses a serial port component to comunicate with other devices. App works fine under Windows CE device, but it locks in PC....
13
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.