Skip to main content

Python connect to PLC LS

Project description

Python connect to PLC LS by TCP XGT Server

LS protocol(LS electric Communication Protocol) implementation by Python. LS protocol enables you to operate PLC from computer.

import library

from PyXGT.LS import plc_ls

connect to PLC

conn = plc_ls("192.168.1.10",2004) #PLC LS IP and port: 2004 (TCP XGT server)

write device

val = conn.command("XGB", "write", "bit", "M70","1")# Write ON to Bit M70

val = conn.command("XGB", "write", "bit", "M70") or conn.command("XGB", "write", "bit", "M70","0") # Write OFF to Bit M70

val = conn.command("XGB", "write", "byte", "D100","20") # Write 20 to 100th Byte(int8) D50( beacause 1 D= int16)

val = conn.command("XGB", "write", "word", "D100","1") # write 1 to Word(int16) D100

val = conn.command("XGB", "write", "dword", "D50","1") # Write 1 to 50th doubleWord(int32)( D100-D101)

val = conn.command("XGB", "write", "lword", "D25","1") # Write 1 to 25th long(int64) ( D100-D101-d102-d103)

read device

val = conn.command("XGB", "read", "bit", "M70") # read Bit M70 return [1] or [0]

val = conn.command("XGB", "read", "byte", "D100") # read 100th Byte(int8) D50( beacause 1 D= int16)

val = conn.command("XGB", "read", "word", "D100) # read Word(int16) D100

val = conn.command("XGB", "read", "dword", "D50) # read 50th doubleWord(int32)( D100-D101)

val = conn.command("XGB", "read", "lword", "D25) # read 25th long(int64) ( D100-D101-d102-d103)

write multi device

val = conn.command("XGB", "write", "bit", "M70,M71,M72","1,0,1")# Write ON to Bit M70, OFF M71 and ON M72

val = conn.command("XGB", "write", "bit", "M70,M71,M72") # write off all 3 bits M70,M71,M72

.......................

read multi device

val = conn.command("XGB", "read", "bit", "M70,M71,M72") # read 3 Bits M70,M71,M72 return [1,0,1]

.............................................

Project details


Release history Release notifications | RSS feed

This version

1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyXGT-1.1.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

PyXGT-1.1-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page