Skip to content

Commit 88bd4eb

Browse files
committed
Get XML of Folders
1 parent a4cc576 commit 88bd4eb

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

src/S7CommPlusDriver/Core/BlobDecompressor.cs

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public string decompress(byte[] compressed_blob, int startoffset)
160160
}
161161
else
162162
{
163+
retstring = System.Text.Encoding.UTF8.GetString(uncompressed_blob, 0, uncomp_length);
164+
//TODO: error!!!
163165
Console.WriteLine(String.Format("BlobDecompressor: Blob decompression failed! Zlib retcode={0} msg={1} ", retcode, z.msg));
164166
}
165167
z.inflateEnd();

src/S7CommPlusDriver/Core/Ids.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ public static class Ids
133133
public const int ControllerArea_ValueInitial = 3735;
134134
public const int ControllerArea_ValueActual = 3736;
135135
public const int ControllerArea_RuntimeModified = 3737;
136-
public const int DAI_MessageType = 4079;
136+
public const int DAI_MessageType = 4079;
137+
public const int ConstantsGlobal_Symbolics = 4275;
137138
public const int ASObjectES_Comment = 4288;
138139
public const int AlarmSubscriptionRef_AlarmDomain2 = 7731;
139140
public const int DAI_HmiInfo = 7813;
@@ -144,6 +145,8 @@ public static class Ids
144145
public const int AlarmSubscriptionRef_SendAlarmTexts_Rid = 8173;
145146
public const int ReturnValue = 40305;
146147

148+
public const uint Constants = 0x8a110000;
149+
147150
public const int TI_BOOL = 0x02000000 + 1;
148151
public const int TI_BYTE = 0x02000000 + 2;
149152
public const int TI_CHAR = 0x02000000 + 3;

src/S7CommPlusDriver/S7CommPlusConnectionHighLevel.cs

+63-3
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ public int BrowseAllBlocks(out List<BlockInfo> exploreData)
161161
#region Evaluate all data blocks that then need to be browsed
162162

163163
var obj = exploreRes.Objects.First(o => o.ClassId == Ids.PLCProgram_Class_Rid);
164-
165164
foreach (var ob in obj.GetObjects())
166165
{
167166
switch (ob.ClassId)
@@ -196,10 +195,61 @@ public int BrowseAllBlocks(out List<BlockInfo> exploreData)
196195

197196
#endregion
198197

198+
return 0;
199+
}
200+
201+
public int GetPlcStructureXML(out string plcStrutureXml)
202+
{
203+
int res;
204+
Browser vars = new Browser();
205+
ExploreRequest exploreReq;
206+
ExploreResponse exploreRes;
207+
plcStrutureXml = null;
208+
209+
#region Read all objects
210+
211+
exploreReq = new ExploreRequest(ProtocolVersion.V2);
212+
exploreReq.ExploreId = Ids.Constants | 0x0000ffff;
213+
exploreReq.ExploreRequestId = Ids.None;
214+
exploreReq.ExploreChildsRecursive = 1;
215+
exploreReq.ExploreParents = 1;
216+
217+
exploreReq.AddressList.Add(Ids.ConstantsGlobal_Symbolics);
218+
219+
res = SendS7plusFunctionObject(exploreReq);
220+
if (res != 0)
221+
{
222+
return res;
223+
}
224+
m_LastError = 0;
225+
WaitForNewS7plusReceived(m_ReadTimeout);
226+
if (m_LastError != 0)
227+
{
228+
return m_LastError;
229+
}
230+
231+
exploreRes = ExploreResponse.DeserializeFromPdu(m_ReceivedPDU, true);
232+
res = checkResponseWithIntegrity(exploreReq, exploreRes);
233+
if (res != 0)
234+
{
235+
return res;
236+
}
237+
238+
#endregion
239+
240+
var attr = exploreRes?.Objects?[0]?.Objects?.First().Value?.Objects?.First().Value?.Attributes?[Ids.ConstantsGlobal_Symbolics] as ValueBlob;
241+
if (attr != null)
242+
{
243+
BlobDecompressor bd3 = new BlobDecompressor();
244+
var v = attr.GetValue();
245+
var xml = bd3.decompress(v, 0);
246+
plcStrutureXml = xml;
247+
}
248+
199249
return 0;
200250
}
201251

202-
public int GetBlockXml(uint relid, out string blockName, out ProgrammingLanguage lang, out uint blockNumber, out string xml_linecomment, out Dictionary<uint, string> xml_comment, out string interfaceDescription, out string[] blockBody, out string fuctionalObjectCode, out string[] intRef, out string[] extRef)
252+
public int GetBlockXml(uint relid, out string blockName, out ProgrammingLanguage lang, out uint blockNumber, out BlockType blockType, out string xml_linecomment, out Dictionary<uint, string> xml_comment, out string interfaceDescription, out string[] blockBody, out string fuctionalObjectCode, out string[] intRef, out string[] extRef)
203253
{
204254
int res;
205255
// With requesting DataInterface_InterfaceDescription, whe would be able to get all informations like the access ids and
@@ -215,6 +265,7 @@ public int GetBlockXml(uint relid, out string blockName, out ProgrammingLanguage
215265
blockName = null;
216266
lang = ProgrammingLanguage.Undef;
217267
blockNumber = relid & 0xffff;
268+
blockType = BlockType.unkown;
218269

219270
var exploreReq = new ExploreRequest(ProtocolVersion.V2);
220271
exploreReq.ExploreId = relid;
@@ -254,7 +305,16 @@ public int GetBlockXml(uint relid, out string blockName, out ProgrammingLanguage
254305
}
255306

256307
foreach (var obj in exploreRes.Objects)
257-
{
308+
{
309+
blockType = obj.ClassId switch
310+
{
311+
Ids.DB_Class_Rid => BlockType.DB,
312+
Ids.FB_Class_Rid => BlockType.FB,
313+
Ids.FC_Class_Rid => BlockType.FC,
314+
Ids.OB_Class_Rid => BlockType.OB,
315+
};
316+
317+
258318
foreach (var att in obj.Attributes)
259319
{
260320
switch (att.Key)

0 commit comments

Comments
 (0)