private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { //dispose managed state (managed objects). if (MasterMySQL != null) { MasterMySQL.Dispose(); } if (BackupMySQL != null) { BackupMySQL.Dispose(); } } // free unmanaged resources (unmanaged objects) and override a finalizer below. // set large fields to null. DriversConf = null; Status = null; disposedValue = true; } }
/// <summary> /// Class Constructor. /// <param name="DriverConf">Driver Configuration Object</param> /// <param name="DataAreaConf">Data Area Block Configuration Object Array</param> /// <param name="StatObject">Object for Status Reporting</param></summary> public DriverS7(DVConfClass DriverConf, DAConfClass[] DataAreaConf, Stat.StatReport StatObject) { MasterDriverConf = DriverConf; MasterDataAreaConf = DataAreaConf; //The Status Report Object Status = StatObject; isInitialized = false; isConnected = false; }
/// <summary> /// Class contructor, receives the Driver Configuration. /// <param name="DriverConf">Driver Configuration Object</param> /// <param name="StatObject">Object for Status Reporting</param></summary> public DriverXWave(DVConfClass DriverConf, Stat.StatReport StatObject) { //Copy the Driver Configuration. MasterDriverConf = DriverConf; NumVars = new DriverConfig.nVars(); DataInit = new VarTree[1, 1]; //The Status Report Object Status = StatObject; isInitialized = false; isConnected = false; }//END Constructor
/// <summary> /// Class contructor. /// <param name="DriverConf">Driver Configuration Object</param> /// <param name="DataAreaConf">Data Area Block Configuration Object Array</param> /// <param name="StatObject">Object for Status Reporting</param></summary> public DriverModbusTCP(DVConfClass DriverConf, DAConfClass[] DataAreaConf, Stat.StatReport StatObject) { MasterDriverConf = DriverConf; MasterDataAreaConf = DataAreaConf; //The Status Report Object Status = StatObject; isInitialized = false; isConnected = false; //Byte register order. HighLow=Big-endian. RegOrder = ModbusClient.RegisterOrder.HighLow; }
/// <summary> /// Class Constructor. /// <param name="Server">Server configuration struct.</param> /// <param name="iamMaster">Defines if its Master=true, for the reporting</param></summary> public DB_MySQL(DBConfClass.ServerConf Server, bool iamMaster) { DBConfig = Server; if (iamMaster) { Status = new Stat.StatReport((int)Stat.StatReport.IDdef.DB); } else { Status = new Stat.StatReport((int)Stat.StatReport.IDdef.DBbackup); } isInitialized = false; }
/// <summary> /// Class Constructor. /// *This method is not thread safe* /// <param name="DBConfigFile">Configuration Object.</param> </summary> public DB_Main(DBConfig DBConfigFile) { DBConfClass.ServerConf Master, Backup; //Main Configuration isInitialized = false; //Create the list of drivers. DriversConf = new List <DriverComm.DVConfDAConfClass>(1); //Master Server Configuration Master.URL = DBConfigFile.MainServer.URL; Master.Type = DBConfigFile.MainServer.Type; Master.Protocol = DBConfigFile.MainServer.Protocol; Master.Port = DBConfigFile.MainServer.Port; Master.Username = DBConfigFile.MainServer.User1; Master.Passwd = DBConfigFile.MainServer.Passw1; Master.Enable = DBConfigFile.MainServer.Enable; Master.DBname = DBConfigFile.MainServer.DBname; //Backup Server Configuration Backup.URL = DBConfigFile.BackupServer.URL; Backup.Type = DBConfigFile.BackupServer.Type; Backup.Protocol = DBConfigFile.BackupServer.Protocol; Backup.Port = DBConfigFile.BackupServer.Port; Backup.Username = DBConfigFile.BackupServer.User1; Backup.Passwd = DBConfigFile.BackupServer.Passw1; Backup.Enable = DBConfigFile.BackupServer.Enable; Backup.DBname = DBConfigFile.BackupServer.DBname; //Create the Conf Object DatabaseConf = new DBConfClass(Master, Backup); //The Status Object Status = new Stat.StatReport((int)Stat.StatReport.IDdef.DBall, FileLog: true); } //END Class Constructor
/// <summary> /// Class Constructor. /// <param name="DNum">Driver number, ID of the driver in the configuration.</param> /// <param name="DriverConfigObj">Object with the Driver configuration</param></summary> public DriverGeneric(int DNum, DriverConfig DriverConfigObj) { int DACount, i, DVindex; thisDriverConf = new DVConfClass(); //Reading and Writing Flags Init iamReading = false; iamWriting = false; thisDriverConf.Enable = false; isInitialized = false; Status = new Stat.StatReport(DNum, FileLog: true); Status.ResetStat(); //Check Driver Number is not out of bounds if ((DriverConfigObj.DriversConf.Length >= DNum) && (DNum > 0)) { //Driver index start from 0, while ID start from 1. ID=0 is reserved to the System. DVindex = DNum - 1; //General Driver Configuration parameters thisDriverConf.ConnConfig(DriverConfigObj.DriversConf[DVindex].ID, DriverConfigObj.DriversConf[DVindex].Enable, DriverConfigObj.DriversConf[DVindex].Type, DriverConfigObj.DriversConf[DVindex].CycleTime, DriverConfigObj.DriversConf[DVindex].Timeout); if (thisDriverConf.Enable) { //Driver Specific configuration parameters switch (thisDriverConf.Type) { case DriverConfig.DriverType.XWave: thisDriverConf.ConfXwave(DriverConfigObj.DriversConf[DVindex].Address, DriverConfigObj.DriversConf[DVindex].PortTCP, DriverConfigObj.DriversConf[DVindex].PortUDP, DriverConfigObj.DriversConf[DVindex].DefFilePath); break; case DriverConfig.DriverType.S7_TCP: thisDriverConf.ConfS7(DriverConfigObj.DriversConf[DVindex].Address, DriverConfigObj.DriversConf[DVindex].Rack, DriverConfigObj.DriversConf[DVindex].Slot); break; case DriverConfig.DriverType.ModbusTCP: thisDriverConf.ConfModbusTCP(DriverConfigObj.DriversConf[DVindex].Address, DriverConfigObj.DriversConf[DVindex].PortTCP); break; case DriverConfig.DriverType.ModbusRTU: thisDriverConf.ConfModbusRTU(DriverConfigObj.DriversConf[DVindex].PortRTU, DriverConfigObj.DriversConf[DVindex].RTUid, DriverConfigObj.DriversConf[DVindex].RTUBaud, DriverConfigObj.DriversConf[DVindex].RTUParity, DriverConfigObj.DriversConf[DVindex].RTUStop); break; default: // Disable the driver as it was not configured properly. thisDriverConf.Enable = false; Status.NewStat(StatType.Warning, "Wrong Driver Config Params: Driver Type."); break; } if (thisDriverConf.Type != DriverConfig.DriverType.XWave) { //Run thru all the DataAreas and copy the ones that has the link to the Driver ID. DACount = 0; foreach (DataAreaConf DataAreaElement in DriverConfigObj.DataAreasConf) { if (DataAreaElement.ID_Driver == thisDriverConf.ID) { if (DataAreaElement.Enable) { DACount++; } } } if (DACount > 0) { thisAreaConf = new DAConfClass[DACount]; ExtData = new DataExtClass[DACount]; thisDriverConf.NDataAreas = DACount; i = 0; foreach (DataAreaConf DataAreaElement in DriverConfigObj.DataAreasConf) { if ((DataAreaElement.ID_Driver == thisDriverConf.ID) && (DataAreaElement.Enable)) { thisAreaConf[i] = new DAConfClass(DataAreaElement.ID, DataAreaElement.ID_Driver, DataAreaElement.Enable, DataAreaElement.Write, DataAreaElement.ToHist, DataAreaElement.DataType, DataAreaElement.DB_Number, DataAreaElement.StartAddr, DataAreaElement.AmountVar); ExtData[i] = new DataExtClass(); //Asign the configuration section to the data area. ExtData[i].AreaConf = thisAreaConf[i]; //VarNames ExtData[i].VarNames = new string[DataAreaElement.AmountVar]; ExtData[i].FirstInit = false; //Create the Data container. if (DataAreaElement.DataType != DriverConfig.DatType.Undefined) { //Reading and Writing Flags Setup if (!thisAreaConf[i].Write) { iamReading = true; } if (thisAreaConf[i].Write) { iamWriting = true; } switch (DataAreaElement.DataType) { case DriverConfig.DatType.Bool: ExtData[i].Data.dBoolean = new bool[DataAreaElement.AmountVar]; break; case DriverConfig.DatType.Byte: ExtData[i].Data.dByte = new byte[DataAreaElement.AmountVar]; break; case DriverConfig.DatType.Word: ExtData[i].Data.dWord = new UInt16[DataAreaElement.AmountVar]; break; case DriverConfig.DatType.DWord: ExtData[i].Data.dDWord = new UInt32[DataAreaElement.AmountVar]; break; case DriverConfig.DatType.sDWord: ExtData[i].Data.dsDWord = new Int32[DataAreaElement.AmountVar]; break; case DriverConfig.DatType.Real: ExtData[i].Data.dReal = new float[DataAreaElement.AmountVar]; break; default: //Disable this Driver, as it has a configuration problem. Status.NewStat(StatType.Warning, "Wrong Driver Config Params: Data Area Type."); thisDriverConf.Enable = false; break; } } else { Status.NewStat(StatType.Warning, "Wrong Driver Config Params: Data Area Type."); } i++; } //DataArea_Driver_ID==Driver_ID .and. DataArea is Enabled } //For each DataArea } //END Data Area Count >0 else { Status.NewStat(StatType.Warning, "Wrong Driver Config Params: No Data Areas Configured."); }//ELSE Data Area Count >0 } else if (thisDriverConf.Type == DriverConfig.DriverType.XWave) { //Special case for the XWave Driver. DACount = 4; thisDriverConf.NDataAreas = DACount; thisAreaConf = new DAConfClass[DACount]; ExtData = new DataExtClass[DACount]; //Reading and Writing Flags (The Xwave only reads data in this edition) iamReading = true; iamWriting = false; //Initialize the driver to get the amount of variables for each type. ObjDriverXWave = new XWave.DriverXWave(thisDriverConf, Status); //The XWave Driver requires initialization to know the amount of data to be addressed. ObjDriverXWave.Initialize(); //Configure each area acordingly. if (ObjDriverXWave.isInitialized) { //Bool Areas. ExtData[0] = new DataExtClass(); if (ObjDriverXWave.NumVars.nBool > 0) { thisAreaConf[0] = new DAConfClass(1, thisDriverConf.ID, true, false, true, DriverConfig.DatType.Bool, 0, "0", ObjDriverXWave.NumVars.nBool); ExtData[0].Data.dBoolean = new bool[ObjDriverXWave.NumVars.nBool]; ExtData[0].VarNames = new string[ObjDriverXWave.NumVars.nBool]; ExtData[0].FirstInit = false; } else { thisAreaConf[0] = new DAConfClass(1, thisDriverConf.ID, false, false, false, DriverConfig.DatType.Bool, 0, "0", ObjDriverXWave.NumVars.nBool); } ExtData[0].AreaConf = thisAreaConf[0]; //Unsigned Double Word Areas. ExtData[1] = new DataExtClass(); if (ObjDriverXWave.NumVars.nDWord > 0) { thisAreaConf[1] = new DAConfClass(2, thisDriverConf.ID, true, false, true, DriverConfig.DatType.DWord, 0, "0", ObjDriverXWave.NumVars.nDWord); ExtData[1].Data.dDWord = new UInt32[ObjDriverXWave.NumVars.nDWord]; ExtData[1].VarNames = new string[ObjDriverXWave.NumVars.nDWord]; ExtData[1].FirstInit = false; } else { thisAreaConf[1] = new DAConfClass(2, thisDriverConf.ID, false, false, false, DriverConfig.DatType.DWord, 0, "0", ObjDriverXWave.NumVars.nDWord); } ExtData[1].AreaConf = thisAreaConf[1]; //Signed Double Word Areas. ExtData[2] = new DataExtClass(); if (ObjDriverXWave.NumVars.nsDWord > 0) { thisAreaConf[2] = new DAConfClass(3, thisDriverConf.ID, true, false, true, DriverConfig.DatType.sDWord, 0, "0", ObjDriverXWave.NumVars.nsDWord); ExtData[2].Data.dsDWord = new Int32[ObjDriverXWave.NumVars.nsDWord]; ExtData[2].VarNames = new string[ObjDriverXWave.NumVars.nsDWord]; ExtData[2].FirstInit = false; } else { thisAreaConf[2] = new DAConfClass(3, thisDriverConf.ID, false, false, false, DriverConfig.DatType.sDWord, 0, "0", ObjDriverXWave.NumVars.nsDWord); } ExtData[2].AreaConf = thisAreaConf[2]; //Float point Areas. ExtData[3] = new DataExtClass(); if (ObjDriverXWave.NumVars.nReal > 0) { thisAreaConf[3] = new DAConfClass(4, thisDriverConf.ID, true, false, true, DriverConfig.DatType.Real, 0, "0", ObjDriverXWave.NumVars.nReal); ExtData[3].Data.dReal = new float[ObjDriverXWave.NumVars.nReal]; ExtData[3].VarNames = new string[ObjDriverXWave.NumVars.nReal]; ExtData[3].FirstInit = false; } else { thisAreaConf[3] = new DAConfClass(4, thisDriverConf.ID, false, false, false, DriverConfig.DatType.Real, 0, "0", ObjDriverXWave.NumVars.nReal); } ExtData[3].AreaConf = thisAreaConf[3]; } else { Status.NewStat(StatType.Warning, "Wrong Driver Config Params: Driver Init Failed."); } // if XWave Driver isInitialized } //IF Driver Type, XWave Driver has a different treatment. // Built the Drivers. switch (thisDriverConf.Type) { case DriverConfig.DriverType.XWave: //This driver is built and initialized above. break; case DriverConfig.DriverType.S7_TCP: ObjDriverS7 = new Siemens7.DriverS7(thisDriverConf, thisAreaConf, Status); break; case DriverConfig.DriverType.ModbusTCP: ObjDriverModTCP = new ModbusTCP.DriverModbusTCP(thisDriverConf, thisAreaConf, Status); break; default: Status.NewStat(StatType.Warning, "Wrong Driver Type, Check Config."); break; } } //IF driver is enabled } else { Status.NewStat(StatType.Warning, "Wrong Driver Config Params: Wrong Driver ID."); } //IF Driver Number is out of bounds. } //DriverGeneric Cttor