473,765 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5626
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...@joepi e.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(d ev, 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...@joepi e.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.co mwrote:
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
12755
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, about 10 to 15 numbers per measurement. This operation is performed frequently and I would like to implement an automatic solution that moves this data across a windows network and into the fields of an Access database application. The device...
2
13195
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. However, I'm unsure of how exactly I should be designing the program, I thought I could use threading to start class: class scanner(Thread): def __init__(self,port):
13
4833
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 been told it is not possible to access the serial ports from asp.net. The application is used to control custom hardware. The hardware is connected to a PC through serial ports. Our customer wants to control the hardware from a remote...
12
8631
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 pins. Any Java people know a good solution? I'm trying to use JNI and create my own library, but building the library gives me these errors: ld: warning: cannot find entry symbol _start; defaulting to 0000000008048094 ParallelPort.o: In...
4
17816
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 with this code sample: ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from WIN32_SerialPort");
5
55781
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 problem but I have no clue where to fix it. Help....
38
9665
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 quite a bit over the web and could not find anything useful. I don't want to use Visual C++ or Cygwin, linux, etc. If any of you guys have some little tid bit of code that would be great to look at.
1
4036
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. If it is under debugger, locks Visual Studio too, and if it running alone, it gives the exception AppName: buttonpanelpc.exe AppVer: 1.0.0.0 AppStamp:450fbf8a
13
6209
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 am sending a short message to a group of embedded boxes daisy chained via the serial port. When I send a 'global' message, all the connected units should reply with their Id and Ack in this format '0 Ack' To be certain that I didn't miss a...
0
9393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9946
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.