三菱机器人MelfaRxM.OCX控件的python用法

1.   安装控件  \MelfaRXM\MelfaRXM_Dev\Redist\Installer

2. 在WINDOWS/System32里找到MelfaRxM.ocx

3.把OCX控件转成C#的DLL

a.打vs的开发人员命令行

b.把刚刚的OCX放到命令行显示的目录

c.在命令输入 :   aximp MelfaRxM.ocx

生成的DLL就是pythonnet可用调用的DLL的

4.pythonnet的调用

# -*- coding: utf-8 -*-
"""
Created on Wed May  6 23:24:19 2020

@author: Martin
"""
import time
import clr
import sys
sys.path.append(r"./MISB_ReferencedAssemblies")
clr.AddReference('AxMELFARXMLib')
clr.AddReference('MELFARXMLib')
import AxMELFARXMLib
import System

class robot(System.Windows.Forms.Form):
    #---初始化
    def __init__(self,robot):
        self.robot = robot
        print(self.robot)
        self.InitializeComponent()
        
    def InitializeComponent(self):  
        self.ctrMelfaRxM=AxMELFARXMLib.AxMelfaRxM() 
        ((System.ComponentModel.ISupportInitialize)(self.ctrMelfaRxM)).BeginInit()
        self.Controls.Add(self.ctrMelfaRxM)
        ((System.ComponentModel.ISupportInitialize)(self.ctrMelfaRxM)).EndInit()     
        if self.ctrMelfaRxM.ServerLive()==False:
            self.ctrMelfaRxM.ServerStart()  
                    
    def sv_off(self):
        sSendDataOFF = "1" + "\n" +"0"
        lStatus = self.ctrMelfaRxM.RequestServiceM(self.robot, 403, len(sSendDataOFF), sSendDataOFF, 0, 0, 0)  
        return lStatus    
        
    def sv_on(self):
        sSendDataON = "1" + "\n" +"1"
        lStatus = self.ctrMelfaRxM.RequestServiceM(self.robot, 403, len(sSendDataON), sSendDataON, 0, 0, 0)
        return lStatus
           
    def read_program_list(self):
        lStatus = self.ctrMelfaRxM.RequestServiceM(self.robot, 106, 0, "", 0, 0, 0)        
        return lStatus
        
def runApp():     
    global robot1
    thread=System.Threading.Thread(System.Threading.ThreadStart(runthread))
    thread.SetApartmentState(0)
    thread.Start()
    time.sleep(1)
#    robot1.Hide()
    
def runthread():
    global robot1  
    robot1 = robot(1)   
    System.Windows.Forms.Application.Run(robot1)             
    pass  

global robot1              
if __name__ == "__main__":   
    runApp()    
    pass

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值