public int upload(ref XLSECTSignal P) { ID = " <ID>" + P.sigSource + "</ID>"; VarNameL0 = " <VarNameL0>" + P.sigSource + "</VarNameL0>"; VarNameL1 = " <VarNameL1>" + P.sigSource + "</VarNameL1>"; DescL0 = " <DescL0 />"; DescL1 = " <DescL1 />"; Visible = " <Visible>true</Visible>"; return(0); }
public int upload(ref XLSECTSignal P) { string scaling_string = "S_1_1_0_0_1"; scaling_string = "S_1_" + Convert.ToString(P.sigKa) + "_" + Convert.ToString(P.sigKb) + "_" + Convert.ToString(P.sigKc) + "_" + Convert.ToString(P.sigKd); ID = " <ID>" + scaling_string + "</ID>"; CVType = " <Type>1</Type>"; LimitType = " <LimitType />"; LimitMode = " <LimitMode>0</LimitMode>"; RangeCorrectionModeForEquiSpacedBP = " <RangeCorrectionModeForEquiSpacedBP>0</RangeCorrectionModeForEquiSpacedBP>"; EquiSpacedBPCount = " <EquiSpacedBPCount>0</EquiSpacedBPCount>"; G1 = " <G1>" + Convert.ToString(P.sigKa) + "</G1>"; O1 = " <O1>" + Convert.ToString(P.sigKb) + "</O1>"; G2 = " <G2>" + Convert.ToString(P.sigKc) + "</G2>"; O2 = " <O2>" + Convert.ToString(P.sigKd) + "</O2>"; return(0); }
public int upload(ref XLSECTSignal P, bool isAnArray, int ind, ref Cont Cnr) { int i; string byte_dim = "1"; string signed_string = "false"; string scaling_string = "S_1_1_0_0_1"; string format_string = "#######0"; string type_string = "0"; string _name = null; string i_hex; scaling_string = "S_1_" + P.sigKa + "_" + P.sigKb + "_" + P.sigKc + "_" + P.sigKd; if (P.sigDecNum != 0) { format_string += "."; for (i = 0; i < P.sigDecNum; i++) { format_string += "0"; } } switch (P.sigType) { case "UBYTE": byte_dim = "1"; signed_string = "false"; type_string = "0"; break; case "SBYTE": byte_dim = "1"; signed_string = "true"; type_string = "256"; break; case "UWORD": byte_dim = "2"; signed_string = "false"; type_string = "0"; break; case "SWORD": byte_dim = "2"; signed_string = "true"; type_string = "256"; break; case "ULONG": byte_dim = "4"; signed_string = "false"; type_string = "0"; break; case "SLONG": byte_dim = "4"; signed_string = "true"; type_string = "256"; break; default: byte_dim = "1"; signed_string = "false"; break; } _name = P.sigName; TabAdr = " <TabAdr>" + Convert.ToString(tab_adr++) + "</TabAdr>"; FactoryName = " <FactoryName>" + P.sigName + "</FactoryName>"; ASAPName = " <ASAPName>" + P.sigName + "</ASAPName>"; NByte = " <NByte>" + byte_dim + "</NByte>"; Format = " <Format>####0</Format>"; Unit = " <Unit>" + P.sigUnit + "</Unit>"; CVType = " <Type>" + type_string + "</Type>"; Default = " <Default>0</Default>"; VarNameL0 = " <VarNameL0>" + P.sigName + "</VarNameL0>"; VarNameL1 = " <VarNameL1>" + P.sigAlias + "</VarNameL1>"; DescL0 = " <DescL0>" + P.sigDescription + "</DescL0>"; DescL1 = " <DescL1>" + P.sigDescription + "</DescL1>"; Address = " <Address>0xF1CACAF1</Address>"; MinGraph = " <MinGraph>" + P.sigMin + "</MinGraph>"; MaxGraph = " <MaxGraph>" + P.sigMax + "</MaxGraph>"; CorrectionType = " <CorrectionType>0</CorrectionType>"; LoggerMaxPer = " <LoggerMaxPer>0</LoggerMaxPer>"; LoggerNBytes = " <LoggerNBytes>1</LoggerNBytes>"; Logger = " <Logger>false</Logger>"; Signed = " <Signed>" + signed_string + "</Signed>"; NByteSingleValue = " <NByteSingleValue>" + byte_dim + "</NByteSingleValue>"; Exportable = " <Exportable>true</Exportable>"; Channel_ScalingID = " <Channel_ScalingID>" + scaling_string + "</Channel_ScalingID>"; Min = " <Min>" + P.sigMin + "</Min>"; Max = " <Max>" + P.sigMax + "</Max>"; Validated = " <Validated>true</Validated>"; GroupID = " <GroupID>" + P.sigSource + "</GroupID>"; IsArray = " <IsArray>false</IsArray>"; UseMaxSize = " <UseMaxSize>false</UseMaxSize>"; Notes = " <Notes />"; Open = " <Open>false</Open>"; ELFVarType = " <ELFVarType>1</ELFVarType>"; if (isAnArray) { FactoryName = " <FactoryName>" + P.sigName + "[" + Convert.ToString(ind) + "]</FactoryName>"; ASAPName = " <ASAPName>" + P.sigName + "[" + Convert.ToString(ind) + "]</ASAPName>"; VarNameL0 = " <VarNameL0>" + P.sigName + "[" + Convert.ToString(ind) + "]</VarNameL0>"; VarNameL1 = " <VarNameL1>" + P.sigAlias + "[" + Convert.ToString(ind) + "]</VarNameL1>"; IsArray = " <IsArray>true</IsArray>"; // ELFVarType = " <ELFVarType>2</ELFVarType>"; } if (Cnr.SymbolTableExists == true) { Symbol S = new Symbol(); try { S = Cnr.SymbolBssList.Find(x => x.name == _name); if (isAnArray) { i = Convert.ToInt32(S.address, 16) + ind * Convert.ToInt32(byte_dim); i_hex = i.ToString("X"); Address = " <Address>0x" + i_hex + "</Address>"; } else { Address = " <Address>0x" + S.address + "</Address>"; } } catch { MessageBox.Show(_name + " does not exist in the symbol table"); } // MessageBox.Show(_name + S.name + S.address); } return(0); }
private void A2LSymbolsWrite(ref System.IO.StreamWriter fileA2L) { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet_Parameters; Excel.Worksheet xlWorkSheet_Signals; Excel.Worksheet xlWorkSheet_Defines; Excel.Worksheet xlWorkSheet_States; string Line; int LineNum; int RetVal = 0; int index; bool ConvExists = false; bool GroupExists = false; XLSECTParameter XLSECTParameter1 = new XLSECTParameter(); XLSECTSignal XLSECTSignal1 = new XLSECTSignal(); Measurement Measurement1 = new Measurement(); CharacteristicValue CharacteristicValue1 = new CharacteristicValue(); Axis_Pts Axis_Pts1 = new Axis_Pts(); CharacteristicCurve CharacteristicCurve1 = new CharacteristicCurve(); CharacteristicMap CharacteristicMap1 = new CharacteristicMap(); // CONV Conversion ConversionNew = new Conversion(); // GROUP A2LGroup GroupNew = new A2LGroup(); A2LGroup GPCurrent = null; A2LGroupList = new List <A2LGroup>(); ConversionList = new List <Conversion>(); object misValue = System.Reflection.Missing.Value; try { xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(filePath, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet_Parameters = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkSheet_Signals = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2); xlWorkSheet_Defines = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(3); xlWorkSheet_States = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(4); // Generate the signals and write them in the new XML file Line = "2"; LineNum = 2; // While there are symbols in the Excel sheet while (-2 != RetVal) { // Elaborate the signals sheet RetVal = XLSECTSignal1.upload(ref xlWorkSheet_Signals, Line); #if zorro // Build the Scaling IDs list // Create the new COMPU_METHOD ConversionNew.upload(ref XLSECTSignal1); ConvExists = false; // Check if it exists already if (CScalingList != null) { foreach (CalibrationScaling CS in CScalingList) { if (CS.ID == ConversionNew.ID) { ConvExists = true; } } } // If it doesn't exist, add it to the list if (ConvExists == false) { ConversionList.Add(ConversionNew); ConversionNew = new Conversion(); } #endif // Build the Group IDs list // Create the new group GroupNew.upload(ref XLSECTSignal1); GroupExists = false; // Check if it exists already foreach (A2LGroup GP in A2LGroupList) { if (GP.ID == GroupNew.ID) { GroupExists = true; GPCurrent = GP; break; } } // If it doesn't exist, add it to the list if (GroupExists == false) { // GroupNew.Add(ref XLSECTSignal1); A2LGroupList.Add(GroupNew); GPCurrent = GroupNew; /* Create the new group for next group */ GroupNew = new A2LGroup(); } // If it is a Signal (MEASUREMENT in A2L nomenclature) if ((RetVal == 0) || (RetVal == 123456789)) { Measurement1.upload(ref XLSECTSignal1, false, 0, ref Containr); Measurement1.AppendToFile(ref fileA2L); GPCurrent.Add(ref XLSECTSignal1); // SignalValue1.Show(); } else { if (RetVal > 1) { if (RetVal > 123456789) { RetVal -= 123456789; } for (index = 0; index < RetVal; index++) { Measurement1.upload(ref XLSECTSignal1, true, index, ref Containr); Measurement1.AppendToFile(ref fileA2L); GPCurrent.Add(ref XLSECTSignal1, index); } } } LineNum++; Line = Convert.ToString(LineNum); } // Generate the calibrations and write them in the new XML file Line = "2"; LineNum = 2; RetVal = 0; while (-2 != RetVal) { // Elaborate the parameters sheet RetVal = XLSECTParameter1.upload(ref xlWorkSheet_Parameters, Line); #if NOT_NECESSARY CScalingNew.upload(ref XLSECTParameter1); ScalingExists = false; foreach (CalibrationScaling CS in CScalingList) { if (CS.ID == CScalingNew.ID) { ScalingExists = true; } } if (ScalingExists == false) { CScalingList.Add(CScalingNew); CScalingNew = new CalibrationScaling(); } #endif // Create the new group GroupNew.upload(ref XLSECTParameter1); GroupExists = false; // Check if it exists already foreach (A2LGroup GP in A2LGroupList) { if (GP.ID == GroupNew.ID) { GroupExists = true; GPCurrent = GP; break; } } // If it doesn't exist, add it to the list if (GroupExists == false) { // GroupNew.Add(ref XLSECTParameter1); A2LGroupList.Add(GroupNew); GPCurrent = GroupNew; /* Create the new group for next group */ GroupNew = new A2LGroup(); } // If it is a CalibrationValue if (RetVal == 0) { CharacteristicValue1.upload(ref XLSECTParameter1, ref Containr); CharacteristicValue1.AppendToFile(ref fileA2L); GPCurrent.Add(ref XLSECTParameter1); // CalibrationValue1.Show(); } // If it is a CalibrationSharedAxis if (RetVal == 1) { Axis_Pts1.upload(ref XLSECTParameter1, ref Containr); Axis_Pts1.AppendToFile(ref fileA2L); GPCurrent.Add(ref XLSECTParameter1, true); // CalibrationSharedAxis1.Show(); } // If it is a CalibrationCurve if (RetVal == 2) { CharacteristicCurve1.upload(ref XLSECTParameter1, ref Containr); CharacteristicCurve1.AppendToFile(ref fileA2L); GPCurrent.Add(ref XLSECTParameter1, true); // CalibrationCurve1.Show(); } // If it is a CalibrationMap if (RetVal == 3) { CharacteristicMap1.upload(ref XLSECTParameter1, ref Containr); CharacteristicMap1.AppendToFile(ref fileA2L); GPCurrent.Add(ref XLSECTParameter1, true); // CalibrationMap1.Show(); } // Copy record layouts LineNum++; Line = Convert.ToString(LineNum); } if (A2LGroupList != null) { fileA2L.WriteLine(" /begin GROUP Calibration \"All the calibration parameters and table\""); fileA2L.WriteLine(" ROOT"); fileA2L.WriteLine(" /begin SUB_GROUP"); foreach (A2LGroup GP in A2LGroupList) { fileA2L.WriteLine(" " + GP.ID); } fileA2L.WriteLine(" /end SUB_GROUP"); fileA2L.WriteLine(" /end GROUP"); foreach (A2LGroup GP in A2LGroupList) { GP.AppendToFile(ref fileA2L); } } #if NOT_NECESSARY foreach (CalibrationScaling CS in CScalingList) { CS.AppendToFile(ref fileXML); } fileXML.WriteLine("</LIE00V12PARTIAL>"); fileXML.Close(); #endif xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet_Parameters); releaseObject(xlWorkSheet_Signals); releaseObject(xlWorkSheet_Defines); releaseObject(xlWorkSheet_States); releaseObject(xlWorkBook); releaseObject(xlApp); } catch { MessageBox.Show("File " + filePath + " doesn't exist"); } }
private void button4_Click(object sender, EventArgs e) { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet_Parameters; Excel.Worksheet xlWorkSheet_Signals; Excel.Worksheet xlWorkSheet_Defines; Excel.Worksheet xlWorkSheet_States; string Line; int LineNum; int RetVal = 0; int index; bool ScalingExists = false; bool GroupExists = false; XLSECTParameter XLSECTParameter1 = new XLSECTParameter(); XLSECTSignal XLSECTSignal1 = new XLSECTSignal(); SignalValue SignalValue1 = new SignalValue(); CalibrationValue CalibrationValue1 = new CalibrationValue(); CalibrationSharedAxis CalibrationSharedAxis1 = new CalibrationSharedAxis(); CalibrationCurve CalibrationCurve1 = new CalibrationCurve(); CalibrationMap CalibrationMap1 = new CalibrationMap(); System.IO.StreamWriter fileXML; /* Scaling IDs */ CalibrationScaling CScalingNew = new CalibrationScaling(); // CalibrationScaling CS; Group GroupNew = new Group(); GroupList = new List <Group>(); CScalingList = new List <CalibrationScaling>(); object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(filePath, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet_Parameters = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkSheet_Signals = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2); xlWorkSheet_Defines = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(3); xlWorkSheet_States = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(4); if (File.Exists(BasefilePath)) { // Copy the XML base file as a header for the new file CopyBaseFileToTarget(); fileXML = new System.IO.StreamWriter(XMLfilePath, true); // Generate the signals and write them in the new XML file Line = "2"; LineNum = 2; while (-2 != RetVal) { // Elaborate the signals sheet RetVal = XLSECTSignal1.upload(ref xlWorkSheet_Signals, Line); // Build the Scaling IDs list CScalingNew.upload(ref XLSECTSignal1); ScalingExists = false; foreach (CalibrationScaling CS in CScalingList) { if (CS.ID == CScalingNew.ID) { ScalingExists = true; } } if (ScalingExists == false) { CScalingList.Add(CScalingNew); CScalingNew = new CalibrationScaling(); } // Build the Group IDs list GroupNew.upload(ref XLSECTSignal1); GroupExists = false; foreach (Group GP in GroupList) { if (GP.ID == GroupNew.ID) { GroupExists = true; } } if (GroupExists == false) { GroupList.Add(GroupNew); GroupNew = new Group(); } // If it is a Signal (Channel in ECT XML nomenclature) if ((RetVal == 0) || (RetVal == 123456789)) { SignalValue1.upload(ref XLSECTSignal1, false, 0, ref Containr); SignalValue1.AppendToFile(ref fileXML); // SignalValue1.Show(); } else { if (RetVal > 1) { if (RetVal > 123456789) { RetVal -= 123456789; } for (index = 0; index < RetVal; index++) { SignalValue1.upload(ref XLSECTSignal1, true, index, ref Containr); SignalValue1.AppendToFile(ref fileXML); } } } LineNum++; Line = Convert.ToString(LineNum); } // Generate the calibrations and write them in the new XML file Line = "2"; LineNum = 2; RetVal = 0; while (-2 != RetVal) { // Elaborate the parameters sheet RetVal = XLSECTParameter1.upload(ref xlWorkSheet_Parameters, Line); CScalingNew.upload(ref XLSECTParameter1); ScalingExists = false; foreach (CalibrationScaling CS in CScalingList) { if (CS.ID == CScalingNew.ID) { ScalingExists = true; } } if (ScalingExists == false) { CScalingList.Add(CScalingNew); CScalingNew = new CalibrationScaling(); } // Build the Group IDs list GroupNew.upload(ref XLSECTParameter1); GroupExists = false; foreach (Group GP in GroupList) { if (GP.ID == GroupNew.ID) { GroupExists = true; } } if (GroupExists == false) { GroupList.Add(GroupNew); GroupNew = new Group(); } // If it is a CalibrationValue if (RetVal == 0) { CalibrationValue1.upload(ref XLSECTParameter1, ref Containr); CalibrationValue1.AppendToFile(ref fileXML); // CalibrationValue1.Show(); } // If it is a CalibrationSharedAxis if (RetVal == 1) { CalibrationSharedAxis1.upload(ref XLSECTParameter1, ref Containr); CalibrationSharedAxis1.AppendToFile(ref fileXML); // CalibrationSharedAxis1.Show(); } // If it is a CalibrationCurve if (RetVal == 2) { CalibrationCurve1.upload(ref XLSECTParameter1, ref Containr); CalibrationCurve1.AppendToFile(ref fileXML); // CalibrationCurve1.Show(); } // If it is a CalibrationMap if (RetVal == 3) { CalibrationMap1.upload(ref XLSECTParameter1, ref Containr); CalibrationMap1.AppendToFile(ref fileXML); // CalibrationMap1.Show(); } LineNum++; Line = Convert.ToString(LineNum); } foreach (Group GP in GroupList) { GP.AppendToFile(ref fileXML); } foreach (CalibrationScaling CS in CScalingList) { CS.AppendToFile(ref fileXML); } fileXML.WriteLine("</LIE00V12PARTIAL>"); fileXML.Close(); } else { MessageBox.Show(" Base File doesn't exist"); } /* * * MessageBox.Show( * xlWorkSheet_Parameters.get_Range("A2", "A2").Value2.ToString() + "\r\n" + * xlWorkSheet_Parameters.get_Range("A3", "A3").Value2.ToString() + "\r\n" + * xlWorkSheet_Parameters.get_Range("A4", "A4").Value2.ToString() + "\r\n" + * xlWorkSheet_Parameters.get_Range("A5", "A5").Value2.ToString() + "\r\n" + * xlWorkSheet_Parameters.get_Range("A6", "A6").Value2.ToString() + "\r\n" * ); */ xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet_Parameters); releaseObject(xlWorkSheet_Signals); releaseObject(xlWorkSheet_Defines); releaseObject(xlWorkSheet_States); releaseObject(xlWorkBook); releaseObject(xlApp); MessageBox.Show("Finished!"); }