dotnetprojects / dotnetsiemensplctoolboxlibrary Goto Github PK
View Code? Open in Web Editor NEWLibrary to Access Siemens PLCs and Step5/Step7 Project Files
License: GNU Lesser General Public License v2.1
Library to Access Siemens PLCs and Step5/Step7 Project Files
License: GNU Lesser General Public License v2.1
I have found that an exception is thrown when opening projects with offline foldes that have no CPU as parent.
im not sure why, but the exception is thrown in the linq expression in the Step7ProjectV5.cs LoadProject Method
foreach(var dp in DPlist)
{
var dpf = DPFolders.FirstOrDefault(x => x.IdTobjId.Any(y => y == dp.TobjID));
if ( dpf != null)
{
if (dpf.TobjId == null) dpf.TobjId = new List<int>();
dpf.TobjId.Add(dp.addr);
}
}
to fix it i have modified the linq to the following
var dpf = DPFolders.FirstOrDefault(x => x.IdTobjId != null && x.IdTobjId.Any(y => y == dp.TobjID));
Can you provide source code for libnodave_jfkmod?
using GetSource prints wrong data when the DB has a string,
it brings the String Variable but it doesn't specify the amount of characters for such string variable.
In the directory i see this file with 571 kb, in a vm with win7 x64 fresh installation, i also see 571 kb as size
DotNetSiemensPLCToolBoxLibrary/externalDlls/siemens/V15/Siemens.Engineering.dll
but in recent installations for V15 (win 7 and win 10 both x64) i've seen files of size 586 kb, and for this files i have an exception (type initialization exception) for type Siemens.Engineering.TiaPortal
both have file versions equal (from the properties of the file) all installations have the same product versions under details of installed software (tia portal dialog)
Should the dll be updated with the one of 586 kb???
Hi,
As I run TestLibrary project and try to read *.ap13 file will cause an error in LoadViaOpennessDlls();
Does this library support TIA ap13 file?
Indexed DB acces in a FC/FB/OB are not shown, instead the absolute access is displayed
Obtained source
U L 5.0;
U "M_AE362_BaQuittieren";
AUF "DB_TAKT";
= DBX10.5;
Desired obtained source:
U L 5.0;
U "M_AE362_BaQuittieren";
= "DB_TAKT".Takt[1].Cmd.Bits.Quit;
I am trying to open a S7P file which worked fine on a older version (like 2 years old or something) but on the recent versions it keeps crashing.
The rows it keeps on crashing looks like this:
- rows {string[12]} string[]
[0] "\r" string
[1] "VAR_TEMP\r" string
[2] " OB86_EV_CLASS : BYTE ;\t//16#38/39 Event class 3\r" string
[3] " OB86_FLT_ID : BYTE ;\t//16#C1/C4/C5, Fault identifcation code\r" string
[4] " OB86_PRIORITY : BYTE ;\t//Priority of OB Execution\r" string
[5] " OB86_OB_NUMBR : BYTE ;\t//86 (Organization block 86, OB86)\r" string
[6] " OB86_RESERVED_1 : BYTE ;\t//Reserved for system\r" string
[7] " OB86_RESERVED_2 : BYTE ;\t//Reserved for system\r" string
[8] " OB86_MDL_ADDR : WORD ;\t//Base address of IM module in rack with fault\r" string
[9] " OB86_RACKS_FLTD : ARRAY [0 .. 31 ] OF BOOL ;\t//Racks in fault\r" string
[10] " OB86_DATE_TIME : DATE_AND_TIME ;\t//Date and time OB86 started\r" string
[11] "END_VAR\r" string
As you can see line 9 is a array with some comment behind it saying
"//Racks in fault"
In the Parameter.cs file (PLCs\S7_xxx\MC7\Parameter.cs) it appends line 10 to line 9 resulting in the following line:
OB86_RACKS_FLTD : ARRAY [0 .. 31 ] OF BOOL ;\t OB86_DATE_TIME : DATE_AND_TIME ;\t//Date and time OB86 started//Racks in fault
This results in the following tmpType
on line 311
ARRAY [0 .. 31 ] OF BOOL OB86_DATE_TIME : DATE_AND_TIME
Since there isn't a S7DataRowType like this it eventually fails to parse this row and crashes the application.
when creating a dll with a dependency to DotNetSiemensPLCToolBoxLibrary and using the
Managed Extensibility Framework (MEF) to lazy load it into an application i get an error that there are dependecies to a SharpZipLib dll (ICSharpCode.SharpZipLib.dll) which is not in there.
Maybe it is missing in the nuget package or an obsolete reference
If the any pointer has acces to more than the limit of a signed int16 the source code generates a negative value
CALL "FC_BEREICH_LES_SCHREIBEN";
ILesen :=L 5.2
ISchreiben :=L 5.3
ISollWert :=0
IIndex :=DB3810.DBW1068
IDatenSchr :=P#M 20.1 BYTE 1
IDatenLe :=P#DB3560.DBX 14.0 BYTE 1
IDatensatz :=P#DB3560.DBX 0.0 BYTE 126
IDatenArray:=P#DB3560.DBX 0.0 BYTE -15136
OIstWert :=LW2
_012: NOP 0;
using ProjectBlockInfo.GetBlockSource() for a source block obtained via S7ProgramFolder.SourceFolder.BlockInfos[x].GetBlockSource() crashes
I think we should separate the library into two (or more) libraries. One with the library itself, one with all Windows Forms related stuff and maybe one for WPF as well. This way we could eliminate the dependency to Windows.Forms assembly in the main communications library.
Of course this is an breaking change and a lot of stuff need to be reworked to make this possible.
What do you think?
Is it possible to read S7 alarms with the help of this library ? If yes, where can be found any samples for it ?
Hi
I've reading through the code to find where the tags are parsed, so far i've only seen the tag tables but if they dont have a constant nothing else gets parsed
Am I missing something? are they parsed somewhere else?
When I read, for example, 110 bytes from DB
for (int ii = 0; ii < 55; ii++)
listTag.Add(new PLCTag() { DataBlockNumber = 888, ByteAddress = ii * 2,TagDataType = TagDataType.Word});
myConn.ReadValues(listTag);
but DB888 have only 100 bytes, all tags in listTag have value "Item does not exist on the PLC" and not throw error.
If I read 1000 bytes from DB which have 900 bytes, 2 buffers 444 (444 = maxPDU - header) bytes len write to PLCTag's, but rest bytes not write to tag's and not have value "Item does not exist on the PLC" (because fall on a non-existent place in DB).
Can you do throw or message "Item not exist"?
Hallo,
ich habe ein Problem mit der Funktion WriteValues, wenn ich diese sehr kurz hintereinander mit dem gleichen Bit verwende. Dies benötige ich für das Fahren einer Achse im Tippbetrieb, d.h. solange eine Taste gedrückt ist ist das Bit gesetzt, wenn nicht mehr gedrückt wird das Bit zurückgesetzt. Wenn ich dass schnell hintereinander mache, dann friert mit die gesamte Anwendung ein. Die Anwendung steht dann am lock und wartet unendlich lange. Entferne ich testweise den lock, dann geht es. Hier habe ich natürlich dann andere Probleme. Was ich noch erwähnen möchte. Im Hintergrund werden Variablen im 1000ms Takt gelesen.
Wie kann ich das Problem umgehen?
Vielen Dank im Voraus
Wolfgang Baldauf
wie Sie die IP-Adresse der PLC von Hardware lesen?
Hi Experts,
Please guide me how we can read real, int values from bytes.
Hello - would it be possible to start & stop a S7-300 using this library?
#43 not fixed
https://mega.nz/#!AYdmnADB!LO0z0Mrn8HSR1Vm19djMzCsEJm1sl2VID2CTzynbhVg is a link to download the example project to test, use DB1 to test.
Hi ,
in the File LibNoDaveConnectionLibrary\DataTypes\Projectfolders\Step7V5\BlocksOfflineFolder.cs there are some Bugs in the GetBlockBytes Method.
var ts1 = (string)row["TIMESTAMP1"];
Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
to that:
//use Windows-1252 code page to get correct time
//because dBaseConverter uses this codepage for strings
var bytes = Encoding.GetEncoding("Windows-1252").GetBytes((string)row["TIMESTAMP1"]);
Helper.GetDt((byte) bytes[0], (byte) bytes[1], (byte) bytes[2], (byte) bytes[3], (byte) bytes[4], (byte) bytes[5]);
Best regards,
Benji
Hey,
I am looking for libnodave library document which is using in EXCEL.
Thanks in advance.
Moelsayed
I noticed that the S7Block has a LastCodeChange and a LastInterfaceChange, Is there also a similar way to notice if a ProjectFolder has changed?
I would like to see if the contents of a ProjectFolder have changed for example the addressing of a DataBlockRow inside a ProjectFolder. This way I can would be able to loop through all the DataBlocks and see which changed.
Currently I loop through all the DataBlocks to see if one changed but it would be neat if there would be some kind of date in the ProjectFolder itself.
Thanks a ton!
Does this library support also S7-1500 ?
Hallo,
ich bekomme manchmal die Meldung das die CPU in Stop ist, obwohl sie es gar nicht ist. Hast Du das auch schon einmal gehabt?
Mein Programm ließt Variablen aus einem DB mit Hilfe der PLCTag-List Funktion.
Gleichzeitig habe ich aber auch ein LiveBit welches alle 1000ms Sekunden gelesen wird. Kann es davon kommen, das sich diese Lese Anforderungen überschneiden?
Sonst läuft alles ohne Probleme.
mfg
Kalle
The following code doesn't give any option to use symbolic or absolute addressing
public string GetSourceBlock(ProjectBlockInfo blkInfo)
the option useSymbol is always false
if (functionBlockRow.ToString(false, false) == "")
retVal.Append(Environment.NewLine);
else
{
retVal.Append(functionBlockRow.ToString(false, true) + Environment.NewLine);
}
is also a performance hit because it calculates two times the awl code,
it can be changed to something like:
public string GetSourceBlock(ProjectBlockInfo blkInfo,bool useSymbol = false)
(...)
string awlCode = functionBlockRow.ToString (useSymbol , true)
if (awlCode == "")
retVal.Append(Environment.NewLine);
else
{
retVal.Append(awlCode + Environment.NewLine);
}
call from " var blks = ConnItem.myConn.PLCListBlocks(PLCBlockType.AllBlocks);"
...
{
int ret = _dc.ListBlocksOfType(Helper.GetPLCBlockTypeForBlockList(myBlk), blocks); //here I get 6116 i.e.
if (ret < 0 && ret != -53763 && ret != -53774 && ret != -255)
throw new Exception("Error: " + libnodave.daveStrerror(ret));
if (ret > 0)
for (int n = 0; n < ret*4; n += 4) // i=0 to 61168*4
{
int nr = blocks[n] + blocks[n + 1]*256; //but blocks is only 8192!
myRet.Add(myBlk.ToString() + nr.ToString());
}
}
return myRet;
}
return null;
}
}
Hi,
I'm looking for some guidance in using the toolbox. I use it to convert S7 project data directly to SCADA-objects.
I am trying to find the Called FB of an UDT-instance and I think using the S7ConvertingOptions might help me filter the addresses. (I have an UDT80 in DB18, 20.0 and I want to know that it is used in FC201)
Could you elaborate what the S7ConvertingOptions do? Or do you know another way of finding the FC?
Recently y did some tests with the "PLCGetBlockInMC7" on S7-400 PLCs. The issue that i will describe here is, i think, not an bug in this library (or libnodave), but rather an bug in either the S7-Firmware or something similar. Maybe somebody knows something about this issue, or it will help somebody encountering the same issue.
The solution was easy: I retry the upload once. This solved the issue for me
First off some information about the software involved:
All blocks that i was testing, where all definitely existing in the CPU.
Now to the issue i encountered.
When you connect to the PLC always the first block that you try to upload via PLCGetBlockInMC7 will fail with 0x8702 "address invalid". It does not matter what block you choose, always the first one will fail immediately (no timeout or something). When you try the second block, even if it is the same, it works without any problem.
I tested this, and could reproduce this behavior consistently. Always the first attempt to upload an block will fail, and the second one will succeed. The strange thing is, that it fails witch 0x8702 Address invalid, as if you are requesting some non supported block or something.
I traced the error and found that the library (and Libnodave) are behaving correctly as far as i can tell, and that in fact the PLC responds with this error. I also checked the Wireshark capture and also the Libnodave debug output, and could not find an error.
Log files
I captured this conversation with wireshark. It shows only the Upload packets, no connection packes:
Failure Upload pcap.zip
I also set the Debug output of libnodave to its maximum and activated an console to see if there is an error. I added some comments into the console output:
Failure Upload.txt
Hi,
in GetNetworksList is variable nw not initialized correctly:
In my opinion correct code should be:
nw = new S7FunctionBlockNetwork();
if (s7FunctionBlockRow.Command == "NETWORK")
{
nw.Parent = blk;
nw.AWLCode = new List();
retVal.Add(nw);
nw.Name = s7FunctionBlockRow.NetworkName;
nw.Comment = s7FunctionBlockRow.Comment;
}
else
{
nw.AWLCode.Add(s7FunctionBlockRow);
}
fixed:
todo:
Hi all,
I'm using the library in order to open an existing tia portial project (ap13), in particular I'm working with the ToolboxForSiemensPLCs utility.
When I try to open a .ap13 file I get and exception telling me that the Siemens.Engineering.ClientAdapter.dll is not found.
I've installed TIA portal v13 SP1 and there isn't such a DLL in my setup.
May someone help me please?
Best Regards,
Luca Casagrande
now my error:
I have PLCTag:
curTag = new PLCTag() { DataBlockNumber = number};
curTag.ByteAddress = 0;
curTag.ValueChanged += ValueChangeEvent;
curTag.TagDataType = TagDataType.String;
curTag has ArraySize is 1 and read only 3 byte: 2 byte is length + 1 char
but length is 20: ( buff [startpos + 1] = 0, buff [startpos] = 20)
After the first reading should be changed ArraySize
When getting the text from a s7 generated source +I and +D dissappears from the obtained text
I used the FC3560 from the project i sent you before, on the last networks i get this text from ProjectBlockInfo.GetSourceBlock(true);
z354: U "DB_FZ_TRACKING".BW_388[2].StaFlag.Belegt;
SPBN z355;
L 1;
L "DB_TRACK_ZAEHL".BW_388;
;
T "DB_TRACK_ZAEHL".BW_388;
z355: U "DB_FZ_TRACKING".BW_388[3].StaFlag.Belegt;
SPBN z356;
L 1;
L "DB_TRACK_ZAEHL".BW_388;
;
T "DB_TRACK_ZAEHL".BW_388;
z356: NOP 0;
END_FUNCTION
and opening the same source block, from the s7 manager has the following code
z354: U "DB_FZ_TRACKING".BW_388[2].StaFlag.Belegt;
SPBN z355;
L 1;
L "DB_TRACK_ZAEHL".BW_388;
+I ;
T "DB_TRACK_ZAEHL".BW_388;
z355: U "DB_FZ_TRACKING".BW_388[3].StaFlag.Belegt;
SPBN z356;
L 1;
L "DB_TRACK_ZAEHL".BW_388;
+I ;
T "DB_TRACK_ZAEHL".BW_388;
z356: NOP 0;
END_FUNCTION
The millisecond conversion is not correct. I changed the function "putDateTimeat" in file libnodave.net.cs
This is what I changed:
tmp = mydatetime.Millisecond;
tmp = tmp / 10;
rem = mydatetime.Millisecond % 10;
b[pos + 6] = Convert.ToByte((tmp / 10) << 4 | tmp % 10);
tmp = (int)mydatetime.DayOfWeek;
b[pos + 7] = Convert.ToByte((rem) << 4 | tmp % 10);
Best Regards
Bert Degrave
Hallo Jochen,
hast du deine Lib schon mal auf nem Raspberry laufen lassen?
In der Lib sind ja Pragma für das IPhone drin. Kann man das eventuell als Basis für den Raspberry hernehmen?
I made an class that discovers available accesible CPU's (only by means of TCP/IP) on an network. This is currently part of an internal project of mine, but i want to integrate it into this Library. It comes with an WinForms dialog, that can be used. It is tested with S7-300, S7-400 and IBH Softec Simulation PLC.
Problem is, it is written in VB.net, not C#. So there are two options.
Should i Implement it as an sepárate Library, or Convert everything to C# to integrate it into this library (I dont know when y will have the time to do so). Which Option do you prefer, or do you have an better solution?
I'm read more DBs different lengths. But read PLCTag("P#DB888.DBX0.0 BYTE 500") throws error because 500 > MaxPDULen.
how to read a long DB another method?
Hallo,
ich möchte von S7-Bauteinen die Attribute (Erstellsprache, Version, Name (Header), Autor, Familie, Änderungsdatum, letzte Schnittstellenänderung) auswerten.
Leider bekomme ich keine oder falsche Werte angezeigt.
Meine Coderealisierung:
For Each baustein In s7ProgrammOrdner.BlocksFolder.BlockInfos
If baustein.blockname = "FC4" Then
block= baustein.GetBlock
End If
Attributergebnisse:
SimaticManager | PLCToolBoxLibrary | Ergebnis | Objekt |
---|---|---|---|
Erstellsprache | BlockLanguage | Nothing | DataTypes.Blocks.Block).BlockLanguage |
Version | Version | 12.11 Falscher Wert (11.15) | DataTypes.Blocks.Step7V5.S7Block).Version |
Name | Name | Nothing | DataTypes.Blocks.Block).Name |
Autor | Autor | IO | |
Familie | Family | Nothing | DataTypes.Blocks.Step7V5.S7Block).Family |
Änderungsdatum | LastCodeChange | Bei UDT's #1/1/0001 12:00:00 AM# | DataTypes.Blocks.Step7V5.S7Block).LastCodeChange |
letzte Schnittstellenänderung | LastInterfaceChange | Bei UDT's #1/1/0001 12:00:00 AM# | DataTypes.Blocks.Step7V5.S7Block).LastInterfaceChange |
Hier die Quelle zum BeispielFC4:
FUNCTION "Symbolischer Name" : VOID
TITLE =Bausteintitel
//BausteinKommentar
//Zeile2
AUTHOR : Autor
FAMILY : Familie
NAME : 'Name'
VERSION : 11.15BEGIN
NETWORK
TITLE =NetzwerkkommentarU "E_1.0"; = "m_cam_active";
END_FUNCTION
Was mache ich falsch?
While making some tests with various S7-400 (CPU414-3DP on Slot 3 and an Ethernet CP443-1 on Slot 5).
I observed the following. the PLC accepts connections via Ethernet not only on Rack 0 Slot 3, but also on Rack 0 Slot 0. The interesting thing is, that one can List the online blocks on Slot 0 and there are event some SDBs in the range of 1003 to 1012, but NOT the blocks that are loaded in the CPU. The Blocks of the CPU are only listed when connected to Slot 3 on the PLC.
From what i understand the Blocks 1000 and above are configured connections and Profibus Connections. I find it interesting that something is responding on Slot0 and does have System Blocks. Does anybody know as to why that is, and also what the content of the SDB's is?
Here i Uploaded the Binaries for the blocks i found online:
Online Blocks form S7-400 Slot 0.zip
Hello,
I found an issue while reading from an Instance DB.
I am using Step7 V5.5 + SP4.
After defining and calling a FB, Step7 and DotNetSiemensPLCToolBoxLibrary (ToolboxForSiemensPLCs) are showing the same content:
After changing a Symbol or Comment in the FB, Step7 updates the corresponding DB:
When I open the DB with DotNetSiemensPLCToolBoxLibrary (ToolboxForSiemensPLCs), it returns still the old Symbol "InitVarname" and old Comment "Initial Comment". After a real change of the FB-interface (for example adding a parameter) and "Check and update Accesses", the Library shows the correct values. But, after a Symbol or a Comment change, an Access update will not be executed.
Hi, I was wondering if its possible to parse different languages when reading symbols and datablocks, i guess when user is changing the language in the simatic manager the language information is taken from somewhere and written in the corresponding database files.
do you have any information where this language file is? or how is it done internally?
At this moment:
tiaPortal = new TiaPortal(TiaPortalMode.WithoutUserInterface);
When i wont to open project i have error "Connection to TiaPortal failed."
When we look inside in the library Siemens.Engineering.dll
string fullPath = Path.GetFullPath(Path.Combine(ApplicationEntryPoint.Loaction, "../../bin/Siemens.Automation.Portal.exe"));
So we must move project to C:\Program Files (x86)\Siemens\Automation\Portal V13\Bin\PublicAPI\V13 SP1 ?? and from there start ?
Also is another problem with TIA.
When Im trying to "PLCListBlocks"
at this point :
int ret = _dc.ListBlocksOfType(Helper.GetPLCBlockTypeForBlockList(myBlk), blocks);
I have error: Error: no message defined!
ret is: -33028
Today y found some bugs in the Interface Parsing section of the MC7Converter, namely the in Parameters.cs. When y did some testing with some unusual code code blocks from one of my clients.
I already Identified them, but more testing needs to be done.
I found the following Bugs:
-When BLOCK_SFB are used in the Interface, for example when calling SFB14 "GET" as MuiliInstances, then the code enters an Endless loop.
-The handling of BLOCK_xx Interface declarations is not correct. So if one of these is used, it Parsing will probably fail.
I am already putting together an Pull Request, for fixing the issues, especially the Endless loop thing.
When using method getcallingstring in an expanded structure from an instance db there should be an option to disable getting the IN, OUT, IN_OUT, STATIC identifiers in the name since that is not how they have to be typed when that signal is used in s7
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.