PMC-Mシリーズ Pythonサンプルプログラム

ソフトウェアマニュアルにPythonのサンプルコードは記載しておりません。また、ソフトウェアパックにもPythonのサンプルプログラムは含まれておりませんので、Pythonで使用される場合は以下を参考にしてください。

サンプルプログラム

汎用デジタル入力/出力

サンプルプログラムのDIOと同等の内容です。 サンプルプログラムのDIOや、ソフトウェアマニュアルの[サンプルプログラム]-[DIO]とあわせてご確認ください。

import platform
import ctypes

# エラーコード(戻り値)
PMCM_RESULT_SUCCESS = 0             # 正常終了

# 軸指定
PMCM_AXIS_X = 0x0001
PMCM_AXIS_Y = 0x0002

# SetSensorConfig,GetSensorConfig
PMCM_LOGIC = 0
PMCM_EL_FUNC = 1
PMCM_SD_FUNC = 2
PMCM_SD_ACTIVE = 3
PMCM_ORG_FUNC = 4
PMCM_EZ_FUNC = 5
PMCM_EZ_COUNT = 6
PMCM_ALM_FUNC = 7
PMCM_LTC_FUNC = 8
PMCM_PCS_FUNC = 9
PMCM_SENS_FILTER = 10

# DLL
pf = platform.system()
if pf == 'Windows':
    pmcm = ctypes.windll.PmcM
elif pf == 'Linux':
    pmcm = ctypes.CDLL('libpmcm.so')


def main():
    class AppData:
        INVALID_ID = 9999
        board_id = INVALID_ID

    while True:
        print('1: open')
        print('2: setting')
        print('3: input')
        print('4: output')
        print('5: close')
        print('9: exit')
        try:
            chosen = int(input('> '))
        except ValueError:
            chosen = 0
        if chosen == 1:
            open_board(AppData)
        elif chosen == 2:
            setting(AppData)
        elif chosen == 3:
            dio_input(AppData)
        elif chosen == 4:
            dio_output(AppData)
        elif chosen == 5:
            close_board(AppData)
        elif chosen == 9:
            exit_app(AppData)
            break
        else:
            pass
    return


def open_board(AppData):
    if AppData.board_id != AppData.INVALID_ID:
        print('Already open')
        return
    try:
        board_id = int(input('board id> '))
    except ValueError:
        board_id = AppData.INVALID_ID
    result = pmcm.PmcmOpen(board_id, b'PMC-M2C-U')
    if result == PMCM_RESULT_SUCCESS:
        print('PmcmOpen succeeded')
    else:
        print('PmcmOpen error {}'.format(result))
        board_id = AppData.INVALID_ID
    AppData.board_id = board_id
    return


def setting(AppData):
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    # 汎用デジタル入力として使用する場合はINPとPCSをオンで検知(負論理)に設定
    result = pmcm.PmcmSetSensorConfig(AppData.board_id, axis, PMCM_LOGIC, 0x30)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetSensorConfig error {}'.format(result))
        return
    # 汎用デジタル入力として使用する場合はLTCを立ち下がりエッジに設定
    result = pmcm.PmcmSetSensorConfig(AppData.board_id, axis, PMCM_LTC_FUNC, 0)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetSensorConfig error {}'.format(result))
        return
    return


def dio_input(AppData):
    try:
        input_no = int(input('input number> '))
    except ValueError:
        input_no = 99
    input_data = ctypes.c_ubyte()
    result = pmcm.PmcmDioInput(AppData.board_id, ctypes.byref(input_data),
                               input_no, 1)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmDioInput error {}'.format(result))
        return
    print('IN{}: {}'.format(input_no, input_data.value))
    # 2点以上の入力をおこなう場合は以下を参考にしてください
    # IN0-4の入力
    # input_data = (ctypes.c_ubyte * 5)()
    # result = pmcm.PmcmDioInput(AppData.board_id, ctypes.byref(input_data),
    #                            0, 5)
    # if result != PMCM_RESULT_SUCCESS:
    #     print('PmcmDioInput error {}'.format(result))
    #     return
    # for i, d in enumerate(input_data):
    #     print('IN{}: {}'.format(i, d))
    return


def dio_output(AppData):
    try:
        output_no = int(input('output number> '))
    except ValueError:
        output_no = 99
    try:
        output_data = ctypes.c_ubyte(int(input('output data> ')))
    except ValueError:
        output_data = ctypes.c_ubyte(99)
    result = pmcm.PmcmDioOutput(AppData.board_id, ctypes.byref(output_data),
                                output_no, 1)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmDioOutput error {}'.format(result))
        return
    # 2点以上の出力をおこなう場合は以下を参考にしてください
    # OUT0-3の出力
    # output_data = (ctypes.c_ubyte * 4)(0, 1, 0, 1)
    # result = pmcm.PmcmDioOutput(AppData.board_id, ctypes.byref(output_data),
    #                             0, 4)
    # if result != PMCM_RESULT_SUCCESS:
    #     print('PmcmDioOutput error {}'.format(result))
    #     return
    return


def close_board(AppData):
    result = pmcm.PmcmClose(AppData.board_id)
    if result:
        AppData.board_id = AppData.INVALID_ID
        print('PmcmClose succeeded')
    else:
        print('PmcmClose falied')
    return


def exit_app(AppData):
    pmcm.PmcmClose(AppData.board_id)
    return


if __name__ == '__main__':
    main()

連続動作

サンプルプログラムのMotion1と同等の内容です。 サンプルプログラムのMotion1や、ソフトウェアマニュアルの[サンプルプログラム]-[Motion1]とあわせてご確認ください。

import platform
import ctypes

# エラーコード(戻り値)
PMCM_RESULT_SUCCESS = 0             # 正常終了

# 軸指定
PMCM_AXIS_X = 0x0001
PMCM_AXIS_Y = 0x0002

# SetMotion(Line),GetMotion(Line)
PMCM_JOG = 0
PMCM_ORG = 1
PMCM_PTP = 2
PMCM_LINE = 3

PMCM_ACC_LINEAR = 0
PMCM_ACC_SCURVE = 1

PMCM_DIR_CW = 1
PMCM_DIR_CCW = -1

PMCM_CONST = 0
PMCM_CONST_DEC = 1
PMCM_ACC_DEC = 2

# StopMotion
PMCM_DEC_STOP = 0
PMCM_IMMEDIATE_STOP = 1

# ChangeSpeed
PMCM_CHG_IMM_LOW_SPEED = 0
PMCM_CHG_IMM_SPEED = 1
PMCM_CHG_DEC_LOW_SPEED = 2
PMCM_CHG_ACC_SPEED = 3
PMCM_CHG_NEW_SPEED = 4

# SetSensorConfig,GetSensorConfig
PMCM_LOGIC = 0
PMCM_EL_FUNC = 1
PMCM_SD_FUNC = 2
PMCM_SD_ACTIVE = 3
PMCM_ORG_FUNC = 4
PMCM_EZ_FUNC = 5
PMCM_EZ_COUNT = 6
PMCM_ALM_FUNC = 7
PMCM_LTC_FUNC = 8
PMCM_PCS_FUNC = 9
PMCM_SENS_FILTER = 10

# SetPulseConfig,GetPulseConfig
PMCM_PULSE_OUT = 0
PMCM_DIR_WAIT = 1
PMCM_FIN_TIMING = 2
PMCM_FH_REVISE = 3

# SetSynchroConfig,GetSynchroConfig
PMCM_SYNC_START_MODE = 0
PMCM_SYNC_START = 1
PMCM_SYNC_SIG_START = 2
PMCM_SYNC_STOP_MODE = 3

# SetSynchroOut,GetSynchroOut
PMCM_SYNC_OUT_MODE = 0

# SetComparatorConfig,GetComparatorConfig
PMCM_COMP_COUNTER = 0
PMCM_COMP_ENCODER = 1

# SetLatchConfig,GetLatchConfig
PMCM_COUNTER_LATCH_LTC = 0
PMCM_COUNTER_LATCH_ORG = 1
PMCM_COUNTER_CLEAR_LATCH = 2
PMCM_ENCODER_LATCH_LTC = 3
PMCM_ENCODER_LATCH_ORG = 4
PMCM_ENCODER_CLEAR_LATCH = 5

# SetEncoderConfig,GetEncoderConfig
PMCM_ENCODER_MODE = 0
PMCM_ENCODER_DIR = 1
PMCM_ENCODER_FILTER = 2

# SetErcConfig,GetErcConfig
PMCM_ERC_LOGIC = 0
PMCM_ERC_AUTOOUT_1 = 1
PMCM_ERC_AUTOOUT_2 = 2
PMCM_ERC_WIDTH = 3
PMCM_ERC_OFF_TIMER = 4
PMCM_ERC_SIG_ON = 5
PMCM_ERC_SIG_OFF = 6

# SetEventMask,GetEventMask
PMCM_EVENT_STOP = 0
PMCM_EVENT_STATE = 1

# PmcmGetStatus
PMCM_BUSY = 0
PMCM_SIG_STATUS = 1

# コンパレータ設定
class COMPPMCM(ctypes.Structure):
    _fields_ = [('wConfig', ctypes.c_ushort),       # 比較条件
                ('lCount', ctypes.c_int)]           # 比較データ

# 動作パラメータ設定(SetMotion,GetMotion)
class MOTIONPMCM(ctypes.Structure):
    _fields_ = [('wMoveMode', ctypes.c_ushort),     # 動作モード
                ('wStartMode', ctypes.c_ushort),    # 起動モード
                ('fSpeedRate', ctypes.c_float),     # 速度倍率
                ('wAccDecMode', ctypes.c_ushort),   # 加減速モード
                ('fLowSpeed', ctypes.c_float),      # 起動速度
                ('fSpeed', ctypes.c_float),         # 移動速度
                ('wAccTime', ctypes.c_ushort),      # 加速時間
                ('wDecTime', ctypes.c_ushort),      # 減速時間
                ('fSAccSpeed', ctypes.c_float),     # 加速S字区間
                ('fSDecSpeed', ctypes.c_float),     # 減速S字区間
                ('lSlowdown', ctypes.c_int),        # スローダウンポイント
                ('lStep', ctypes.c_int),            # 移動パルス数,移動方向
                ('bAbsolutePtp', ctypes.c_int)]     # 絶対座標指定

# 動作パラメータ設定(SetMotionLine,GetMotionLine)
class MOTIONLINEPMCM(ctypes.Structure):
    _fields_ = [('wStartMode', ctypes.c_ushort),    # 起動モード
                ('fSpeedRate', ctypes.c_float),     # 速度倍率
                ('wAccDecMode', ctypes.c_ushort),   # 加減速モード
                ('fLowSpeed', ctypes.c_float),      # 起動速度
                ('fSpeed', ctypes.c_float),         # 移動速度
                ('wAccTime', ctypes.c_ushort),      # 加速時間
                ('wDecTime', ctypes.c_ushort),      # 減速時間
                ('fSAccSpeed', ctypes.c_float),     # 加速S字区間
                ('fSDecSpeed', ctypes.c_float),     # 減速S字区間
                ('lSlowdown', ctypes.c_int),        # スローダウンポイント
                ('lStep', ctypes.c_int * 2),        # 移動パルス数,移動方向
                ('bAbsolute', ctypes.c_int * 2)]    # 絶対座標指定

# イベント要因(SetEvent)
class EVENTFACTORPMCM(ctypes.Structure):
    _fields_ = [('nResult', ctypes.c_int),
                ('wStop', ctypes.c_ushort * 2),     # 停止イベント要因
                ('wState', ctypes.c_ushort * 2)]    # 状態イベント要因

# DLL
pf = platform.system()
if pf == 'Windows':
    pmcm = ctypes.windll.PmcM
elif pf == 'Linux':
    pmcm = ctypes.CDLL('libpmcm.so')


def main():
    class AppData:
        INVALID_ID = 9999
        board_id = INVALID_ID

    while True:
        print('1: open')
        print('2: setting')
        print('3: parameter')
        print('4: start')
        print('5: stop')
        print('6: close')
        print('9: exit')
        try:
            chosen = int(input('> '))
        except ValueError:
            chosen = 0
        if chosen == 1:
            open_board(AppData)
        elif chosen == 2:
            setting(AppData)
        elif chosen == 3:
            parameter(AppData)
        elif chosen == 4:
            start(AppData)
        elif chosen == 5:
            stop(AppData)
        elif chosen == 6:
            close_board(AppData)
        elif chosen == 9:
            exit_app(AppData)
            break
        else:
            pass
    return


def open_board(AppData):
    if AppData.board_id != AppData.INVALID_ID:
        print('Already open')
        return
    try:
        board_id = int(input('board id> '))
    except ValueError:
        board_id = AppData.INVALID_ID
    result = pmcm.PmcmOpen(board_id, b'PMC-M2C-U')
    if result == PMCM_RESULT_SUCCESS:
        print('PmcmOpen succeeded')
    else:
        print('PmcmOpen error {}'.format(result))
        board_id = AppData.INVALID_ID
    AppData.board_id = board_id
    return


def setting(AppData):
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    # センサ設定
    # オンで検知するセンサを接続している場合や、リミットスイッチを接続していない場合はモーターが動作しません
    # その場合は以下の関数を実行してセンサ設定を"オンで検知"に変更してください
    # result = pmcm.PmcmSetSensorConfig(AppData.board_id, axis, PMCM_LOGIC, 0x3F)
    # if result != PMCM_RESULT_SUCCESS:
    #     print('PmcmSetSensorConfig error {}'.format(result))
    #     return

    # パルス出力モード設定
    # 使用しているドライバに合致したパルス出力モードを選択してください
    result = pmcm.PmcmSetPulseConfig(AppData.board_id, axis, PMCM_PULSE_OUT, 7)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetPulseConfig error {}'.format(result))
        return
    return


def parameter(AppData):
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    motion = (MOTIONPMCM * 2)()
    # X軸
    motion[0].wMoveMode = PMCM_JOG              # 動作モード
    motion[0].wStartMode = PMCM_CONST           # 起動モード
    motion[0].fSpeedRate = 1                    # 速度倍率
    motion[0].wAccDecMode = PMCM_ACC_LINEAR     # 加減速モード
    motion[0].fLowSpeed = 1000                  # 起動時速度
    motion[0].fSpeed = 1000                     # 移動速度
    motion[0].wAccTime = 0                      # 加速時間
    motion[0].wDecTime = 0                      # 減速時間
    motion[0].fSAccSpeed = 0                    # 加速S字区間
    motion[0].fSDecSpeed = 0                    # 減速S字区間
    motion[0].lSlowdown = -1                    # スローダウンポイント
    motion[0].lStep = PMCM_DIR_CW               # 移動パルス数,移動方向
    motion[0].bAbsolutePtp = 0                  # 絶対座標指定
    # Y軸
    motion[1].wMoveMode = PMCM_JOG              # 動作モード
    motion[1].wStartMode = PMCM_CONST           # 起動モード
    motion[1].fSpeedRate = 1                    # 速度倍率
    motion[1].wAccDecMode = PMCM_ACC_LINEAR     # 加減速モード
    motion[1].fLowSpeed = 500                   # 起動時速度
    motion[1].fSpeed = 500                      # 移動速度
    motion[1].wAccTime = 0                      # 加速時間
    motion[1].wDecTime = 0                      # 減速時間
    motion[1].fSAccSpeed = 0                    # 加速S字区間
    motion[1].fSDecSpeed = 0                    # 減速S字区間
    motion[1].lSlowdown = -1                    # スローダウンポイント
    motion[1].lStep = PMCM_DIR_CCW              # 移動パルス数,移動方向
    motion[1].bAbsolutePtp = 0                  # 絶対座標指定
    # 動作パラメータ設定
    result = pmcm.PmcmSetMotion(AppData.board_id, axis, ctypes.byref(motion))
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetMotion error {}'.format(result))
        return
    return


def start(AppData):
    # 動作させる軸
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    # 動作開始
    result = pmcm.PmcmStartMotion(AppData.board_id, axis)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmStartMotion error {}'.format(result))
        return
    return


def stop(AppData):
    # 停止させる軸
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    # 停止モード
    stop_mode = PMCM_IMMEDIATE_STOP
    # 動作停止
    result = pmcm.PmcmStopMotion(AppData.board_id, axis, stop_mode)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmStopMotion error {}'.format(result))
        return
    return


def close_board(AppData):
    result = pmcm.PmcmClose(AppData.board_id)
    if result:
        AppData.board_id = AppData.INVALID_ID
        print('PmcmClose succeeded')
    else:
        print('PmcmClose falied')
    return


def exit_app(AppData):
    pmcm.PmcmClose(AppData.board_id)
    return


if __name__ == '__main__':
    main()

条件スタート

サンプルプログラムのMotion2と同等の内容です。 サンプルプログラムのMotion2や、ソフトウェアマニュアルの[サンプルプログラム]-[Motion2]とあわせてご確認ください。

import platform
import ctypes

# エラーコード(戻り値)
PMCM_RESULT_SUCCESS = 0             # 正常終了

# 軸指定
PMCM_AXIS_X = 0x0001
PMCM_AXIS_Y = 0x0002

# SetMotion(Line),GetMotion(Line)
PMCM_JOG = 0
PMCM_ORG = 1
PMCM_PTP = 2
PMCM_LINE = 3

PMCM_ACC_LINEAR = 0
PMCM_ACC_SCURVE = 1

PMCM_DIR_CW = 1
PMCM_DIR_CCW = -1

PMCM_CONST = 0
PMCM_CONST_DEC = 1
PMCM_ACC_DEC = 2

# StopMotion
PMCM_DEC_STOP = 0
PMCM_IMMEDIATE_STOP = 1

# ChangeSpeed
PMCM_CHG_IMM_LOW_SPEED = 0
PMCM_CHG_IMM_SPEED = 1
PMCM_CHG_DEC_LOW_SPEED = 2
PMCM_CHG_ACC_SPEED = 3
PMCM_CHG_NEW_SPEED = 4

# SetSensorConfig,GetSensorConfig
PMCM_LOGIC = 0
PMCM_EL_FUNC = 1
PMCM_SD_FUNC = 2
PMCM_SD_ACTIVE = 3
PMCM_ORG_FUNC = 4
PMCM_EZ_FUNC = 5
PMCM_EZ_COUNT = 6
PMCM_ALM_FUNC = 7
PMCM_LTC_FUNC = 8
PMCM_PCS_FUNC = 9
PMCM_SENS_FILTER = 10

# SetPulseConfig,GetPulseConfig
PMCM_PULSE_OUT = 0
PMCM_DIR_WAIT = 1
PMCM_FIN_TIMING = 2
PMCM_FH_REVISE = 3

# SetSynchroConfig,GetSynchroConfig
PMCM_SYNC_START_MODE = 0
PMCM_SYNC_START = 1
PMCM_SYNC_SIG_START = 2
PMCM_SYNC_STOP_MODE = 3

# SetSynchroOut,GetSynchroOut
PMCM_SYNC_OUT_MODE = 0

# SetComparatorConfig,GetComparatorConfig
PMCM_COMP_COUNTER = 0
PMCM_COMP_ENCODER = 1

# SetLatchConfig,GetLatchConfig
PMCM_COUNTER_LATCH_LTC = 0
PMCM_COUNTER_LATCH_ORG = 1
PMCM_COUNTER_CLEAR_LATCH = 2
PMCM_ENCODER_LATCH_LTC = 3
PMCM_ENCODER_LATCH_ORG = 4
PMCM_ENCODER_CLEAR_LATCH = 5

# SetEncoderConfig,GetEncoderConfig
PMCM_ENCODER_MODE = 0
PMCM_ENCODER_DIR = 1
PMCM_ENCODER_FILTER = 2

# SetErcConfig,GetErcConfig
PMCM_ERC_LOGIC = 0
PMCM_ERC_AUTOOUT_1 = 1
PMCM_ERC_AUTOOUT_2 = 2
PMCM_ERC_WIDTH = 3
PMCM_ERC_OFF_TIMER = 4
PMCM_ERC_SIG_ON = 5
PMCM_ERC_SIG_OFF = 6

# SetEventMask,GetEventMask
PMCM_EVENT_STOP = 0
PMCM_EVENT_STATE = 1

# PmcmGetStatus
PMCM_BUSY = 0
PMCM_SIG_STATUS = 1

# コンパレータ設定
class COMPPMCM(ctypes.Structure):
    _fields_ = [('wConfig', ctypes.c_ushort),       # 比較条件
                ('lCount', ctypes.c_int)]           # 比較データ

# 動作パラメータ設定(SetMotion,GetMotion)
class MOTIONPMCM(ctypes.Structure):
    _fields_ = [('wMoveMode', ctypes.c_ushort),     # 動作モード
                ('wStartMode', ctypes.c_ushort),    # 起動モード
                ('fSpeedRate', ctypes.c_float),     # 速度倍率
                ('wAccDecMode', ctypes.c_ushort),   # 加減速モード
                ('fLowSpeed', ctypes.c_float),      # 起動速度
                ('fSpeed', ctypes.c_float),         # 移動速度
                ('wAccTime', ctypes.c_ushort),      # 加速時間
                ('wDecTime', ctypes.c_ushort),      # 減速時間
                ('fSAccSpeed', ctypes.c_float),     # 加速S字区間
                ('fSDecSpeed', ctypes.c_float),     # 減速S字区間
                ('lSlowdown', ctypes.c_int),        # スローダウンポイント
                ('lStep', ctypes.c_int),            # 移動パルス数,移動方向
                ('bAbsolutePtp', ctypes.c_int)]     # 絶対座標指定

# 動作パラメータ設定(SetMotionLine,GetMotionLine)
class MOTIONLINEPMCM(ctypes.Structure):
    _fields_ = [('wStartMode', ctypes.c_ushort),    # 起動モード
                ('fSpeedRate', ctypes.c_float),     # 速度倍率
                ('wAccDecMode', ctypes.c_ushort),   # 加減速モード
                ('fLowSpeed', ctypes.c_float),      # 起動速度
                ('fSpeed', ctypes.c_float),         # 移動速度
                ('wAccTime', ctypes.c_ushort),      # 加速時間
                ('wDecTime', ctypes.c_ushort),      # 減速時間
                ('fSAccSpeed', ctypes.c_float),     # 加速S字区間
                ('fSDecSpeed', ctypes.c_float),     # 減速S字区間
                ('lSlowdown', ctypes.c_int),        # スローダウンポイント
                ('lStep', ctypes.c_int * 2),        # 移動パルス数,移動方向
                ('bAbsolute', ctypes.c_int * 2)]    # 絶対座標指定

# イベント要因(SetEvent)
class EVENTFACTORPMCM(ctypes.Structure):
    _fields_ = [('nResult', ctypes.c_int),
                ('wStop', ctypes.c_ushort * 2),     # 停止イベント要因
                ('wState', ctypes.c_ushort * 2)]    # 状態イベント要因

# DLL
pf = platform.system()
if pf == 'Windows':
    pmcm = ctypes.windll.PmcM
elif pf == 'Linux':
    pmcm = ctypes.CDLL('libpmcm.so')


def main():
    class AppData:
        INVALID_ID = 9999
        board_id = INVALID_ID
        start_mode = 0

    while True:
        print('1: open')
        print('2: setting')
        print('3: parameter')
        print('4: start')
        print('5: stop')
        print('6: close')
        print('9: exit')
        try:
            chosen = int(input('> '))
        except ValueError:
            chosen = 0
        if chosen == 1:
            open_board(AppData)
        elif chosen == 2:
            setting(AppData)
        elif chosen == 3:
            parameter(AppData)
        elif chosen == 4:
            start(AppData)
        elif chosen == 5:
            stop(AppData)
        elif chosen == 6:
            close_board(AppData)
        elif chosen == 9:
            exit_app(AppData)
            break
        else:
            pass
    return


def open_board(AppData):
    if AppData.board_id != AppData.INVALID_ID:
        print('Already open')
        return
    try:
        board_id = int(input('board id> '))
    except ValueError:
        board_id = AppData.INVALID_ID
    result = pmcm.PmcmOpen(board_id, b'PMC-M2C-U')
    if result == PMCM_RESULT_SUCCESS:
        print('PmcmOpen succeeded')
    else:
        print('PmcmOpen error {}'.format(result))
        board_id = AppData.INVALID_ID
    AppData.board_id = board_id
    return


def setting(AppData):
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    # センサ設定
    # オンで検知するセンサを接続している場合や、リミットスイッチを接続していない場合はモーターが動作しません
    # その場合は以下の関数を実行してセンサ設定を"オンで検知"に変更してください
    # result = pmcm.PmcmSetSensorConfig(AppData.board_id, axis, PMCM_LOGIC, 0x3F)
    # if result != PMCM_RESULT_SUCCESS:
    #     print('PmcmSetSensorConfig error {}'.format(result))
    #     return

    # パルス出力モード設定
    # 使用しているドライバに合致したパルス出力モードを選択してください
    result = pmcm.PmcmSetPulseConfig(AppData.board_id, axis, PMCM_PULSE_OUT, 7)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetPulseConfig error {}'.format(result))
        return

    print('1: 他軸の停止によるスタート')
    print('2: 内部同期信号によるスタート')
    try:
        chosen = int(input('> '))
    except ValueError:
        chosen = 0
    if chosen == 1:
        # 他軸の停止によるスタート
        # Y軸の停止によりX軸がスタートします
        # X軸の起動条件を設定します(他軸の停止によるスタート)
        result = pmcm.PmcmSetSynchroConfig(AppData.board_id, PMCM_AXIS_X,
                                           PMCM_SYNC_START_MODE, 3)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmSetSynchroConfig error {}'.format(result))
            return

        # X軸の他軸の停止によるスタート条件を設定します(Y軸の停止確認)
        result = pmcm.PmcmSetSynchroConfig(AppData.board_id, PMCM_AXIS_X,
                                           PMCM_SYNC_START, PMCM_AXIS_Y)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmSetSynchroConfig error {}'.format(result))
            return
    elif chosen == 2:
        # 内部同期信号によるスタート
        # X軸の出力パルスカウンタが500になったらY軸がスタートします
        # Y軸の起動条件を設定(内部同期信号によるスタート)
        result = pmcm.PmcmSetSynchroConfig(AppData.board_id, PMCM_AXIS_Y,
                                           PMCM_SYNC_START_MODE, 2)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmSetSynchroConfig error {}'.format(result))
            return

        # Y軸の内部同期信号によるスタート条件の設定(X軸の内部同期信号でスタート)
        result = pmcm.PmcmSetSynchroConfig(AppData.board_id, PMCM_AXIS_Y,
                                           PMCM_SYNC_SIG_START, 0)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmSetSynchroConfig error {}'.format(result))
            return

        # X軸の内部同期信号出力タイミングの設定(出力パルスコンパレータ条件成立時)
        result = pmcm.PmcmSetSynchroOut(AppData.board_id, PMCM_AXIS_X,
                                        PMCM_SYNC_OUT_MODE, 1)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmSetSynchroOut error {}'.format(result))
            return

        # X軸のコンパレータの設定
        comp = (COMPPMCM * 2)()
        comp[0].wConfig = 1
        comp[0].lCount = 500
        result = pmcm.PmcmSetComparatorConfig(AppData.board_id, PMCM_AXIS_X,
                                              PMCM_COMP_COUNTER, comp)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmSetComparatorConfig error {}'.format(result))
            return
    else:
        chosen = 0
        print('error')
    AppData.start_mode = chosen
    return


def parameter(AppData):
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    motion = (MOTIONPMCM * 2)()
    # X軸
    motion[0].wMoveMode = PMCM_PTP              # 動作モード
    motion[0].wStartMode = PMCM_CONST           # 起動モード
    motion[0].fSpeedRate = 1                    # 速度倍率
    motion[0].wAccDecMode = PMCM_ACC_LINEAR     # 加減速モード
    motion[0].fLowSpeed = 500                   # 起動時速度
    motion[0].fSpeed = 500                      # 移動速度
    motion[0].wAccTime = 0                      # 加速時間
    motion[0].wDecTime = 0                      # 減速時間
    motion[0].fSAccSpeed = 0                    # 加速S字区間
    motion[0].fSDecSpeed = 0                    # 減速S字区間
    motion[0].lSlowdown = -1                    # スローダウンポイント
    motion[0].lStep = 1000                      # 移動パルス数,移動方向
    motion[0].bAbsolutePtp = 0                  # 絶対座標指定
    # Y軸
    motion[1].wMoveMode = PMCM_PTP              # 動作モード
    motion[1].wStartMode = PMCM_CONST           # 起動モード
    motion[1].fSpeedRate = 1                    # 速度倍率
    motion[1].wAccDecMode = PMCM_ACC_LINEAR     # 加減速モード
    motion[1].fLowSpeed = 1000                  # 起動時速度
    motion[1].fSpeed = 1000                     # 移動速度
    motion[1].wAccTime = 0                      # 加速時間
    motion[1].wDecTime = 0                      # 減速時間
    motion[1].fSAccSpeed = 0                    # 加速S字区間
    motion[1].fSDecSpeed = 0                    # 減速S字区間
    motion[1].lSlowdown = -1                    # スローダウンポイント
    motion[1].lStep = 1000                      # 移動パルス数,移動方向
    motion[1].bAbsolutePtp = 0                  # 絶対座標指定
    # 動作パラメータ設定
    result = pmcm.PmcmSetMotion(AppData.board_id, axis, ctypes.byref(motion))
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetMotion error {}'.format(result))
        return
    return


def start(AppData):
    if AppData.start_mode == 1:
        # 他軸の停止によるスタート
        # X軸はY軸の停止を確認して動作しますので、Y軸を先に動作させます
        # 同時に動作させてしまうと、その時点でY軸がまだ動作開始前で停止中のため、X軸が動作してしまいます
        # Y軸動作開始
        result = pmcm.PmcmStartMotion(AppData.board_id, PMCM_AXIS_Y)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmStartMotion error {}'.format(result))
            return
        # X軸動作開始
        result = pmcm.PmcmStartMotion(AppData.board_id, PMCM_AXIS_X)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmStartMotion error {}'.format(result))
            return
    elif AppData.start_mode == 2:
        # 内部同期信号によるスタート
        # 動作開始
        axis = PMCM_AXIS_X + PMCM_AXIS_Y
        result = pmcm.PmcmStartMotion(AppData.board_id, axis)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmStartMotion error {}'.format(result))
            return
    else:
        print('error')
    return


def stop(AppData):
    # 停止させる軸
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    # 停止モード
    stop_mode = PMCM_IMMEDIATE_STOP
    # 動作停止
    result = pmcm.PmcmStopMotion(AppData.board_id, axis, stop_mode)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmStopMotion error {}'.format(result))
        return
    return


def close_board(AppData):
    result = pmcm.PmcmClose(AppData.board_id)
    if result:
        AppData.board_id = AppData.INVALID_ID
        AppData.start_mode = 0
        print('PmcmClose succeeded')
    else:
        print('PmcmClose falied')
    return


def exit_app(AppData):
    pmcm.PmcmClose(AppData.board_id)
    return


if __name__ == '__main__':
    main()

直線補間動作

サンプルプログラムのMotionLineと同等の内容です。 サンプルプログラムのMotionLineや、ソフトウェアマニュアルの[サンプルプログラム]-[MotionLine]とあわせてご確認ください。

import platform
import ctypes

# エラーコード(戻り値)
PMCM_RESULT_SUCCESS = 0             # 正常終了

# 軸指定
PMCM_AXIS_X = 0x0001
PMCM_AXIS_Y = 0x0002

# SetMotion(Line),GetMotion(Line)
PMCM_JOG = 0
PMCM_ORG = 1
PMCM_PTP = 2
PMCM_LINE = 3

PMCM_ACC_LINEAR = 0
PMCM_ACC_SCURVE = 1

PMCM_DIR_CW = 1
PMCM_DIR_CCW = -1

PMCM_CONST = 0
PMCM_CONST_DEC = 1
PMCM_ACC_DEC = 2

# StopMotion
PMCM_DEC_STOP = 0
PMCM_IMMEDIATE_STOP = 1

# ChangeSpeed
PMCM_CHG_IMM_LOW_SPEED = 0
PMCM_CHG_IMM_SPEED = 1
PMCM_CHG_DEC_LOW_SPEED = 2
PMCM_CHG_ACC_SPEED = 3
PMCM_CHG_NEW_SPEED = 4

# SetSensorConfig,GetSensorConfig
PMCM_LOGIC = 0
PMCM_EL_FUNC = 1
PMCM_SD_FUNC = 2
PMCM_SD_ACTIVE = 3
PMCM_ORG_FUNC = 4
PMCM_EZ_FUNC = 5
PMCM_EZ_COUNT = 6
PMCM_ALM_FUNC = 7
PMCM_LTC_FUNC = 8
PMCM_PCS_FUNC = 9
PMCM_SENS_FILTER = 10

# SetPulseConfig,GetPulseConfig
PMCM_PULSE_OUT = 0
PMCM_DIR_WAIT = 1
PMCM_FIN_TIMING = 2
PMCM_FH_REVISE = 3

# SetSynchroConfig,GetSynchroConfig
PMCM_SYNC_START_MODE = 0
PMCM_SYNC_START = 1
PMCM_SYNC_SIG_START = 2
PMCM_SYNC_STOP_MODE = 3

# SetSynchroOut,GetSynchroOut
PMCM_SYNC_OUT_MODE = 0

# SetComparatorConfig,GetComparatorConfig
PMCM_COMP_COUNTER = 0
PMCM_COMP_ENCODER = 1

# SetLatchConfig,GetLatchConfig
PMCM_COUNTER_LATCH_LTC = 0
PMCM_COUNTER_LATCH_ORG = 1
PMCM_COUNTER_CLEAR_LATCH = 2
PMCM_ENCODER_LATCH_LTC = 3
PMCM_ENCODER_LATCH_ORG = 4
PMCM_ENCODER_CLEAR_LATCH = 5

# SetEncoderConfig,GetEncoderConfig
PMCM_ENCODER_MODE = 0
PMCM_ENCODER_DIR = 1
PMCM_ENCODER_FILTER = 2

# SetErcConfig,GetErcConfig
PMCM_ERC_LOGIC = 0
PMCM_ERC_AUTOOUT_1 = 1
PMCM_ERC_AUTOOUT_2 = 2
PMCM_ERC_WIDTH = 3
PMCM_ERC_OFF_TIMER = 4
PMCM_ERC_SIG_ON = 5
PMCM_ERC_SIG_OFF = 6

# SetEventMask,GetEventMask
PMCM_EVENT_STOP = 0
PMCM_EVENT_STATE = 1

# PmcmGetStatus
PMCM_BUSY = 0
PMCM_SIG_STATUS = 1

# コンパレータ設定
class COMPPMCM(ctypes.Structure):
    _fields_ = [('wConfig', ctypes.c_ushort),       # 比較条件
                ('lCount', ctypes.c_int)]           # 比較データ

# 動作パラメータ設定(SetMotion,GetMotion)
class MOTIONPMCM(ctypes.Structure):
    _fields_ = [('wMoveMode', ctypes.c_ushort),     # 動作モード
                ('wStartMode', ctypes.c_ushort),    # 起動モード
                ('fSpeedRate', ctypes.c_float),     # 速度倍率
                ('wAccDecMode', ctypes.c_ushort),   # 加減速モード
                ('fLowSpeed', ctypes.c_float),      # 起動速度
                ('fSpeed', ctypes.c_float),         # 移動速度
                ('wAccTime', ctypes.c_ushort),      # 加速時間
                ('wDecTime', ctypes.c_ushort),      # 減速時間
                ('fSAccSpeed', ctypes.c_float),     # 加速S字区間
                ('fSDecSpeed', ctypes.c_float),     # 減速S字区間
                ('lSlowdown', ctypes.c_int),        # スローダウンポイント
                ('lStep', ctypes.c_int),            # 移動パルス数,移動方向
                ('bAbsolutePtp', ctypes.c_int)]     # 絶対座標指定

# 動作パラメータ設定(SetMotionLine,GetMotionLine)
class MOTIONLINEPMCM(ctypes.Structure):
    _fields_ = [('wStartMode', ctypes.c_ushort),    # 起動モード
                ('fSpeedRate', ctypes.c_float),     # 速度倍率
                ('wAccDecMode', ctypes.c_ushort),   # 加減速モード
                ('fLowSpeed', ctypes.c_float),      # 起動速度
                ('fSpeed', ctypes.c_float),         # 移動速度
                ('wAccTime', ctypes.c_ushort),      # 加速時間
                ('wDecTime', ctypes.c_ushort),      # 減速時間
                ('fSAccSpeed', ctypes.c_float),     # 加速S字区間
                ('fSDecSpeed', ctypes.c_float),     # 減速S字区間
                ('lSlowdown', ctypes.c_int),        # スローダウンポイント
                ('lStep', ctypes.c_int * 2),        # 移動パルス数,移動方向
                ('bAbsolute', ctypes.c_int * 2)]    # 絶対座標指定

# イベント要因(SetEvent)
class EVENTFACTORPMCM(ctypes.Structure):
    _fields_ = [('nResult', ctypes.c_int),
                ('wStop', ctypes.c_ushort * 2),     # 停止イベント要因
                ('wState', ctypes.c_ushort * 2)]    # 状態イベント要因

# DLL
pf = platform.system()
if pf == 'Windows':
    pmcm = ctypes.windll.PmcM
elif pf == 'Linux':
    pmcm = ctypes.CDLL('libpmcm.so')


def main():
    class AppData:
        INVALID_ID = 9999
        board_id = INVALID_ID

    while True:
        print('1: open')
        print('2: setting')
        print('3: parameter')
        print('4: start')
        print('5: stop')
        print('6: close')
        print('9: exit')
        try:
            chosen = int(input('> '))
        except ValueError:
            chosen = 0
        if chosen == 1:
            open_board(AppData)
        elif chosen == 2:
            setting(AppData)
        elif chosen == 3:
            parameter(AppData)
        elif chosen == 4:
            start(AppData)
        elif chosen == 5:
            stop(AppData)
        elif chosen == 6:
            close_board(AppData)
        elif chosen == 9:
            exit_app(AppData)
            break
        else:
            pass
    return


def open_board(AppData):
    if AppData.board_id != AppData.INVALID_ID:
        print('Already open')
        return
    try:
        board_id = int(input('board id> '))
    except ValueError:
        board_id = AppData.INVALID_ID
    result = pmcm.PmcmOpen(board_id, b'PMC-M2C-U')
    if result == PMCM_RESULT_SUCCESS:
        print('PmcmOpen succeeded')
    else:
        print('PmcmOpen error {}'.format(result))
        board_id = AppData.INVALID_ID
    AppData.board_id = board_id
    return


def setting(AppData):
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    # センサ設定
    # オンで検知するセンサを接続している場合や、リミットスイッチを接続していない場合はモーターが動作しません
    # その場合は以下の関数を実行してセンサ設定を"オンで検知"に変更してください
    # result = pmcm.PmcmSetSensorConfig(AppData.board_id, axis, PMCM_LOGIC, 0x3F)
    # if result != PMCM_RESULT_SUCCESS:
    #     print('PmcmSetSensorConfig error {}'.format(result))
    #     return

    # パルス出力モード設定
    # 使用しているドライバに合致したパルス出力モードを選択してください
    result = pmcm.PmcmSetPulseConfig(AppData.board_id, axis, PMCM_PULSE_OUT, 7)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetPulseConfig error {}'.format(result))
        return
    return


def parameter(AppData):
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    motion_line = MOTIONLINEPMCM()
    motion_line.wStartMode = PMCM_CONST         # 起動モード
    motion_line.fSpeedRate = 1                  # 速度倍率
    motion_line.wAccDecMode = PMCM_ACC_LINEAR   # 加減速モード
    motion_line.fLowSpeed = 1000                # 起動時速度
    motion_line.fSpeed = 1000                   # 移動速度
    motion_line.wAccTime = 0                    # 加速時間
    motion_line.wDecTime = 0                    # 減速時間
    motion_line.fSAccSpeed = 0                  # 加速S字区間
    motion_line.fSDecSpeed = 0                  # 減速S字区間
    motion_line.lSlowdown = -1                  # スローダウンポイント
    motion_line.lStep[0] = 500                  # 移動パルス数,移動方向
    motion_line.lStep[1] = 1000                 # 移動パルス数,移動方向
    motion_line.bAbsolute[0] = 0                # 絶対座標指定
    motion_line.bAbsolute[1] = 0                # 絶対座標指定
    # 動作パラメータ設定
    result = pmcm.PmcmSetMotionLine(AppData.board_id, axis,
                                    ctypes.byref(motion_line))
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetMotionLine error {}'.format(result))
        return
    return


def start(AppData):
    result = pmcm.PmcmStartMotionLine(AppData.board_id)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmStartMotionLine error {}'.format(result))
        return
    return


def stop(AppData):
    # 停止させる軸
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    # 停止モード
    stop_mode = PMCM_IMMEDIATE_STOP
    # 動作停止
    result = pmcm.PmcmStopMotion(AppData.board_id, axis, stop_mode)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmStopMotion error {}'.format(result))
        return
    return


def close_board(AppData):
    result = pmcm.PmcmClose(AppData.board_id)
    if result:
        AppData.board_id = AppData.INVALID_ID
        print('PmcmClose succeeded')
    else:
        print('PmcmClose falied')
    return


def exit_app(AppData):
    pmcm.PmcmClose(AppData.board_id)
    return


if __name__ == '__main__':
    main()

CP動作

サンプルプログラムのMotionCPと同等の内容です。 サンプルプログラムのMotionCPや、ソフトウェアマニュアルの[サンプルプログラム]-[MotionCP]とあわせてご確認ください。

import platform
import ctypes

# エラーコード(戻り値)
PMCM_RESULT_SUCCESS = 0             # 正常終了

# 軸指定
PMCM_AXIS_X = 0x0001
PMCM_AXIS_Y = 0x0002

# SetMotion(Line),GetMotion(Line)
PMCM_JOG = 0
PMCM_ORG = 1
PMCM_PTP = 2
PMCM_LINE = 3

PMCM_ACC_LINEAR = 0
PMCM_ACC_SCURVE = 1

PMCM_DIR_CW = 1
PMCM_DIR_CCW = -1

PMCM_CONST = 0
PMCM_CONST_DEC = 1
PMCM_ACC_DEC = 2

# StopMotion
PMCM_DEC_STOP = 0
PMCM_IMMEDIATE_STOP = 1

# ChangeSpeed
PMCM_CHG_IMM_LOW_SPEED = 0
PMCM_CHG_IMM_SPEED = 1
PMCM_CHG_DEC_LOW_SPEED = 2
PMCM_CHG_ACC_SPEED = 3
PMCM_CHG_NEW_SPEED = 4

# SetSensorConfig,GetSensorConfig
PMCM_LOGIC = 0
PMCM_EL_FUNC = 1
PMCM_SD_FUNC = 2
PMCM_SD_ACTIVE = 3
PMCM_ORG_FUNC = 4
PMCM_EZ_FUNC = 5
PMCM_EZ_COUNT = 6
PMCM_ALM_FUNC = 7
PMCM_LTC_FUNC = 8
PMCM_PCS_FUNC = 9
PMCM_SENS_FILTER = 10

# SetPulseConfig,GetPulseConfig
PMCM_PULSE_OUT = 0
PMCM_DIR_WAIT = 1
PMCM_FIN_TIMING = 2
PMCM_FH_REVISE = 3

# SetSynchroConfig,GetSynchroConfig
PMCM_SYNC_START_MODE = 0
PMCM_SYNC_START = 1
PMCM_SYNC_SIG_START = 2
PMCM_SYNC_STOP_MODE = 3

# SetSynchroOut,GetSynchroOut
PMCM_SYNC_OUT_MODE = 0

# SetComparatorConfig,GetComparatorConfig
PMCM_COMP_COUNTER = 0
PMCM_COMP_ENCODER = 1

# SetLatchConfig,GetLatchConfig
PMCM_COUNTER_LATCH_LTC = 0
PMCM_COUNTER_LATCH_ORG = 1
PMCM_COUNTER_CLEAR_LATCH = 2
PMCM_ENCODER_LATCH_LTC = 3
PMCM_ENCODER_LATCH_ORG = 4
PMCM_ENCODER_CLEAR_LATCH = 5

# SetEncoderConfig,GetEncoderConfig
PMCM_ENCODER_MODE = 0
PMCM_ENCODER_DIR = 1
PMCM_ENCODER_FILTER = 2

# SetErcConfig,GetErcConfig
PMCM_ERC_LOGIC = 0
PMCM_ERC_AUTOOUT_1 = 1
PMCM_ERC_AUTOOUT_2 = 2
PMCM_ERC_WIDTH = 3
PMCM_ERC_OFF_TIMER = 4
PMCM_ERC_SIG_ON = 5
PMCM_ERC_SIG_OFF = 6

# SetEventMask,GetEventMask
PMCM_EVENT_STOP = 0
PMCM_EVENT_STATE = 1

# PmcmGetStatus
PMCM_BUSY = 0
PMCM_SIG_STATUS = 1

# コンパレータ設定
class COMPPMCM(ctypes.Structure):
    _fields_ = [('wConfig', ctypes.c_ushort),       # 比較条件
                ('lCount', ctypes.c_int)]           # 比較データ

# 動作パラメータ設定(SetMotion,GetMotion)
class MOTIONPMCM(ctypes.Structure):
    _fields_ = [('wMoveMode', ctypes.c_ushort),     # 動作モード
                ('wStartMode', ctypes.c_ushort),    # 起動モード
                ('fSpeedRate', ctypes.c_float),     # 速度倍率
                ('wAccDecMode', ctypes.c_ushort),   # 加減速モード
                ('fLowSpeed', ctypes.c_float),      # 起動速度
                ('fSpeed', ctypes.c_float),         # 移動速度
                ('wAccTime', ctypes.c_ushort),      # 加速時間
                ('wDecTime', ctypes.c_ushort),      # 減速時間
                ('fSAccSpeed', ctypes.c_float),     # 加速S字区間
                ('fSDecSpeed', ctypes.c_float),     # 減速S字区間
                ('lSlowdown', ctypes.c_int),        # スローダウンポイント
                ('lStep', ctypes.c_int),            # 移動パルス数,移動方向
                ('bAbsolutePtp', ctypes.c_int)]     # 絶対座標指定

# 動作パラメータ設定(SetMotionLine,GetMotionLine)
class MOTIONLINEPMCM(ctypes.Structure):
    _fields_ = [('wStartMode', ctypes.c_ushort),    # 起動モード
                ('fSpeedRate', ctypes.c_float),     # 速度倍率
                ('wAccDecMode', ctypes.c_ushort),   # 加減速モード
                ('fLowSpeed', ctypes.c_float),      # 起動速度
                ('fSpeed', ctypes.c_float),         # 移動速度
                ('wAccTime', ctypes.c_ushort),      # 加速時間
                ('wDecTime', ctypes.c_ushort),      # 減速時間
                ('fSAccSpeed', ctypes.c_float),     # 加速S字区間
                ('fSDecSpeed', ctypes.c_float),     # 減速S字区間
                ('lSlowdown', ctypes.c_int),        # スローダウンポイント
                ('lStep', ctypes.c_int * 2),        # 移動パルス数,移動方向
                ('bAbsolute', ctypes.c_int * 2)]    # 絶対座標指定

# イベント要因(SetEvent)
class EVENTFACTORPMCM(ctypes.Structure):
    _fields_ = [('nResult', ctypes.c_int),
                ('wStop', ctypes.c_ushort * 2),     # 停止イベント要因
                ('wState', ctypes.c_ushort * 2)]    # 状態イベント要因

# DLL
pf = platform.system()
if pf == 'Windows':
    pmcm = ctypes.windll.PmcM
elif pf == 'Linux':
    pmcm = ctypes.CDLL('libpmcm.so')


def main():
    class AppData:
        INVALID_ID = 9999
        board_id = INVALID_ID

    while True:
        print('1: open')
        print('2: setting')
        print('3: parameter')
        print('4: start')
        print('5: add')
        print('6: stop')
        print('7: close')
        print('9: exit')
        try:
            chosen = int(input('> '))
        except ValueError:
            chosen = 0
        if chosen == 1:
            open_board(AppData)
        elif chosen == 2:
            setting(AppData)
        elif chosen == 3:
            parameter(AppData)
        elif chosen == 4:
            start(AppData)
        elif chosen == 5:
            add(AppData)
        elif chosen == 6:
            stop(AppData)
        elif chosen == 7:
            close_board(AppData)
        elif chosen == 9:
            exit_app(AppData)
            break
        else:
            pass
    return


def open_board(AppData):
    if AppData.board_id != AppData.INVALID_ID:
        print('Already open')
        return
    try:
        board_id = int(input('board id> '))
    except ValueError:
        board_id = AppData.INVALID_ID
    result = pmcm.PmcmOpen(board_id, b'PMC-M2C-U')
    if result == PMCM_RESULT_SUCCESS:
        print('PmcmOpen succeeded')
    else:
        print('PmcmOpen error {}'.format(result))
        board_id = AppData.INVALID_ID
    AppData.board_id = board_id
    return


def setting(AppData):
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    # センサ設定
    # オンで検知するセンサを接続している場合や、リミットスイッチを接続していない場合はモーターが動作しません
    # その場合は以下の関数を実行してセンサ設定を"オンで検知"に変更してください
    # result = pmcm.PmcmSetSensorConfig(AppData.board_id, axis, PMCM_LOGIC, 0x3F)
    # if result != PMCM_RESULT_SUCCESS:
    #     print('PmcmSetSensorConfig error {}'.format(result))
    #     return

    # パルス出力モード設定
    # 使用しているドライバに合致したパルス出力モードを選択してください
    result = pmcm.PmcmSetPulseConfig(AppData.board_id, axis, PMCM_PULSE_OUT, 7)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetPulseConfig error {}'.format(result))
        return
    return


def parameter(AppData):
    axis = PMCM_AXIS_X
    # CP動作パラメータ数
    count = 3
    motion = (MOTIONPMCM * count)()
    # 1回目
    motion[0].wMoveMode = PMCM_PTP              # 動作モード
    motion[0].wStartMode = PMCM_ACC_DEC         # 起動モード
    motion[0].fSpeedRate = 1                    # 速度倍率
    motion[0].wAccDecMode = PMCM_ACC_LINEAR     # 加減速モード
    motion[0].fLowSpeed = 100                   # 起動時速度
    motion[0].fSpeed = 500                      # 移動速度
    motion[0].wAccTime = 500                    # 加速時間
    motion[0].wDecTime = 500                    # 減速時間
    motion[0].fSAccSpeed = 0                    # 加速S字区間
    motion[0].fSDecSpeed = 0                    # 減速S字区間
    motion[0].lSlowdown = 0                     # スローダウンポイント
    motion[0].lStep = 1000                      # 移動パルス数,移動方向
    motion[0].bAbsolutePtp = 0                  # 絶対座標指定
    # 2回目
    motion[1].wMoveMode = PMCM_PTP              # 動作モード
    motion[1].wStartMode = PMCM_ACC_DEC         # 起動モード
    motion[1].fSpeedRate = 1                    # 速度倍率
    motion[1].wAccDecMode = PMCM_ACC_LINEAR     # 加減速モード
    motion[1].fLowSpeed = 500                   # 起動時速度
    motion[1].fSpeed = 1000                     # 移動速度
    motion[1].wAccTime = 500                    # 加速時間
    motion[1].wDecTime = 500                    # 減速時間
    motion[1].fSAccSpeed = 0                    # 加速S字区間
    motion[1].fSDecSpeed = 0                    # 減速S字区間
    motion[1].lSlowdown = -1                    # スローダウンポイント
    motion[1].lStep = 2000                      # 移動パルス数,移動方向
    motion[1].bAbsolutePtp = 0                  # 絶対座標指定
    # 3回目
    motion[2].wMoveMode = PMCM_PTP              # 動作モード
    motion[2].wStartMode = PMCM_CONST_DEC       # 起動モード
    motion[2].fSpeedRate = 1                    # 速度倍率
    motion[2].wAccDecMode = PMCM_ACC_LINEAR     # 加減速モード
    motion[2].fLowSpeed = 100                   # 起動時速度
    motion[2].fSpeed = 500                      # 移動速度
    motion[2].wAccTime = 0                      # 加速時間
    motion[2].wDecTime = 500                    # 減速時間
    motion[2].fSAccSpeed = 0                    # 加速S字区間
    motion[2].fSDecSpeed = 0                    # 減速S字区間
    motion[2].lSlowdown = -1                    # スローダウンポイント
    motion[2].lStep = 1500                      # 移動パルス数,移動方向
    motion[2].bAbsolutePtp = 0                  # 絶対座標指定
    # CPの空き取得
    empty = (ctypes.c_ushort * 2)()
    result = pmcm.PmcmGetEmptyCp(AppData.board_id, axis, ctypes.byref(empty))
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmGetEmptyCp error {}'.format(result))
        return
    # CPの空き確認
    if empty[0] >= count:   # 空きあり
        result = pmcm.PmcmSetMotionCp(AppData.board_id, axis,
                                      ctypes.byref(motion), count)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmSetMotionCp error {}'.format(result))
            return
    return


def start(AppData):
    # 動作させる軸
    axis = PMCM_AXIS_X
    # 動作開始
    result = pmcm.PmcmStartMotionCp(AppData.board_id, axis)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmStartMotionCp error {}'.format(result))
        return
    return


def add(AppData):
    # CP動作は96動作までしか設定できません
    # それ以上の動作を設定したい場合は、動作中にCPの空きを確認し、空き数分の動作を開始します
    axis = PMCM_AXIS_X
    # CP動作パラメータ数
    count = 100
    motion = (MOTIONPMCM * count)()
    for m in motion:
        m.wMoveMode = PMCM_PTP              # 動作モード
        m.wStartMode = PMCM_CONST           # 起動モード
        m.fSpeedRate = 1                    # 速度倍率
        m.wAccDecMode = PMCM_ACC_LINEAR     # 加減速モード
        m.fLowSpeed = 1000                  # 起動時速度
        m.fSpeed = 1000                     # 移動速度
        m.wAccTime = 0                      # 加速時間
        m.wDecTime = 0                      # 減速時間
        m.fSAccSpeed = 0                    # 加速S字区間
        m.fSDecSpeed = 0                    # 減速S字区間
        m.lSlowdown = -1                    # スローダウンポイント
        m.lStep = 1000                      # 移動パルス数,移動方向
        m.bAbsolutePtp = 0                  # 絶対座標指定

    # 残り動作数
    remain_count = count
    empty = (ctypes.c_ushort * 2)()
    while remain_count > 0:
        # CPの空き取得
        result = pmcm.PmcmGetEmptyCp(AppData.board_id, axis,
                                     ctypes.byref(empty))
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmGetEmptyCp error {}'.format(result))
            return
        # CPの空きを確認し、設定動作数を決定する
        if empty[0] == 0:                           # CP空きなし
            set_count = 0
        elif empty[0] < remain_count:               # CP空き < 残り動作数
            set_count = empty[0]                    # CP空き分だけ設定する
        elif empty[0] >= remain_count:              # CP空き >= 残り動作数
            set_count = remain_count                # 残り動作数を設定する
        if set_count > 0:
            # 動作パラメータ設定
            result = pmcm.PmcmSetMotionCp(AppData.board_id, axis, 
                                          ctypes.byref(
                                              motion[count - remain_count]),
                                          set_count)
            if result != PMCM_RESULT_SUCCESS:
                print('PmcmSetMotionCp error {}'.format(result))
                return
            # 動作開始
            result = pmcm.PmcmStartMotionCp(AppData.board_id, axis)
            if result != PMCM_RESULT_SUCCESS:
                print('PmcmStartMotionCp error {}'.format(result))
                return
        # 残り動作数更新
        remain_count -= set_count
    return


def stop(AppData):
    # 停止させる軸
    axis = PMCM_AXIS_X
    # 停止モード
    stop_mode = PMCM_IMMEDIATE_STOP
    # 動作停止
    result = pmcm.PmcmStopMotion(AppData.board_id, axis, stop_mode)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmStopMotion error {}'.format(result))
        return
    return


def close_board(AppData):
    result = pmcm.PmcmClose(AppData.board_id)
    if result:
        AppData.board_id = AppData.INVALID_ID
        print('PmcmClose succeeded')
    else:
        print('PmcmClose falied')
    return


def exit_app(AppData):
    pmcm.PmcmClose(AppData.board_id)
    return


if __name__ == '__main__':
    main()

イベント発生

サンプルプログラムのEventと同等の内容です。 サンプルプログラムのEventや、ソフトウェアマニュアルの[サンプルプログラム]-[Event]とあわせてご確認ください。

import platform
import ctypes
import threading

# エラーコード(戻り値)
PMCM_RESULT_SUCCESS = 0             # 正常終了

# 軸指定
PMCM_AXIS_X = 0x0001
PMCM_AXIS_Y = 0x0002

# SetMotion(Line),GetMotion(Line)
PMCM_JOG = 0
PMCM_ORG = 1
PMCM_PTP = 2
PMCM_LINE = 3

PMCM_ACC_LINEAR = 0
PMCM_ACC_SCURVE = 1

PMCM_DIR_CW = 1
PMCM_DIR_CCW = -1

PMCM_CONST = 0
PMCM_CONST_DEC = 1
PMCM_ACC_DEC = 2

# StopMotion
PMCM_DEC_STOP = 0
PMCM_IMMEDIATE_STOP = 1

# ChangeSpeed
PMCM_CHG_IMM_LOW_SPEED = 0
PMCM_CHG_IMM_SPEED = 1
PMCM_CHG_DEC_LOW_SPEED = 2
PMCM_CHG_ACC_SPEED = 3
PMCM_CHG_NEW_SPEED = 4

# SetSensorConfig,GetSensorConfig
PMCM_LOGIC = 0
PMCM_EL_FUNC = 1
PMCM_SD_FUNC = 2
PMCM_SD_ACTIVE = 3
PMCM_ORG_FUNC = 4
PMCM_EZ_FUNC = 5
PMCM_EZ_COUNT = 6
PMCM_ALM_FUNC = 7
PMCM_LTC_FUNC = 8
PMCM_PCS_FUNC = 9
PMCM_SENS_FILTER = 10

# SetPulseConfig,GetPulseConfig
PMCM_PULSE_OUT = 0
PMCM_DIR_WAIT = 1
PMCM_FIN_TIMING = 2
PMCM_FH_REVISE = 3

# SetSynchroConfig,GetSynchroConfig
PMCM_SYNC_START_MODE = 0
PMCM_SYNC_START = 1
PMCM_SYNC_SIG_START = 2
PMCM_SYNC_STOP_MODE = 3

# SetSynchroOut,GetSynchroOut
PMCM_SYNC_OUT_MODE = 0

# SetComparatorConfig,GetComparatorConfig
PMCM_COMP_COUNTER = 0
PMCM_COMP_ENCODER = 1

# SetLatchConfig,GetLatchConfig
PMCM_COUNTER_LATCH_LTC = 0
PMCM_COUNTER_LATCH_ORG = 1
PMCM_COUNTER_CLEAR_LATCH = 2
PMCM_ENCODER_LATCH_LTC = 3
PMCM_ENCODER_LATCH_ORG = 4
PMCM_ENCODER_CLEAR_LATCH = 5

# SetEncoderConfig,GetEncoderConfig
PMCM_ENCODER_MODE = 0
PMCM_ENCODER_DIR = 1
PMCM_ENCODER_FILTER = 2

# SetErcConfig,GetErcConfig
PMCM_ERC_LOGIC = 0
PMCM_ERC_AUTOOUT_1 = 1
PMCM_ERC_AUTOOUT_2 = 2
PMCM_ERC_WIDTH = 3
PMCM_ERC_OFF_TIMER = 4
PMCM_ERC_SIG_ON = 5
PMCM_ERC_SIG_OFF = 6

# SetEventMask,GetEventMask
PMCM_EVENT_STOP = 0
PMCM_EVENT_STATE = 1

# PmcmGetStatus
PMCM_BUSY = 0
PMCM_SIG_STATUS = 1

# コンパレータ設定
class COMPPMCM(ctypes.Structure):
    _fields_ = [('wConfig', ctypes.c_ushort),       # 比較条件
                ('lCount', ctypes.c_int)]           # 比較データ

# 動作パラメータ設定(SetMotion,GetMotion)
class MOTIONPMCM(ctypes.Structure):
    _fields_ = [('wMoveMode', ctypes.c_ushort),     # 動作モード
                ('wStartMode', ctypes.c_ushort),    # 起動モード
                ('fSpeedRate', ctypes.c_float),     # 速度倍率
                ('wAccDecMode', ctypes.c_ushort),   # 加減速モード
                ('fLowSpeed', ctypes.c_float),      # 起動速度
                ('fSpeed', ctypes.c_float),         # 移動速度
                ('wAccTime', ctypes.c_ushort),      # 加速時間
                ('wDecTime', ctypes.c_ushort),      # 減速時間
                ('fSAccSpeed', ctypes.c_float),     # 加速S字区間
                ('fSDecSpeed', ctypes.c_float),     # 減速S字区間
                ('lSlowdown', ctypes.c_int),        # スローダウンポイント
                ('lStep', ctypes.c_int),            # 移動パルス数,移動方向
                ('bAbsolutePtp', ctypes.c_int)]     # 絶対座標指定

# 動作パラメータ設定(SetMotionLine,GetMotionLine)
class MOTIONLINEPMCM(ctypes.Structure):
    _fields_ = [('wStartMode', ctypes.c_ushort),    # 起動モード
                ('fSpeedRate', ctypes.c_float),     # 速度倍率
                ('wAccDecMode', ctypes.c_ushort),   # 加減速モード
                ('fLowSpeed', ctypes.c_float),      # 起動速度
                ('fSpeed', ctypes.c_float),         # 移動速度
                ('wAccTime', ctypes.c_ushort),      # 加速時間
                ('wDecTime', ctypes.c_ushort),      # 減速時間
                ('fSAccSpeed', ctypes.c_float),     # 加速S字区間
                ('fSDecSpeed', ctypes.c_float),     # 減速S字区間
                ('lSlowdown', ctypes.c_int),        # スローダウンポイント
                ('lStep', ctypes.c_int * 2),        # 移動パルス数,移動方向
                ('bAbsolute', ctypes.c_int * 2)]    # 絶対座標指定

# イベント要因(SetEvent)
class EVENTFACTORPMCM(ctypes.Structure):
    _fields_ = [('nResult', ctypes.c_int),
                ('wStop', ctypes.c_ushort * 2),     # 停止イベント要因
                ('wState', ctypes.c_ushort * 2)]    # 状態イベント要因

# DLL
pf = platform.system()
if pf == 'Windows':
    pmcm = ctypes.windll.PmcM
    kernel32 = ctypes.windll.Kernel32
elif pf == 'Linux':
    pmcm = ctypes.CDLL('libpmcm.so')


def main():
    class AppData:
        INVALID_ID = 9999
        board_id = INVALID_ID
        thread = None
        event_handle = None

    while True:
        print('1: open')
        print('2: setting')
        print('3: parameter')
        print('4: start')
        print('5: event')
        print('6: close')
        print('9: exit')
        try:
            chosen = int(input('> '))
        except ValueError:
            chosen = 0
        if chosen == 1:
            open_board(AppData)
        elif chosen == 2:
            setting(AppData)
        elif chosen == 3:
            parameter(AppData)
        elif chosen == 4:
            start(AppData)
        elif chosen == 5:
            event(AppData)
        elif chosen == 6:
            close_board(AppData)
        elif chosen == 9:
            exit_app(AppData)
            break
        else:
            pass
    return


def open_board(AppData):
    if AppData.board_id != AppData.INVALID_ID:
        print('Already open')
        return
    try:
        board_id = int(input('board id> '))
    except ValueError:
        board_id = AppData.INVALID_ID
    result = pmcm.PmcmOpen(board_id, b'PMC-M2C-U')
    if result == PMCM_RESULT_SUCCESS:
        print('PmcmOpen succeeded')
    else:
        print('PmcmOpen error {}'.format(result))
        board_id = AppData.INVALID_ID
    AppData.board_id = board_id
    return


def setting(AppData):
    axis = PMCM_AXIS_X + PMCM_AXIS_Y
    # センサ設定
    # オンで検知するセンサを接続している場合や、リミットスイッチを接続していない場合はモーターが動作しません
    # その場合は以下の関数を実行してセンサ設定を"オンで検知"に変更してください
    # result = pmcm.PmcmSetSensorConfig(AppData.board_id, axis, PMCM_LOGIC, 0x3F)
    # if result != PMCM_RESULT_SUCCESS:
    #     print('PmcmSetSensorConfig error {}'.format(result))
    #     return

    # パルス出力モード設定
    # 使用しているドライバに合致したパルス出力モードを選択してください
    result = pmcm.PmcmSetPulseConfig(AppData.board_id, axis, PMCM_PULSE_OUT, 7)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetPulseConfig error {}'.format(result))
        return

    # イベントマスク設定
    # 自動停止時のイベント発生を許可に設定します
    result = pmcm.PmcmSetEventMask(AppData.board_id, axis,
                                   PMCM_EVENT_STOP, 0x01)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetEventMask error {}'.format(result))
        return
    if pf == 'Windows':
        # イベントオブジェクト作成
        AppData.event_handle = kernel32.CreateEventA(None, 1, 0, None)
        # イベント設定
        result = pmcm.PmcmSetEvent(AppData.board_id, AppData.event_handle)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmSetEvent error {}'.format(result))
            return
    elif pf == 'Linux':
        # イベント設定
        result = pmcm.PmcmSetEvent(AppData.board_id)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmSetEvent error {}'.format(result))
            return
    return


def parameter(AppData):
    axis = PMCM_AXIS_X
    motion = (MOTIONPMCM * 2)()
    # X軸
    motion[0].wMoveMode = PMCM_PTP              # 動作モード
    motion[0].wStartMode = PMCM_CONST           # 起動モード
    motion[0].fSpeedRate = 1                    # 速度倍率
    motion[0].wAccDecMode = PMCM_ACC_LINEAR     # 加減速モード
    motion[0].fLowSpeed = 1000                  # 起動時速度
    motion[0].fSpeed = 1000                     # 移動速度
    motion[0].wAccTime = 0                      # 加速時間
    motion[0].wDecTime = 0                      # 減速時間
    motion[0].fSAccSpeed = 0                    # 加速S字区間
    motion[0].fSDecSpeed = 0                    # 減速S字区間
    motion[0].lSlowdown = -1                    # スローダウンポイント
    motion[0].lStep = 10000                     # 移動パルス数,移動方向
    motion[0].bAbsolutePtp = 0                  # 絶対座標指定
    # 動作パラメータ設定
    result = pmcm.PmcmSetMotion(AppData.board_id, axis, ctypes.byref(motion))
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmSetMotion error {}'.format(result))
        return
    return


def start(AppData):
    # 動作させる軸
    axis = PMCM_AXIS_X
    # 動作開始
    result = pmcm.PmcmStartMotion(AppData.board_id, axis)
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmStartMotion error {}'.format(result))
        return
    return


def event(AppData):
    if AppData.thread is not None:
        if AppData.thread.is_alive():
            return
    AppData.thread = threading.Thread(target=event_thread,
                                      args=(AppData.board_id,
                                            AppData.event_handle))
    AppData.thread.start()
    return


def event_thread(board_id, event_handle):
    if pf == 'Windows':
        # イベント発生待ち
        kernel32.WaitForSingleObject(event_handle, 0xFFFFFFFF)
        # イベントクリア
        kernel32.ResetEvent(event_handle)
    elif pf == 'Linux':
        # イベント発生待ち
        result = pmcm.PmcmWaitForEvent(board_id, 0xFFFFFFFF)
        if result != PMCM_RESULT_SUCCESS:
            print('PmcmWaitForEvent error {}'.format(result))
            return

    # イベント要因取得
    event_factor = EVENTFACTORPMCM()
    result = pmcm.PmcmGetEventFactor(board_id, ctypes.byref(event_factor))
    if result != PMCM_RESULT_SUCCESS:
        print('PmcmGetEventFactor error {}'.format(result))
        return
    if event_factor.nResult != 0:
        print('イベント失敗')
        return
    print("停止イベント要因: H'{:X}".format(event_factor.wStop[0]))
    print("状態イベント要因: H'{:X}".format(event_factor.wState[0]))
    return


def close_board(AppData):
    result = pmcm.PmcmClose(AppData.board_id)
    if result:
        AppData.board_id = AppData.INVALID_ID
        print('PmcmClose succeeded')
    else:
        print('PmcmClose falied')
    if AppData.thread is not None:
        AppData.thread.join()
    if pf == 'Windows':
        kernel32.CloseHandle(AppData.event_handle)
        AppData.event_handle = None
    return


def exit_app(AppData):
    pmcm.PmcmClose(AppData.board_id)
    if AppData.thread is not None:
        AppData.thread.join()
    if pf == 'Windows':
        kernel32.CloseHandle(AppData.event_handle)
        AppData.event_handle = None
    return


if __name__ == '__main__':
    main()

API使用例
PmcmSetSensorConfig
# X軸とY軸のPCS,INP,ALM,ORG,SD,-EL,+ELを「オンで検知」に設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmSetSensorConfig(board_id, axis, PMCM_LOGIC, 0x3F)
PmcmGetSensorConfig
# X軸のセンサ極性設定を取得します。
axis = PMCM_AXIS_X
config = ctypes.c_ushort()
result = pmcm.PmcmGetSensorConfig(board_id, axis, PMCM_LOGIC,
                                  ctypes.byref(config))
PmcmSetPulseConfig
# X軸とY軸のパルス出力モードを0に設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmSetPulseConfig(board_id, axis, PMCM_PULSE_OUT, 0)
PmcmGetPulseConfig
# X軸のパルス出力モードを取得します。
axis = PMCM_AXIS_X
config = ctypes.c_ushort()
result = pmcm.PmcmGetPulseConfig(board_id, axis,
                                 PMCM_PULSE_OUT, ctypes.byref(config))
PmcmSetSynchroConfig
# X軸とY軸の起動条件を即スタートに設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmSetSynchroConfig(board_id, axis, PMCM_SYNC_START_MODE, 0)
PmcmGetSynchroConfig
# X軸の起動条件を取得します。
axis = PMCM_AXIS_X
config = ctypes.c_ushort()
result = pmcm.PmcmGetSynchroConfig(board_id, axis,
                                   PMCM_SYNC_START_MODE, ctypes.byref(config))
PmcmSetSynchroOut
# X軸とY軸の内部同期信号出力タイミングを出力なしに設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmSetSynchroOut(board_id, axis, PMCM_SYNC_OUT_MODE, 0)
PmcmGetSynchroOut
# X軸内部同期信号出力タイミングを取得します。
axis = PMCM_AXIS_X
config = ctypes.c_ushort()
result = pmcm.PmcmGetSynchroOut(board_id, axis,
                                PMCM_SYNC_OUT_MODE, ctypes.byref(config))
PmcmSetComparatorConfig
# X軸の出力パルスコンパレータをOFFに設定します。
axis = PMCM_AXIS_X
comp = (COMPPMCM * 2)()
comp[0].wConfig = 0
comp[0].lCount = 0
result = pmcm.PmcmSetComparatorConfig(board_id, axis,
                                      PMCM_COMP_COUNTER, ctypes.byref(comp))
PmcmGetComparatorConfig
# X軸の出力パルスコンパレータ設定を取得します。
axis = PMCM_AXIS_X
comp = (COMPPMCM * 2)()
result = pmcm.PmcmGetComparatorConfig(board_id, axis,
                                      PMCM_COMP_COUNTER, ctypes.byref(comp))
PmcmSetLatchConfig
# X軸とY軸のLTC信号によるラッチ(出力パルスカウンタ)をなしに設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmSetLatchConfig(board_id, axis, PMCM_COUNTER_LATCH_LTC, 0)
PmcmGetLatchConfig
# X軸のLTC信号によるラッチ(出力パルスカウンタ)を取得します。
axis = PMCM_AXIS_X
config = ctypes.c_ushort()
result = pmcm.PmcmGetLatchConfig(board_id, axis,
                                 PMCM_COUNTER_LATCH_LTC, ctypes.byref(config))
PmcmSetEncoderConfig
# X軸とY軸のエンコーダ入力モードをアップ・ダウンの2パルス入力に設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmSetEncoderConfig(board_id, axis, PMCM_ENCODER_MODE, 3)
PmcmGetEncoderConfig
# X軸のエンコーダ入力モードを取得します。
axis = PMCM_AXIS_X
config = ctypes.c_ushort()
result = pmcm.PmcmGetEncoderConfig(board_id, axis,
                                   PMCM_ENCODER_MODE, ctypes.byref(config))
PmcmSetErcConfig
# X軸とY軸の出力論理を負論理に設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmSetErcConfig(board_id, axis, PMCM_ERC_LOGIC, 0)
PmcmGetErcConfig
# X軸の出力論理を取得します。
axis = PMCM_AXIS_X
config = ctypes.c_ushort()
result = pmcm.PmcmGetErcConfig(board_id, axis, PMCM_ERC_LOGIC,
                               ctypes.byref(config))
PmcmSetMotion
# X軸の動作パラメータを設定します。
axis = PMCM_AXIS_X
motion = (MOTIONPMCM * 2)()
motion[0].wMoveMode = PMCM_JOG
motion[0].wStartMode = PMCM_CONST
motion[0].fSpeedRate = 1
motion[0].wAccDecMode = PMCM_ACC_LINEAR
motion[0].fLowSpeed = 100
motion[0].fSpeed = 100
motion[0].wAccTime = 0
motion[0].wDecTime = 0
motion[0].fSAccSpeed = 0
motion[0].fSDecSpeed = 0
motion[0].lSlowdown = -1
motion[0].lStep = PMCM_DIR_CW
motion[0].bAbsolutePtp = 0
result = pmcm.PmcmSetMotion(board_id, axis, ctypes.byref(motion))
PmcmGetMotion
# X軸の動作パラメータを取得します。
axis = PMCM_AXIS_X
motion = (MOTIONPMCM * 2)()
result = pmcm.PmcmGetMotion(board_id, axis, ctypes.byref(motion))
PmcmSetMotionLine
# 直線補間動作パラメータを設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
motion_line = MOTIONLINEPMCM()
motion_line.wStartMode = PMCM_CONST
motion_line.fSpeedRate = 1
motion_line.wAccDecMode = PMCM_ACC_LINEAR
motion_line.fLowSpeed = 100
motion_line.fSpeed = 100
motion_line.wAccTime = 0
motion_line.wDecTime = 0
motion_line.fSAccSpeed = 0
motion_line.fSDecSpeed = 0
motion_line.lSlowdown = -1
motion_line.lStep[0] = 1000
motion_line.lStep[1] = 500
motion_line.bAbsolute[0] = 0
motion_line.bAbsolute[1] = 0
result = pmcm.PmcmSetMotionLine(board_id, axis, ctypes.byref(motion_line))
PmcmGetMotionLine
# 直線補間動作パラメータを取得します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
motion_line = MOTIONLINEPMCM()
result = pmcm.PmcmGetMotionLine(board_id, axis, ctypes.byref(motion_line))
PmcmSetMotionCp
# X軸のCP動作パラメータを2つ設定します。
axis = PMCM_AXIS_X
motion = (MOTIONPMCM * 2)()
motion[0].wMoveMode = PMCM_PTP
motion[0].wStartMode = PMCM_CONST
motion[0].fSpeedRate = 1
motion[0].wAccDecMode = PMCM_ACC_LINEAR
motion[0].fLowSpeed = 100
motion[0].fSpeed = 100
motion[0].wAccTime = 0
motion[0].wDecTime = 0
motion[0].fSAccSpeed = 0
motion[0].fSDecSpeed = 0
motion[0].lSlowdown = -1
motion[0].lStep = 1000
motion[0].bAbsolutePtp = 0
motion[1].wMoveMode = PMCM_PTP
motion[1].wStartMode = PMCM_CONST
motion[1].fSpeedRate = 1
motion[1].wAccDecMode = PMCM_ACC_LINEAR
motion[1].fLowSpeed = 100
motion[1].fSpeed = 100
motion[1].wAccTime = 0
motion[1].wDecTime = 0
motion[1].fSAccSpeed = 0
motion[1].fSDecSpeed = 0
motion[1].lSlowdown = -1
motion[1].lStep = 1000
motion[1].bAbsolutePtp = 0
result = pmcm.PmcmSetMotionCp(board_id, axis, ctypes.byref(motion), 2)
PmcmGetMotionCp
# X軸のCP動作パラメータを2つ取得します。
axis = PMCM_AXIS_X
motion = (MOTIONPMCM * 2)()
count = ctypes.c_ushort(2)
result = pmcm.PmcmGetMotionCp(board_id, axis,
                              ctypes.byref(motion), ctypes.byref(count))
PmcmStartMotion
# X軸とY軸の動作を開始します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmStartMotion(board_id, axis)
PmcmStartMotionLine
# 直線補間動作を開始します。
result = pmcm.PmcmStartMotionLine(board_id)
PmcmStartMotionCp
# X軸とY軸のCP動作を開始します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmStartMotionCp(board_id, axis)
PmcmStopMotion
# X軸とY軸のモーターを即停止します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmStopMotion(board_id, axis, PMCM_IMMEDIATE_STOP)
PmcmChangeSpeed
# Y軸の速度を2000ppsに変更します。
axis = PMCM_AXIS_Y
speed = (ctypes.c_float * 2)()
speed[0] = 0
speed[1] = 2000
result = pmcm.PmcmChangeSpeed(board_id, axis,
                              PMCM_CHG_NEW_SPEED, ctypes.byref(speed))
PmcmChangeStep
# Y軸の目標位置を5000に変更します。
axis = PMCM_AXIS_Y
step = (ctypes.c_int * 2)()
step[0] = 0
step[1] = 5000
result = pmcm.PmcmChangeStep(board_id, axis, ctypes.byref(step))
PmcmGetStatus
# X軸の制御信号入力/出力状態を取得します。
axis = PMCM_AXIS_X
status = ctypes.c_ushort()
result = pmcm.PmcmGetStatus(board_id, axis, PMCM_SIG_STATUS,
                            ctypes.byref(status))
PmcmGetEmptyCp
# X軸とY軸のCP空き動作パラメータ数を取得します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
empty = (ctypes.c_ushort * 2)()
result = pmcm.PmcmGetEmptyCp(board_id, axis, ctypes.byref(empty))
PmcmSetEventMask
# X軸とY軸の停止イベントを全てマスクに設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
result = pmcm.PmcmSetEventMask(board_id, axis, PMCM_EVENT_STOP, 0)
PmcmGetEventMask
# X軸の停止イベントマスクを取得します。
axis = PMCM_AXIS_X
config = ctypes.c_ushort()
result = pmcm.PmcmGetEventMask(board_id, axis, PMCM_EVENT_STOP,
                               ctypes.byref(config))
PmcmSetEvent(Windows)
# イベントの設定します。
kernel32 = ctypes.windll.Kernel32
event_handle = kernel32.CreateEventA(None, 1, 0, None)
result = pmcm.PmcmSetEvent(board_id, event_handle)
PmcmSetEvent(Linux)
# イベントの設定します。
result = pmcm.PmcmSetEvent(board_id)
PmcmWaitForEvent(Linuxのみ)
# イベント発生待ち(WindowsではWin32 APIのWaitForSingleObjectを使用します)。
result = pmcm.PmcmWaitForEvent(board_id, 0xFFFFFFFF)
PmcmGetEventFactor
# イベント要因を取得します。
event_factor = EVENTFACTORPMCM()
result = pmcm.PmcmGetEventFactor(board_id, ctypes.byref(event_factor))
PmcmSetCounter
# X軸の出力パルスカウンタ値を1000、Y軸の出力パルスカウンタ値を-1000に設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
data = (ctypes.c_int * 2)()
data[0] = 1000
data[1] = -1000
result = pmcm.PmcmSetCounter(board_id, axis, ctypes.byref(data))
PmcmGetCounter
# X軸とY軸の出力パルスカウンタ値を取得します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
data = (ctypes.c_int * 2)()
result = pmcm.PmcmGetCounter(board_id, axis, ctypes.byref(data))
PmcmGetLatchCounter
# X軸とY軸の出力パルスカウンタのラッチカウンタ値を取得します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
data = (ctypes.c_int * 2)()
result = pmcm.PmcmGetLatchCounter(board_id, axis, ctypes.byref(data))
PmcmSetEncoder
# X軸のエンコーダカウンタ値を1000、Y軸のエンコーダカウンタ値を-1000に設定します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
data = (ctypes.c_int * 2)()
data[0] = 1000
data[1] = -1000
result = pmcm.PmcmSetEncoder(board_id, axis, ctypes.byref(data))
PmcmGetEncoder
# X軸とY軸のエンコーダカウンタ値を取得します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
data = (ctypes.c_int * 2)()
result = pmcm.PmcmGetEncoder(board_id, axis, ctypes.byref(data))
PmcmGetLatchEncoder
# X軸とY軸のエンコーダカウンタのラッチカウンタ値を取得します。
axis = PMCM_AXIS_X + PMCM_AXIS_Y
data = (ctypes.c_int * 2)()
result = pmcm.PmcmGetLatchEncoder(board_id, axis, ctypes.byref(data))

関連情報

製品情報
ソフトウェアマニュアル