示例#1
0
        public CKM55LC_M(byte index, BaseLine line)
            : base(index, "CKM55LC_M")
        {
            Line  = line;
            _lock = new object();

            string str = Line.GetType().ToString();

            if (str == "Lines.Com.ComLine")
            {
                ComLine cl = (ComLine)line;

                _modbus = new Modbus(index);
                _modbus.InterFrameGap         = cl.InterFrameGap;
                _modbus.CaptureLineArgs      += new CaptureLineArgsEventHandler(cl.CaptureLine);
                _modbus.ReleaseLineArgs      += new ReleaseLineArgsEventHandler(cl.ReleaseLine);
                _modbus.DiscardSendBuffer    += new CommonEventHandler(cl.DiscardSendBuffer);
                _modbus.DiscardReceiveBuffer += new CommonEventHandler(cl.DiscardReceiveBuffer);
                _modbus.Send    += new IOEventHandler(cl.Send);
                _modbus.Receive += new IOEventHandler(cl.Receive);

                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("初始化CKM55LC_M[{0}]绑定ComLine[{1}]", index, cl.Name);
                }
            }
            else if (str == "Lines.Ethernet.NetLine")
            {
            }
            else
            {
                Log.Error("unsupported Line type:" + str);
                throw new Exception("unsupported Line type:" + str);
            }

            //异步操作Handler对象初始化
            _SetRegisterHandle = new GetSetRegisterHandler(SetRegister);
            _GetRegisterHandle = new GetSetRegisterHandler(GetRegister);

            //各类寄存器对象初始化
            _RunValues                   = new RunValue();
            _RunValues.GetRegister      += new GetSetRegisterHandler(GetRegister);
            _RunValues.GetRegisterAsync += new GetSetRegisterAsyncHandler(GetRegisterAsync);

            _MonitorValues                   = new MonitorValue();
            _MonitorValues.GetRegister      += new GetSetRegisterHandler(GetRegister);
            _MonitorValues.GetRegisterAsync += new GetSetRegisterAsyncHandler(GetRegisterAsync);

            _ControlSets = new ControlSet();
            _ControlSets.SetRegisterAsync += new GetSetRegisterAsyncHandler(SetRegisterAsync);

            _DiagnosisValues                   = new DiagnosisValue();
            _DiagnosisValues.GetRegister      += new GetSetRegisterHandler(GetRegister);
            _DiagnosisValues.GetRegisterAsync += new GetSetRegisterAsyncHandler(GetRegisterAsync);

            _ProtectSets                   = new ProtectSet();
            _ProtectSets.GetRegister      += new GetSetRegisterHandler(GetRegister);
            _ProtectSets.GetRegisterAsync += new GetSetRegisterAsyncHandler(GetRegisterAsync);
            _ProtectSets.SetRegisterAsync += new GetSetRegisterAsyncHandler(SetRegisterAsync);

            _SystemSets                   = new SystemSet();
            _SystemSets.GetRegister      += new GetSetRegisterHandler(GetRegister);
            _SystemSets.GetRegisterAsync += new GetSetRegisterAsyncHandler(GetRegisterAsync);
            _SystemSets.SetRegisterAsync += new GetSetRegisterAsyncHandler(SetRegisterAsync);

            _IdentityValues                   = new IdentityValue();
            _IdentityValues.GetRegister      += new GetSetRegisterHandler(GetRegister);
            _IdentityValues.GetRegisterAsync += new GetSetRegisterAsyncHandler(GetRegisterAsync);
            _IdentityValues.SetRegister      += new GetSetRegisterHandler(SetRegister);

            _CalibrationValues                   = new CalibrationValue();
            _CalibrationValues.GetRegister      += new GetSetRegisterHandler(GetRegister);
            _CalibrationValues.GetRegisterAsync += new GetSetRegisterAsyncHandler(GetRegisterAsync);
            _CalibrationValues.SetRegisterAsync += new GetSetRegisterAsyncHandler(SetRegisterAsync);
            _CalibrationValues.SetRegister      += new GetSetRegisterHandler(SetRegister);

            GetAllRegistersAsync();
        }