[Python] Is there a problem with the connection code to PLC?

Discussão em 'Python' iniciado por Stack, Junho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I try to connect to Mitsubishi QJ71E71 PLC with python code.

    I already set the GX_works2's open setting.

    But when i connect to PLC with below code, it got a timed out error.

    import pymcprotocol

    pymc3e = pymcprotocol.Type3E() # Q series
    pymc3e.setaccessopt(commtype = "binary", network = 1, pc = 18)
    is_con = True

    while is_con:
    try:
    pymc3e.connect("192.100.13.34", 5002)
    print("conn succ")
    quit()
    except Exception as e:
    print(f"conn fail -> {e}")
    break


    And Below is GX_works2's open setting. [​IMG]

    Note

    • The connection between 192.100.13.5 and PLC(192.100.13.34) works well. It is already set a few years ago.
    • I know that mitshubishi plc need source port when connect to plc. So, i've been fix the code that packet included source port, But time out error is still occur. (I checked the connection packet by wireshark. and I checked source port is 33213.)

    Continue reading...

Compartilhe esta Página