Integration 2.1j6 :

- migliorata lettura parametri macchina.
This commit is contained in:
Dario Sassi
2019-10-17 08:52:53 +00:00
parent 3677c6ac19
commit 649d2c1261
2 changed files with 56 additions and 100 deletions
+54 -98
View File
@@ -674,6 +674,18 @@ namespace ib.essetre.integration.egaltech
di.Create() ;
return BtlDir ;
}
//-------------------------------------------------------------------------------------------------------------
// Restituisce il direttorio per i file con i dati macchina
private static String GetDataDir( InOutParameters parameters)
{
String DataDir = parameters.Read( "EGALTECH", "DIR_DATA", "") ;
// Se la directory non esiste viene creata
DirectoryInfo di = new DirectoryInfo( DataDir) ;
if ( ! di.Exists)
di.Create() ;
return DataDir ;
}
//-------------------------------------------------------------------------------------------------------------
// Visualizzazione finestra gestione DB utensili
@@ -735,93 +747,18 @@ namespace ib.essetre.integration.egaltech
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString( string Section, string Key, string Value, string FilePath) ;
//-------------------------------------------------------------------------------------------------------------
// Scrive il file ToolConfig.ini che include gli utensili e i relativi parametri presi dal DB
private static void GetToolParams( InOutParameters parameters)
{
// Direttorio di scrittura del file e sua creazione se non esiste
String BtlDir = parameters.Read( "EGALTECH", "DIR_BTL", "") ;
DirectoryInfo di = new DirectoryInfo( BtlDir) ;
if ( ! di.Exists)
di.Create() ;
// Path del file INI e sua cancellazione se già esiste
string IniPath = Path.Combine( BtlDir, "ToolConfig.ini") ;
if ( File.Exists( IniPath))
File.Delete( IniPath) ;
// Preparazione interrogazione del DB
_SqlConnectionStr = parameters.ConnectionString ;
DataSet dsTools = new DataSet() ;
string sqlTool = "SELECT [vw_Tool].[toolId], [code], [jobType], [toolType], " +
"[enabled], [note], [position], [file3ds], [rpm], [feed], [srot], " +
"[number], [vw_Tool].[configurationId], [vw_Tool].[flagDeleted], [lastModified], " +
"[key], [value] " +
"FROM [ESSETRE].[dbo].[vw_Tool] " +
"INNER JOIN [ESSETRE].[dbo].[vw_ToolParam] " +
"ON [vw_Tool].[toolId] = [vw_ToolParam].[toolId] ";
// Connessione al DB ed esecuzione query
using ( SqlConnection cn = new SqlConnection( _SqlConnectionStr)) {
cn.Open() ;
using ( SqlCommand cmd = new SqlCommand( sqlTool, cn)) {
var dataAdapter = new SqlDataAdapter( cmd) ;
// Lettura DB e riempimento DataSet
dsTools.Clear() ;
dataAdapter.Fill( dsTools) ;
}
}
// Scrittura del file
foreach ( DataTable table in dsTools.Tables) {
int toolId = 0 ;
String Section = "" ;
foreach ( DataRow row in table.Rows) {
String Key = "" ;
String Value = "" ;
if ( (int)row["toolId"] != toolId) {
// Nuovo utensile
toolId = (int)row["toolId"] ;
Section = "Tool_" + toolId.ToString("00") ; //row["code"].ToString();
// Dati utensile presenti in ogni riga
foreach ( DataColumn column in table.Columns) {
if ( ! ( column.ColumnName.Equals( "key") || column.ColumnName.Equals( "value"))) {
Key = column.ColumnName ;
Value = row[column].ToString() ;
WritePrivateProfileString( Section, Key, Value, IniPath) ;
}
}
}
// Altri dati utensile
Key = row["key"].ToString() ;
Value = row["value"].ToString() ;
WritePrivateProfileString( Section, Key, Value, IniPath) ;
}
}
}
//-------------------------------------------------------------------------------------------------------------
// Scrive il file MachConfig_[MachineName].ini che include i parametri macchina presi dal DB
private static void GetMachineParams( InOutParameters parameters)
{
// Direttorio di scrittura del file e sua creazione se non esiste
String BtlDir = parameters.Read( "EGALTECH", "DIR_BTL", "") ;
DirectoryInfo di = new DirectoryInfo( BtlDir) ;
if ( ! di.Exists)
di.Create() ;
// Direttorio di scrittura del file
String DataDir = GetDataDir( parameters) ;
// Path del file INI e sua cancellazione se già esiste
string IniName = "MachConfig_" + parameters.MachineName + ".ini" ;
string IniPath = Path.Combine( BtlDir, IniName) ;
if ( File.Exists( IniPath))
File.Delete( IniPath) ;
// Path del file di dati e sua cancellazione se già esiste
string DataName = "Essetre-" + parameters.MachineName + ".data" ;
string DataPath = Path.Combine( DataDir, DataName) ;
if ( File.Exists( DataPath))
File.Delete( DataPath) ;
// Preparazione interrogazione per Offsets del DB
_SqlConnectionStr = parameters.ConnectionString ;
@@ -861,24 +798,43 @@ namespace ib.essetre.integration.egaltech
}
}
// Scrittura del file INI per Offsets
foreach ( DataTable table in dsOffsets.Tables) {
foreach ( DataRow row in table.Rows) {
String Section = row["group"].ToString() ;
String Key = row["key"].ToString() ;
String Value = row["value"].ToString() ;
WritePrivateProfileString( Section, Key, Value, IniPath) ;
}
}
// Apro file
using ( var tw = new StreamWriter( DataPath, false)) {
// Scrittura del file INI per trave
foreach ( DataTable table in dsTrave.Tables) {
foreach ( DataRow row in table.Rows) {
String Section = row["group"].ToString() ;
String Key = row["key"].ToString() ;
String Value = row["value"].ToString() ;
WritePrivateProfileString( Section, Key, Value, IniPath) ;
// Scrittura intestazione
tw.WriteLine( "-- " + DataPath) ;
tw.WriteLine( "") ;
// Scrittura dei dati di Offsets
tw.WriteLine( "local Offsets = {") ;
foreach ( DataTable table in dsOffsets.Tables) {
foreach ( DataRow row in table.Rows) {
String Key = row["key"].ToString() ;
String Value = row["value"].ToString() ;
tw.WriteLine( " " + Key + "=" + Value + ",") ;
}
}
tw.WriteLine( " Zzz=1") ;
tw.WriteLine( "}") ;
tw.WriteLine( "") ;
// Scrittura dei dati di Trave
tw.WriteLine( "local Trave = {") ;
foreach ( DataTable table in dsTrave.Tables) {
foreach ( DataRow row in table.Rows) {
String Key = row["key"].ToString() ;
String Value = row["value"].ToString() ;
tw.WriteLine( " " + Key + "=" + Value + ",") ;
}
}
tw.WriteLine( " Zzz=1") ;
tw.WriteLine( "}") ;
tw.WriteLine( "") ;
// Scrittura tabella da restituire
tw.WriteLine( "local Machine = { Offsets=Offsets, Trave=Trave}") ;
tw.WriteLine( "return Machine") ;
}
}
}
@@ -36,5 +36,5 @@ using System.Runtime.InteropServices;
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// usando l'asterisco '*' come illustrato di seguito:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.10.3")]
[assembly: AssemblyFileVersion("2.1.10.3")]
[assembly: AssemblyVersion("2.1.10.6")]
[assembly: AssemblyFileVersion("2.1.10.6")]