pymcprotocol API referencess

pymcprotocol.type3e module

This file implements mcprotocol 3E type communication.

pymcprotocol.type3e.isascii(text)[source]

check text is all ascii character. Python 3.6 does not support str.isascii()

pymcprotocol.type3e.twos_comp(val, mode='short')[source]

compute the 2’s complement of int value val

pymcprotocol.type3e.get_device_number(device)[source]

Extract device number.

Ex: “D1000” → “1000”

“X0x1A” → “0x1A

exception pymcprotocol.type3e.CommTypeError[source]

Bases: Exception

Communication type error. Communication type must be “binary” or “ascii”

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

exception pymcprotocol.type3e.PLCTypeError[source]

Bases: Exception

PLC type error. PLC type must be”Q”, “L”, “QnA”, “iQ-L”, “iQ-R”

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

class pymcprotocol.type3e.Type3E(plctype='Q')[source]

Bases: object

mcprotocol 3E communication class.

plctype

connect PLC type. “Q”, “L”, “QnA”, “iQ-L”, “iQ-R”

Type

str

commtype

communication type. “binary” or “ascii”. (Default: “binary”)

Type

str

subheader

Subheader for mc protocol

Type

int

network

network No. of an access target. (0<= network <= 255)

Type

int

pc

network module station No. of an access target. (0<= pc <= 255)

Type

int

dest_moduleio

When accessing a multidrop connection station via network, specify the start input/output number of a multidrop connection source module. the CPU module of the multiple CPU system and redundant system.

Type

int

dest_modulesta

accessing a multidrop connection station via network, specify the station No. of aaccess target module

Type

int

timer

time to raise Timeout error(/250msec). default=4(1sec) If PLC elapsed this time, PLC returns Timeout answer. Note: python socket timeout is always set timer+1sec. To recieve Timeout answer.

Type

int

plctype = 'Q'
commtype = 'binary'
subheader = 20480
network = 0
pc = 255
dest_moduleio = 1023
dest_modulesta = 0
timer = 4
soc_timeout = 2
__init__(plctype='Q')[source]

Constructor

connect(ip, port)[source]

Connect to PLC

Parameters
  • ip (str) – ip address(IPV4) to connect PLC

  • port (int) – port number of connect PLC

  • timeout (float) – timeout second in communication

close()[source]

Close connection

setaccessopt(commtype=None, network=None, pc=None, dest_moduleio=None, dest_modulesta=None, timer_sec=None)[source]

Set mc protocol access option.

Parameters
  • commtype (str) – communication type. “binary” or “ascii”. (Default: “binary”)

  • network (int) – network No. of an access target. (0<= network <= 255)

  • pc (int) – network module station No. of an access target. (0<= pc <= 255)

  • dest_moduleio (int) – When accessing a multidrop connection station via network, specify the start input/output number of a multidrop connection source module. the CPU module of the multiple CPU system and redundant system.

  • dest_modulesta (int) – accessing a multidrop connection station via network, specify the station No. of aaccess target module

  • timer_sec (int) – Time out to return Timeout Error from PLC. MC protocol time is per 250msec, but for ease, setaccessopt requires per sec. Socket time out is set timer_sec + 1 sec.

batchread_wordunits(headdevice, readsize)[source]

batch read in word units.

Parameters
  • headdevice (str) – Read head device. (ex: “D1000”)

  • readsize (int) – Number of read device points

Returns

word units value list

Return type

wordunits_values(list[int])

batchread_bitunits(headdevice, readsize)[source]

batch read in bit units.

Parameters
  • headdevice (str) – Read head device. (ex: “X1”)

  • size (int) – Number of read device points

Returns

bit units value(0 or 1) list

Return type

bitunits_values(list[int])

batchwrite_wordunits(headdevice, values)[source]

batch write in word units.

Parameters
  • headdevice (str) – Write head device. (ex: “D1000”)

  • values (list[int]) – Write values.

batchwrite_bitunits(headdevice, values)[source]

batch read in bit units.

Parameters
  • headdevice (str) – Write head device. (ex: “X10”)

  • values (list[int]) – Write values. each value must be 0 or 1. 0 is OFF, 1 is ON.

randomread(word_devices, dword_devices)[source]

read word units and dword units randomly. Moniter condition does not support.

Parameters
  • word_devices (list[str]) – Read device word units. (ex: [“D1000”, “D1010”])

  • dword_devices (list[str]) – Read device dword units. (ex: [“D1000”, “D1012”])

Returns

word units value list dword_values(list[int]): dword units value list

Return type

word_values(list[int])

randomwrite(word_devices, word_values, dword_devices, dword_values)[source]

write word units and dword units randomly.

Parameters
  • word_devices (list[str]) – Write word devices. (ex: [“D1000”, “D1020”])

  • word_values (list[int]) – Values for each word devices. (ex: [100, 200])

  • dword_devices (list[str]) – Write dword devices. (ex: [“D1000”, “D1020”])

  • dword_values (list[int]) – Values for each dword devices. (ex: [100, 200])

randomwrite_bitunits(bit_devices, values)[source]

write bit units randomly.

Parameters
  • bit_devices (list[str]) – Write bit devices. (ex: [“X10”, “X20”])

  • values (list[int]) – Write values. each value must be 0 or 1. 0 is OFF, 1 is ON.

remote_run(clear_mode, force_exec=False)[source]

Run PLC

Parameters
  • clear_mode (int) – Clear mode. 0: does not clear. 1: clear except latch device. 2: clear all.

  • force_exec (bool) – Force to execute if PLC is operated remotely by other device.

remote_stop()[source]

Stop remotely.

remote_pause(force_exec=False)[source]

pause PLC remotely.

Parameters

force_exec (bool) – Force to execute if PLC is operated remotely by other device.

remote_latchclear()[source]

Clear latch remotely. PLC must be stop when use this command.

remote_reset()[source]

Reset remotely. PLC must be stop when use this command.

read_cputype()[source]

Read CPU type

Returns

CPU type CPU code(str): CPU code (4 length number)

Return type

CPU type(str)

remote_unlock(password='', request_input=False)[source]

Unlock PLC by inputting password.

Parameters
  • password (str) – Remote password

  • request_input (bool) – If true, require inputting password. If false, use password.

remote_lock(password='', request_input=False)[source]

Lock PLC by inputting password.

Parameters
  • password (str) – Remote password

  • request_input (bool) – If true, require inputting password. If false, use password.

echo_test(echo_data)[source]

Do echo test. Send data and answer data should be same.

Parameters

echo_data (str) – send data to PLC

Returns

answer data length from PLC answer_data(str): answer data from PLC

Return type

answer_len(int)

pymcprotocol.type4e module

This file implements mcprotocol 4E type communication.

class pymcprotocol.type4e.Type4E(plctype='Q')[source]

Bases: pymcprotocol.type3e.Type3E

mcprotocol 4E communication class. Type 4e is almost same to Type 3E. Difference is only subheader. So, Changed self.subhear and self._make_senddata()

Arributes:

subheader(int): Subheader for mc protocol subheaderserial(int): Subheader serial for mc protocol to identify client

subheader = 21504
subheaderserial = 0
set_subheaderserial(subheaderserial)[source]

Change subheader serial

Parameters

subheaderserial (int) – Subheader serial to change

pymcprotocol.mcprotocolerror module

This file is collection of mcprotocol error.

exception pymcprotocol.mcprotocolerror.MCProtocolError(errorcode)[source]

Bases: Exception

devicecode error. Device is not exsist.

plctype

PLC type. “Q”, “L” or “iQ”

Type

str

devicename

devicename. (ex: “Q”, “P”, both of them does not support mcprotocol.)

Type

str

__init__(errorcode)[source]

Initialize self. See help(type(self)) for accurate signature.

exception pymcprotocol.mcprotocolerror.UnsupportedComandError[source]

Bases: Exception

This command is not supported by the module you connected.

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

pymcprotocol.mcprotocolerror.check_mcprotocol_error(status)[source]

Check mc protocol command error. If errot exist(status != 0), raise Error.

Module contents