1.先安装板卡和对应驱动.(测试程序运行起来,没有问题即可.)

(顺便提一句:如果官方 测试程序 | 示例,运行起来找不到IO卡说明DLL版本太新,换旧版DLL即可.)

2.官方例程给的文件打包成(C#的DLL,32 | 64和Windows 相对应;

(厂商给的DLL也是32 | 64 和Windows相对应)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace CSIOC0640
{public class Class1{[DllImport("IOC0640.dll", EntryPoint = "ioc_board_init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern int ioc_board_init();[DllImport("IOC0640.dll", EntryPoint = "ioc_board_close", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern void ioc_board_close();[DllImport("IOC0640.dll", EntryPoint = "ioc_read_inbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern int ioc_read_inbit(ushort cardno, ushort bitno);[DllImport("IOC0640.dll", EntryPoint = "ioc_read_outbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern int ioc_read_outbit(ushort cardno, ushort bitno);[DllImport("IOC0640.dll", EntryPoint = "ioc_write_outbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern uint ioc_write_outbit(ushort cardno, ushort bitno, int on_off);[DllImport("IOC0640.dll", EntryPoint = "ioc_read_inport", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern int ioc_read_inport(ushort cardno, ushort m_PortNo);[DllImport("IOC0640.dll", EntryPoint = "ioc_read_outport", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern int ioc_read_outport(ushort cardno, ushort m_PortNo);[DllImport("IOC0640.dll", EntryPoint = "ioc_write_outport", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern uint ioc_write_outport(ushort cardno, ushort m_PortNo, uint port_value);public delegate uint IOC0640_OPERATE(IntPtr operate_data);[DllImport("IOC0640.dll", EntryPoint = "ioc_int_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern uint ioc_int_enable(ushort cardno, IOC0640_OPERATE funcIntHandler, IntPtr operate_data);[DllImport("IOC0640.dll", EntryPoint = "ioc_int_disable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern uint ioc_int_disable(ushort cardno);[DllImport("IOC0640.dll", EntryPoint = "ioc_config_intbitmode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern uint ioc_config_intbitmode(ushort cardno, ushort bitno, ushort enable, ushort logic);[DllImport("IOC0640.dll", EntryPoint = "ioc_config_intbitmode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern uint ioc_config_intbitmode(ushort cardno, ushort bitno, ushort[] enable, ushort[] logic);[DllImport("IOC0640.dll", EntryPoint = "ioc_read_intbitstatus", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern int ioc_read_intbitstatus(ushort cardno, ushort bitno);[DllImport("IOC0640.dll", EntryPoint = "ioc_config_intporten", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern uint ioc_config_intporten(ushort cardno, ushort m_PortNo, uint port_en);[DllImport("IOC0640.dll", EntryPoint = "ioc_config_intportlogic", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern uint ioc_config_intportlogic(ushort cardno, ushort m_PortNo, uint port_logic);[DllImport("IOC0640.dll", EntryPoint = "ioc_read_intportmode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern uint ioc_read_intportmode(ushort cardno, ushort m_PortNo, uint[] enable, uint[] logic);[DllImport("IOC0640.dll", EntryPoint = "ioc_read_intportstatus", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern int ioc_read_intportstatus(ushort cardno, ushort m_PortNo);[DllImport("IOC0640.dll", EntryPoint = "ioc_set_filter", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]public static extern uint ioc_set_filter(ushort cardno, double filter);}
}

3.官方给的DLL还有上面生成的DLL复制到py程序运行目录.

4.不多说python贴上来 .

(import clr 之前 需要install pythonnet ;下来C# | .NET那一套就能直接用了.)

{用winform的定时器读取输入口}

from tkinter import ttk
from tkinter import messagebox
from tkinter import *
import tkinter as tk
import tkinter.messagebox
import os,sys,time
import tkinter.filedialog
def cmd(s="pause"):os.system(s)
from ctypes import *
import sys,time
from tkinter import Tk,Frame
import clr
import System
from System import String, Char, Int32,UInt16, Int64, Environment, IntPtr
print(f"{clr.AddReference('System')}")
print(f"{clr.AddReference('CSIOC0640')}")
import CSIOC0640
print("Loading complete");
if __name__=='__main__': i=0nCard = CSIOC0640.Class1.ioc_board_init(); #CSIOC0640.Class1.ioc_board_close();    if (nCard <= 0):System.Windows.Forms.MessageBox.Show("未找到IOC0640控制卡!", "警告!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);def IoCardSetOn(x1=1,x2=0):#CSIOC0640.Class1.ioc_write_outbit(0,x1,x2); def IoCardSetOff(x1=1,x2=1):CSIOC0640.Class1.ioc_write_outbit(0,x1,x2);def IoCardGet(x1=1):#print(f"type:= {type(CSIOC0640.Class1.ioc_read_inbit(0,x1))}")#返回 int类型 0 1;return CSIOC0640.Class1.ioc_read_inbit(0,x1)   Timer_Flag=Falsedef IoCardtim(x1=1,x2=1):#无论如何这个函数一定要有两个参数;否则不能正常执行;global i;global Timer_Flag;i=i+1;if Timer_Flag==False:Timer_Flag=TrueIoCardSetOn()else:Timer_Flag=FalseIoCardSetOff()print(f"定时器事件计次{i}")for I,n in enumerate(range(1,32+1,1)):print(f"In{I+1}:= {IoCardGet(n)}")#遍历输入状态映射到列表 | 算了 先输出看看passt = System.Timers.Timer(500);t.Elapsed += System.Timers.ElapsedEventHandler(IoCardtim);#到达时间的时候执行事件;t.AutoReset = True;#设置是执行一次(false)还是一直执行(true);t.Enabled = True;#是否执行System.Timers.Timer.Elapsed事件;#*******************************************a=Tk()a.title('IOC0640')screenwidth = a.winfo_screenwidth()  # 屏幕宽度screenheight = a.winfo_screenheight()  # 屏幕高度width = 1000height = 500x = int((screenwidth - width) / 2)y = int((screenheight - height) / 2)a.geometry('{}x{}+{}+{}'.format(width, height, x, y))  # 大小以及位置a.geometry('400x400+100+100')ICO="3D.ico"#a.iconbitmap(f'{ICO}')cbox001 = ttk.Combobox(a)# 创建cbox001.pack()#.place(x=0, y=80)    #绘制cbox001['value'] = ('1','2','3')#列表 #{str(cbox001.get())} {str(cbox001.current()+1)}cbox001.current(0)#设置默认def func(event):# result=tkinter.messagebox.askokcancel ("......(确定/取消).",f"名称: !") #下拉菜单索引if result==True:print(f"result={result};")else:print(f"result={result};")passcbox001.bind("<<ComboboxSelected>>",func)# lb1 = Label(a,text='111', bg='purple', );lb1.place (x=20,y=80)lb2 = Label(a,text='222');lb2.place (x=16,y=120);def click_button(): print("开");IoCardSetOn(1)        button = tk.Button(a,text='开',bg='#8cb5b3',width=10, height=2,command=click_button)button.place(x=20, y=20) def click_button_(): print("关");IoCardSetOff(1)button_ = tk.Button(a,text='关',bg='#8cb5b3',width=10, height=2,command=click_button_)button_.place(x=20, y=80) def click_button___():print("全开");for n in range(1,32+1,1):  IoCardSetOn(n)button___ = tk.Button(a,text='全开',bg='#8cb5b3',width=10, height=2,command=click_button___)button___.place(x=20, y=140) def click_button____(): print("全关");for n in range(1,32+1,1):  IoCardSetOff(n)    button____ = tk.Button(a,text='全关',bg='#8cb5b3',width=10, height=2,command=click_button____)button____.place(x=120, y=140) def QueryWindow():result=tkinter.messagebox.askokcancel ("(确定/取消)",f"确定关闭??") #if result==True:print(f"result={result};")try:a.destroy()#关闭窗口pass except:passelse:print(f"result={result};")a.protocol('WM_DELETE_WINDOW', QueryWindow)#注册a.mainloop()

5.运行起来.

python操作雷赛IO卡(IOC0640)相关推荐

  1. python操作excel及爬取美赛证书

    今天美赛成绩出来了,S奖,有点遗憾.但工作还是要继续,因为要下载校队的获奖证书,所以使用python爬虫来爬取证书,省点事. python操作excel 在这里我选择pandas库来操作excel,详 ...

  2. python和R文件IO操作对比及dataframe创建方式对比:read_csv、to_csv、write.csv、 data.frame、pd.DataFrame

    python和R文件IO操作对比及dataframe创建方式对比 很多工程师可能刚开始的时候只熟悉python或者R其中的一个进行数据科学相关的任务. 那么如果我们对比这学习可以快速了解语言设计背后的 ...

  3. python open写入_Python IO操作文件读取和写入、open函数的mode参数、buffering,文件缓冲区...

    IO编程 文件读写 打开文件 open(file, mode='r', buffering=None, encoding=None, errors=None, newline=None, closef ...

  4. 21天学Python --- 打卡4:Python操作Mysql,Sqlserver

    21天学Python --- 打卡4:Python操作Mysql,Sqlserver 1.Execute Query 1.1 Install Plugins 1.2 Conn Parameters 1 ...

  5. 【阿尼亚喜欢BigData】“红亚杯”数据分析进阶—使用Python操作Hive专题赛——满分解析③

    大家好,喜欢Bigdata的阿尼亚来了!希望大家会喜欢阿尼亚的文章!!哇酷哇酷!!! 本次为师傅们带来的是"红亚杯"数据分析进阶-使用Python操作Hive专题赛--满分解析系列 ...

  6. 【阿尼亚喜欢BigData】“红亚杯”数据分析进阶—使用Python操作Hive专题赛——满分解析②

    大家好,喜欢Bigdata的阿尼亚来了!希望大家会喜欢阿尼亚的文章!!哇酷哇酷!!! 本次为师傅们带来的是"红亚杯"数据分析进阶-使用Python操作Hive专题赛--满分解析系列 ...

  7. 运动控制卡课程:固高,凌华,雷赛,(单一款学习时间45天,要求有C语言基础)凭良学校

    一.雷赛运动控制卡(雷赛dmc5480.smc6480)(可单独学习,要求有C#语言基础) 简介: DMC5480是一款基于PCI总线的高档脉冲式运动控制卡,配置了512段缓冲,使得实时处理能力更强: ...

  8. 台达伺服b3设置_雷赛BAC332E运动控制器控制台达B3伺服电机的使用入门介绍(精)...

    测试视频见下一篇文章! 先来看两个系统结构: 系统结构1 系统结构2 我本次是如下的一个系统结构: 系统结构3 BAC332E运动控制器可使用BASIC语言编程,独立运行(不需要PC机):也可以让BA ...

  9. DM3E,雷赛步进驱动器

    2000电流(mA) 2001一圈脉冲 2048母线电压 2051电机方向 //0正转 1反转 2057清除报警 // 1清除 2058使能2151从站地址6098回零方式 //35和37以当前位置, ...

最新文章

  1. 日记——2019-03-08
  2. 一款数据人专属的红包封面,速度领,手慢无
  3. Objective-C 深复制和浅复制与NSCopying协议
  4. python生成器的使用_应该如何以及为什么使用Python生成器
  5. 前端JavaScript之BOM与DOM
  6. Leetcode#102Binary Tree Level Order Traversal
  7. 2013蓝桥杯C++B:第39阶台阶(递归法);前缀判断
  8. 对数组操作[:,:4]
  9. cad---菜单,工具栏,屏幕菜单,增强工具栏
  10. js 大地坐标转经纬度
  11. 74CMS 3.0任意文件写入漏洞
  12. Vue + Refresh Token
  13. 在 Windows10 系统下重新安装 Ubuntu22.04 系统
  14. OpenCV:字符分割——方向投影法
  15. MSCI宣布与Royalty Pharma结成战略联盟,推出生命科学指数
  16. 华为交换机的浮动路由及NQA动态切换
  17. [Intensive Reading]目标检测(object detection)系列(九) YOLOv3:取百家所长成一家之言
  18. 北科大计算机与通信工程博士,2015年北科大计算机与通信工程学院考研拟录取名单...
  19. [转载]三联生活周刊:12万亿财富疯狂膨胀人人都是股神
  20. 您可以免费使用高质量照片的网站

热门文章

  1. 解决win10提示无法开启SENS服务
  2. 95后离职汇智动力,现在月薪9k,哭着说出经历!
  3. bash: cat/etc/group: 没有那个文件或目录
  4. 存储环境启动关闭顺序
  5. 学习PLC必须要知道的小常识
  6. Idea关联java documentation帮助文档
  7. 关于VISIO绘图如何清晰导入WORD保持不变型,不留白边
  8. 人体存在感应器,毫米波雷达智能化感知,静止存在方案应用
  9. 新手学习大数据技术如何入门?
  10. java实现视频上传和播放SpringMVC + Mybatis + ckplayer+ffmpeg+mencoder