Skip to content

Using Multiple pyads instances on linux #423

Answered by chrisbeardy
cisk asked this question in Q&A
Discussion options

You must be logged in to vote

Try something similar to this:

import threading
import time

import pyads

def connect_and_read():
    with pyads.Connection("39.22.134.140.1.1", 851, "192.168.56.105") as plc:
        print(plc.get_local_address())
        time.sleep(3)


if __name__ == '__main__':  
    thread_1 = threading.Thread(target=connect_and_read)
    thread_2 = threading.Thread(target=connect_and_read)
    thread_1.start()
    thread_2.start()

You should get an output like this:

<AmsAddress 172.16.1.105.1.1:32908>
<AmsAddress 172.16.1.105.1.1:32909>

Showing different ports have been opened. You can alos create two instances of the Connection class to achieve the same thing e.g.

plc_1 = pyads.Connection("39.22.…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by chrisbeardy
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #314 on September 17, 2024 08:47.