Win32环境下一种通用控制软件的实现方法

摘 要:介绍了一种通用的控制系统软件的实现方法,该软件架构将复杂的控制系统所有硬件传感器经数学抽象、归类后,使用流对象统一处理,控制软件仅对流操作。所有硬件传感器后台读写用独立线程完成,线程由各自事件同步,同步事件由中断产生,中断由脉冲设备或者定时器产生,软件缓冲区与硬件缓冲区使用临界区对象同步,硬件传感器读写完成后发送用户消息给前台窗口,这样,控制软件中访问硬件的代码段同其他代码段完全独立,特别地,通讯协议等复杂的问题在此软件架构下仅以一条控制函数形式出现。无论控制对象由多少种传感器搭建,无论设备多少,监控软件的架构是一致的,复杂的控制问题就转化为对某类流设备的读写问题。

  关键词:win32编程;传感器;事件;临界区;用户消息;流对象
implementation of & universal control software in win32 circumstance
cai wenzhai
(the 39th institute,electronics science & technology group corp oration of china,xi′an,710065,china)
  abstract:in this paper,an universal control system software method is introduced,the method abstract hardware device with steam object, cont rol software only operate the steam objectread and write all hardware sensor d atausing each threads singly,each the event synchronize the threads, synchroni zation event is created by the interrupt,the interrupt is created by hardware impulse device or timer, critical section object synchronize the software and ha rdware buffer after read and write the data of hardware sensor,the thread sendmessage to main windows,in the way control the code segment of operate hardwareandother code segment areindependencespecially, the complex problem of ha rdwaredevice communication prototal appears in the only function form, no matt er what control object is made of what sensor type, no matter what there are howmany hardware device, monitor and control software framework is consistent and debugis convenience,complicated control problem translate to some software ste am object read and write

  keywords:win32 programming; sensor; event;critical section;user message; steam object
1引言

  工控应用已遍及各行各业,特别是随着计算机的普遍降价、由pc机建构的控制系统也越来越多,该类控制系统的优点是开发人员可以用高级语言及大量的现有软件快速建构成自己的软件系统。本文主要介绍了这类应用的一种实现方法:该方法是将所有硬件i/o部分按类型分类。将他们各自的读写过程全部函数化。经数学抽象后归一化为流对象统一处理:传感器→流→(初始化函数,流读,流写,关闭)→应用软件读写线程→用户消息→主窗口。经这样的抽象后,无论控制系统多么复杂,硬件传感器是什么形式,在这种软件架构下全使用统一的软件方法处理。
2控制系统硬件结构

  设想一类控制系统是如下结构建成的,主控台完成同5个测量站的通信并指挥测量站按确定 方程运动。主控台通过与网络与中心站完成双向i/o、主控台可以单独遥控某一测量站设备单独工作。大的硬件控制如图1所示。

  主控台与测量站用rs 232通信,经modem接连,与其他测量设备由a/d、d/a连接卡连接,与中心机通信由网络连接。

  在构建此控制系统软件时,不妨将问题扩展,假定不考虑具体的设备控制对象,不考虑具体的应用类型,考虑一种更复杂的控制系统:设想控制系统如图2所示。

  控制计算机使用p4 2.8或p4 2.4 ghz处理器,具体的控制对象设想为抽象传感器即可。
3控制系统软件构架

  本文提供的软件构架为:对每类控制硬件设备而言,访问该类硬件无非对应如下几个函数:

  (1) 硬件初始化函数。

  (2) 硬件读函数。

  (3) 硬件写函数。

  (4) 硬件刷新及关闭函数。

  这样,经过数学抽象后,每类硬件访问不超过这5条函数。无论控制系统由什么硬件传感器 搭建,对一类传感器而言。访问他仅需要几条语句而已。假设按类型编制了相关的i/o函数。

  该软件系统的主要思路为:任一控制对象(传感器)均可设想为流设备、线程完成流读 写,读写时序由中断或其他设备事件决定。一旦硬件设备i/o完成,用临界区锁住数据,导入软设备缓冲区。用户交互部分仅同软设备缓冲区打交道,与设备硬件无关。控制函数只负责设备缓

  • Win32环境下一种通用控制软件的实现方法已关闭评论
    A+
发布日期:2019年07月02日  所属分类:参考设计