pm2cd.core package

class pm2cd.core.Communication(ip_address: str, port: int = 7777, timeout_sec: float = 3.0, encoding: str = 'ascii', logger=None, log_level: str = 'INFO')[source]

Bases: object

PMシリーズ用のTCP通信層。

TCPソケットの生成、接続、CR+LF単位の送受信、切断までをこのクラス内で 完結させる。

通常運転中に発生し得る通信失敗はログへ原因を記録し、False または None を返す。コンストラクタ引数の不正など、戻り値では表現できない 呼び出し側の誤りは例外とする。

close() → bool[source]

通信を終了する。

connect() → bool[source]

TCP接続する。

Returns:

接続済み、または接続に成功した場合は True。 接続に失敗した場合は False。

disconnect() → bool[source]

TCP接続を切断する。

property encoding

encoding を返す。

property ip_address

ip_address を返す。

is_connected() → bool[source]

TCP 接続状態を取得する。

Returns:

接続中の場合は True、それ以外は False。

property port

port を返す。

query(command: str) → str | None[source]

コマンドを送信し、その応答を1件受信する。

receive() → str | None[source]

CR+LF単位で装置応答を1件受信する。

send(command: str) → bool[source]

CR+LFを付加してコマンドを送信する。

property timeout_sec

timeout_sec を返す。

exception pm2cd.core.CommunicationError[source]

Bases: MotorControlError

通信処理に失敗した場合の例外。

exception pm2cd.core.MotorControlError[source]

Bases: Exception

モーター制御に関する基底例外。

class pm2cd.core.MotorStatus(motor: int, channel: int, raw: str, remote_local: str, direction: str, ls_status: int, mcc_status: int, position: int, motor_status: str, is_busy: bool, is_driving: bool, is_accelerating: bool, is_decelerating: bool, has_command_error: bool, limit_stop_received: bool, slow_stop_received: bool, emergency_stop_received: bool, rotation_state: int, cw_ls: bool, ccw_ls: bool, hp_ls: bool, hold_off: bool, legacy_status_bits: int)[source]

Bases: object

STS? 応答中の1軸分の状態を保持する。

ccw_ls: bool
channel: int
cw_ls: bool
direction: str
emergency_stop_received: bool
has_command_error: bool
hold_off: bool
hp_ls: bool
is_accelerating: bool
is_busy: bool
is_decelerating: bool
is_driving: bool
legacy_status_bits: int
limit_stop_received: bool
ls_status: int
mcc_status: int
motor: int
motor_status: str
position: int
raw: str
remote_local: str
rotation_state: int
slow_stop_received: bool
exception pm2cd.core.ProtocolError[source]

Bases: MotorControlError

装置応答を解釈できない場合の例外。

Submodules

pm2cd.core.communication_tcp module

class pm2cd.core.communication_tcp.Communication(ip_address: str, port: int = 7777, timeout_sec: float = 3.0, encoding: str = 'ascii', logger=None, log_level: str = 'INFO')[source]

Bases: object

PMシリーズ用のTCP通信層。

TCPソケットの生成、接続、CR+LF単位の送受信、切断までをこのクラス内で 完結させる。

通常運転中に発生し得る通信失敗はログへ原因を記録し、False または None を返す。コンストラクタ引数の不正など、戻り値では表現できない 呼び出し側の誤りは例外とする。

close() → bool[source]

通信を終了する。

connect() → bool[source]

TCP接続する。

Returns:

接続済み、または接続に成功した場合は True。 接続に失敗した場合は False。

disconnect() → bool[source]

TCP接続を切断する。

property encoding

encoding を返す。

property ip_address

ip_address を返す。

is_connected() → bool[source]

TCP 接続状態を取得する。

Returns:

接続中の場合は True、それ以外は False。

property port

port を返す。

query(command: str) → str | None[source]

コマンドを送信し、その応答を1件受信する。

receive() → str | None[source]

CR+LF単位で装置応答を1件受信する。

send(command: str) → bool[source]

CR+LFを付加してコマンドを送信する。

property timeout_sec

timeout_sec を返す。

pm2cd.core.communication_tcp.main() → None[source]

Communication の基本的な送受信例を実行する。

実機の IP アドレスに変更してから、パッケージのモジュールとして実行する。 VER? を送信し、CR+LF で区切られた装置応答を 1 件受信する。

Returns:

None。

pm2cd.core.controller_status module

class pm2cd.core.controller_status.ControllerStatus(raw: str, remote_local: str, stopped_motor_count: int, is_remote: bool, can_start: bool)[source]

Bases: object

STQ? の REMOTE/LOCAL と停止可能数を保持する。

can_start: bool
is_remote: bool
raw: str
remote_local: str
stopped_motor_count: int
pm2cd.core.controller_status.parse_controller_status(raw: str) → ControllerStatus | None[source]

STQ? 応答を解析する。

pm2cd.core.data module

PM2CD / PM2C-06A 固有データ。

pm2cd.core.errors module

exception pm2cd.core.errors.CommunicationError[source]

Bases: MotorControlError

通信処理に失敗した場合の例外。

exception pm2cd.core.errors.MotorControlError[source]

Bases: Exception

モーター制御に関する基底例外。

exception pm2cd.core.errors.ProtocolError[source]

Bases: MotorControlError

装置応答を解釈できない場合の例外。

pm2cd.core.home_status module

class pm2cd.core.home_status.HomeStatus(raw: str, found: bool, found_direction: str, auto_start_direction: str)[source]

Bases: object

SETHP?x の 0XYZ 応答を保持する。

auto_start_direction: str
found: bool
found_direction: str
raw: str
pm2cd.core.home_status.parse_home_status(raw: str) → HomeStatus | None[source]

SETHP?x 応答を解析する。

pm2cd.core.limit_status module

class pm2cd.core.limit_status.LimitStatus(motor: int, channel: int, raw: str, hard_status: int, soft_status: int, hard_cw: bool, hard_ccw: bool, hard_hp: bool, soft_cw: bool, soft_ccw: bool)[source]

Bases: object

HDSTLS? 応答中の1軸分のリミット状態を保持する。

channel: int
property hard: List[bool]

ハードウェアLS現在状態を [CW, CCW, HP] で返す。

hard_ccw: bool
hard_cw: bool
hard_hp: bool
hard_status: int
motor: int
raw: str
property soft: List[bool]

ソフトウェアLS現在状態を [CW, CCW] で返す。

soft_ccw: bool
soft_cw: bool
soft_status: int
pm2cd.core.limit_status.parse_limit_status_all(raw: str) → List[LimitStatus] | None[source]

PM2CD の HDSTLS? 2ch応答 abHHSS を解析する。

pm2cd.core.limit_switch_setting module

class pm2cd.core.limit_switch_setting.LimitSwitchSetting(raw: str, digital_limit_enabled: bool, raw_hp_enabled: bool, raw_ccw_enabled: bool, raw_cw_enabled: bool, hp_nc: bool, raw_ccw_nc: bool, raw_cw_nc: bool)[source]

Bases: object

SETLS?x の DYYY0yyy 応答を保持する。

PM□C-06 シリーズでは、書き込み時の HP LS enable は常に 1 であり、 CCW LS の enable / 接点仕様が CW LS にも適用される。 読み出し応答そのものはマニュアル記載どおり DYYY0yyy として保持する。

property ccw_enabled: bool

PM□C-06 の実効 CCW LS enable を返す。

property ccw_nc: bool

PM□C-06 の実効 CCW LS 接点仕様を返す。

property cw_enabled: bool

PM□C-06 では CCW 設定が適用される CW LS enable を返す。

property cw_nc: bool

PM□C-06 では CCW 設定が適用される CW LS 接点仕様を返す。

digital_limit_enabled: bool
property hp_enabled: bool

PM□C-06 で実効的に常時有効な HP LS enable を返す。

hp_nc: bool
raw: str
raw_ccw_enabled: bool
raw_ccw_nc: bool
raw_cw_enabled: bool
raw_cw_nc: bool
raw_hp_enabled: bool
to_write_raw() → str[source]

PM□C-06 用 D1YY0yyy 書き込み値を生成する。

SETLS?x の読み出し値をそのまま再送せず、装置仕様に従って HP LS enable を 1 に固定し、CCW の enable / 接点仕様を CW にも 適用した canonical な書き込み値を返す。

pm2cd.core.limit_switch_setting.parse_limit_switch_setting(raw: str) → LimitSwitchSetting | None[source]

SETLS?x の DYYY0yyy 応答を解析する。

8文字の位置は順に、 D, HP-enable, CCW-enable, CW-enable, 0, HP-contact, CCW-contact, CW-contact。

読み出しでは DYYY0yyy をそのまま解析し、PM□C-06 固有の 実効値への解釈は LimitSwitchSetting の property が担当する。

pm2cd.core.limit_switch_setting.set_digital_limit(setting: LimitSwitchSetting, enabled: bool) → str | None[source]

digital limit enable を変更した PM□C-06 書き込み値を返す。

pm2cd.core.limit_switch_setting.set_hardware_limit(setting: LimitSwitchSetting, enabled: bool) → str | None[source]

CW/CCW hardware LS enable を同時変更した書き込み値を返す。

pm2cd.core.limit_switch_setting.set_hardware_limit_normally_closed(setting: LimitSwitchSetting, side: str, normally_closed: bool) → str | None[source]

hardware LS の接点仕様を変更した PM□C-06 書き込み値を返す。

HP は独立して変更する。CW または CCW を指定した場合は、 PM□C-06 の仕様に従い CCW/CW を同じ接点仕様へ変更する。

pm2cd.core.motor_setting module

class pm2cd.core.motor_setting.MotorSetting(raw: str, drive_enabled: bool, hold_mode: int, drive_mode: int, output_mode: int)[source]

Bases: object

SETMT?x のモーター設定を保持する。

drive_enabled: bool
drive_mode: int
hold_mode: int
output_mode: int
raw: str
pm2cd.core.motor_setting.parse_motor_setting(raw: str) → MotorSetting | None[source]

SETMT?x の ABCD 応答を解析する。

pm2cd.core.motor_status module

class pm2cd.core.motor_status.MotorStatus(motor: int, channel: int, raw: str, remote_local: str, direction: str, ls_status: int, mcc_status: int, position: int, motor_status: str, is_busy: bool, is_driving: bool, is_accelerating: bool, is_decelerating: bool, has_command_error: bool, limit_stop_received: bool, slow_stop_received: bool, emergency_stop_received: bool, rotation_state: int, cw_ls: bool, ccw_ls: bool, hp_ls: bool, hold_off: bool, legacy_status_bits: int)[source]

Bases: object

STS? 応答中の1軸分の状態を保持する。

ccw_ls: bool
channel: int
cw_ls: bool
direction: str
emergency_stop_received: bool
has_command_error: bool
hold_off: bool
hp_ls: bool
is_accelerating: bool
is_busy: bool
is_decelerating: bool
is_driving: bool
legacy_status_bits: int
limit_stop_received: bool
ls_status: int
mcc_status: int
motor: int
motor_status: str
position: int
raw: str
remote_local: str
rotation_state: int
slow_stop_received: bool
pm2cd.core.motor_status.parse_motor_status_all(raw: str) → List[MotorStatus] | None[source]

PM4C-06A互換の STS? 応答を解析する。

pm2cd.core.stop_mode module

class pm2cd.core.stop_mode.StopMode(raw: str, panel_fast: bool, limit_fast: bool)[source]

Bases: object

STOPMD?x の停止モード設定を保持する。

limit_fast: bool
panel_fast: bool
raw: str
pm2cd.core.stop_mode.parse_stop_mode(raw: str) → StopMode | None[source]

STOPMD?x の AB 応答を解析する。

pm2cd.core.version_info module

class pm2cd.core.version_info.VersionInfo(raw: str)[source]

Bases: object

VER? 応答を解析して保持する。

property date

date を返す。

property is_pm2cd: bool
property is_valid

is_valid を返す。

property model

model を返す。

normalized_model() → str[source]
property raw

raw を返す。

property version

version を返す。

pm2cd.core.version_info.main() → None[source]

VersionInfo の解析例を実行する。

Returns:

None。