Blog

My IToolS Demo Driver

Un esempio che mostra come creare un driver itools

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace MyDemo
{
   using IToolS.IOServers;
   using IToolS;
   using IToolS.Data;

   [IOServerManifest("MyDemo.MyDemoDriver.txt")]
   [IOServerFamilyAttribute("Demo")]
   [IOServerName("MyDemoDriver")]
   [IOServerArea(".*")]
   [IOServerTypes(true)]
   public class MyDemoDriver : IToolS.IOServers.MasterIOServerBase
   {
      private Dictionary<string, object> m_table;


      public MyDemoDriver()
      {
         PreSetRead = true;
         PreSetWrite = true;

         AllReadRequestInReadDataRequest = true;
         AllWriteRequestInWriteDataRequest = true;

         UseObjectsConvention = true;

         m_table = new Dictionary<string, object>();
      }

      protected override Channel CreateChannel()
      {
         return null;
      }


      protected override IOServerErrors ReadDataPack(VariablePack block, out object[] values, bool synchro)
      {
         values = new object[block.Count];

         for (int i = 0; i < block.Count; i++)
         {
            var variable = block.Variables[i];

            if (!m_table.ContainsKey(variable.Address))
               m_table[variable.Address] = variable.TypeBase.GetDefault();

            values[i] = m_table[variable.Address];
         }

         return IOServerErrors.Ok;
      }

      protected override IOServerErrors WriteDataPack(VariablePack block, object[] writeValues, bool synchro)
      {
         for (int i = 0; i < block.Count; i++)
         {
            var variable = block.Variables[i];

            m_table[variable.Address] = writeValues[i];
         }

         return IOServerErrors.Ok;
      }


      public override bool CheckReadRequestPack(IVariableInternal root, IVariableInternal join, VariablePack pack)
      {
         return true;
      }

      public override bool CheckWriteRequestPack(IVariableInternal root, IVariableInternal join, VariablePack pack)
      {
         return true;
      }

      public override bool CheckVariable(IVariableInternal variable)
      {
         return true;
      }
   }
}

 

MyDemoDriver.zip

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *