2010/01/28 | C# 通用DLL dll触发事件 调用dll的事件通用用户驱动源代码 源码
类别(心情故事) | 评论(0) | 阅读(455) | 发表于 09:12

你还为自己的设备驱动无法集成到组态软件里而感到困惑吗?我做了一个通用的c# dll驱动,可对dll中的事件就行调用,用户只需要按照该dll的格式完成自己的驱动就行了,这样我的APMC先进控制 组态软件可以加载任何驱动!下面是驱动代码:

using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;
namespace iScadaUserDLL
{
    public delegate void iScadaEvent(object DriverName, object[] DataItem);
    public class UserDLL
    {
        public  event iScadaEvent iScadaChangedEvent;
        private string DriverName = "iScadaUserDLL.UserDLL";

        private int n = 0;
      

        private System.Timers.Timer mTimer;

        public UserDLL()
        {
            Start();
        }
        public bool Start()
        {
            mTimer = new Timer();
            mTimer.Elapsed += new ElapsedEventHandler(mTimer_Elapsed);
            mTimer.Interval = 2000;
            mTimer.Start();
            return true;
        }
        public bool Stop()
        {
            mTimer.Enabled = false;
            return true;
        }
        public bool Write2Dev(string Address, object value)
        {
            return true;
        }
        private void mTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            n++;
            object[] o = new object[2];
            o[0] = n * 2 + 1;
            o[1] = 111;

            iScadaChangedEvent(DriverName, o);
        }
    }
}
 

0

评论Comments