Skip to main content

MC Protocol(MELSEC Communication Protocol) implementation by Python

Project description

pymcprotocol

MC Protocol(MELSEC Communication Protocol) implementation by Python

Installation

pip install pymcprotocol

Protocol type

Now, pymcprotocol supports only mcprotocol 3E type. In the future, support 4E type. (And if possible, 1C~4C type too...)

How to use mc protocol

1. Set up PLC

First, you need to set upopen your PLC port to communicate by mcprotocol in Gxworks2 or Gxworks3.

  • Open port you want to communicate.
  • Select "Communication Data Code". If you select ascii type, you also need to set "ascii" in setaccessopt method. (default is "bainary")
  • If you would like to write in to PLC, you also have to check Enable online change

2. Connect by Python

import pymcprotocol

#If you use Q series PLC
pymc3e = pymcprotocol.Type3E()
#if you use L series PLC,
pymc3e = pymcprotocol.Type3E(plctype="L")
#if you use iQ series PLC,
pymc3e = pymcprotocol.Type3E(plctype="iQ")

#If you use ascii byte communication, (Default is "binary")
pymc3e.setaccessopt(commtype="ascii")
pymc3e.connect("192.168.1.2", 1025)

3. Send command

#read from D100 to D110
wordunits_values = pymc3e.batchread_wordunits(headdevice="D100", readsize=10)

#read from X10 to X20
bitunits_values = pymc3e.batchread_bitunits(headdevice="X10", readsize=10)

#write from D10 to D15
pymc3e.batchread_wordunits(headdevice="D10", values=[0, 10, 20, 30, 40])

#write from Y10 to Y15
pymc3e.batchread_bitunits(headdevice="Y10", values=[0, 1, 0, 1, 0])

#read "D1000", "D2000" and  dword "D3000".
word_values, dword_values = pymc3e.randomread(word_devices=["D1000", "D2000"], dword_devices=["D3000"])

#write 1000 to "D1000", 2000 to "D2000" and 655362 todword "D3000"
pymc3e.randomwrite(word_devices=["D1000", "D1002"], word_value=[1000, 2000], 
                   dword_devices=["D1004"], dword_values=[655362])

#write 1(ON) to "X0", 0(OFF) to "X10"
pymc3e.randomwrite_bitunits(bit_devices=["X0", "X10"], values=[1, 0])

pymc3e.close()

API Reference

API reference is depoloyed on here.
https://pymcprotocol.netlify.app/

Project details


Download files

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

Source Distribution

pymcprotocol-0.2.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymcprotocol-0.2.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file pymcprotocol-0.2.1.tar.gz.

File metadata

  • Download URL: pymcprotocol-0.2.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.4.72-v8+

File hashes

Hashes for pymcprotocol-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8124dfb81baf8bc1d420919171241192274de31c982d3c1e7bb4e4ca533aa5b7
MD5 cfdfb97d2a88649e92a62391bc8ecbb6
BLAKE2b-256 5b61d210484a7e8964db189d788ff51fbc69147e9d69dccdf068b32d0834bf7f

See more details on using hashes here.

File details

Details for the file pymcprotocol-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pymcprotocol-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.4.72-v8+

File hashes

Hashes for pymcprotocol-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b487690054c7f23a582ef2a5510e1adc9d02408fdefe2ed39b62a3b959235b18
MD5 f0c06b7d7f4ff55507e12c7178dc36c7
BLAKE2b-256 53a32567defef18f5bdef53f9ed40fd1b93f6fd3b0655d2c1debb121c3ffb9a8

See more details on using hashes here.

Supported by

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