Jump to content

Need advice on locking serial port


Trax
 Share

Recommended Posts

   I have written a program that reads a serial port to obtain data. The problem is that the serial port is not multi-user. Only one person can read it at any given time. I am looking for a way to "lock" the serial port when one person is reading it so that others trying to access it will know it is "busy" and wait until it frees up. Is there a "standard" way of doing this? 

Link to comment
Share on other sites

if your program is the only one accessing the port, and only one instance of your program can use the port at any given time, then you can apply a locking mechanism like this:

NOTE: although the title mentions locking files, this method is applicable for practically any object.

 

 

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

It is odd. I have a Lantronix Device out in Production. It is what actually connects RS232 on one side and TCP/IP on the other. So various computers can access this "virtual" serial port at the same time but the Lantronix Box will only allow one of this computer to connect at any given time.

Link to comment
Share on other sites

1 hour ago, Trax said:

So various computers can access this "virtual" serial port at the same time but the Lantronix Box will only allow one of this computer to connect at any given time.

It is getting clearer now.  Are all those computers use the same application to access this virtual port ?  Is it written in AutoIt ?  

Link to comment
Share on other sites

hard to say without details on device type and your environment. No details in your question so quarantee that you get vague answers

What happens if 2 users read at the same time? Why would it be a problem?

If user A reads something whats the purpose of having user B reading the device? Shouldn't all the information come together thats read from the device?

looking here https://www.lantronix.com/resources/networking-tutorials/device-servers-tutorial/ gives an idea how things can look.

developer wiki seems not to be working and their forum seems not having any acitivity

  • Are all endusers on their pc starting your program from a central network location?
    • If so you could write a "lock" file in the folder when a users starts reading and you clean it when finished.
    • You could have your program start with tcp/ip udf functions to communicate with each other
    • You could make 1 PC dedicated for the communication and the other computers communicate with your central computer that dispatches

 

 

Link to comment
Share on other sites

We have same situation. Our solution is that a service is always connected to the device and the users only connect to the service.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...