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. memcache的介绍与应用场景
  2. 【风控术语】数字金融欺诈行为名词表
  3. 音视频技术开发周刊 | 172
  4. python和stata_从Python运行Stata do文件
  5. php redis.h,swoole安装hredis支持导致php不能加载swoole扩展
  6. 微软已确认放弃Windows 10X操作系统 新功能下放
  7. mybatis的mapper.java_mybatis笔记之使用Mapper接口注解
  8. npoi excel导入html数据库,C#_.NetFramework_Web项目_NPOI_EXCEL数据导入
  9. 3D引擎优化: 分布式渲染系统能聚沙成塔
  10. 2021年中国兽医热疗室市场趋势报告、技术动态创新及2027年市场预测
  11. 机械制造作业考研题目答案分享——回转体的加工
  12. 百度网盘——下载限速问题解决方案(油猴(Tampermonkey)+百度网盘直链下载助手+IDM)
  13. WinForm PrintDocument 进行打印标签
  14. 【数据库】imp-00015
  15. Rockchip HDMI 软件开发指南
  16. android平台下OpenGL ES 3.0绘制纯色背景
  17. 大数据项目离线数仓(全 )二(数仓系统)
  18. dmesg的详细用法
  19. 多边形裁剪(Polygon Clipping) 1
  20. java写一个登录系统_用java写一个用户登陆界面

热门文章

  1. ViewPager按比例显示图片(显示下一张图片的一部分)
  2. Google Chrome 旧版本下载地址
  3. 计算机国二考多久出来的,2008年国二(国家计算机二级考试)什么时候举行?...
  4. matlab将二值图像与原图重叠_MATLAB:增加噪声,同时多次叠加噪声图和原图以及求平均图像(imnoise,imadd函数)...
  5. xcode 插件的安装使用与管理
  6. 腾讯迁移至阿里云播放器
  7. java 不等待 视频转码_java调用ffmpeg,mencoder进行视频转换,读取时长等
  8. vb与oracle数据库连接,vb.net 如何与oracle数据库连接
  9. 惊!!!笔记本外接显示器,显示器界面不能充满全屏
  10. 按键精灵移动端系列一滑块本地识别源码参考例子