Hello everyone,
For the purpose of preparing some materials about AF I found myself preparing sequence diagrams multiple times. Since this was a tedious task I decided to use some tools and make it easier. In the process I wrote a small Python script that is parsing DETT traces created by AF_Debug_Trace=TRUE in the project.
The python script parsed out the information about AF events and prepared syntaxt needed for PlantUML tools available online. The translated UML was saved to file and copied to clipboard. Then you can paste it to the online tool and you get nice looking and easy to read diagrams of the sequence of Actors' activities.
Steps to generate the diagram:
1. Install Python3
2. Install the packages required for the script to work: easygui, pyperclip
Installing the packages can be done with cmd command "pip install easygui" and "pip install pyperclip"
easygui is used to ask the user for paths to txt files
Pyperclip is used to copy the final string into clipboard
3. Enable AF_Debug_Trace in your AF project
4. Generate trace from your project
5. Save the trace in TXT file
6. Run the parser script in windows cmd line "python C:\YourPathHere\AFParser.py"
7. If everything went well your web browser should open and go to page http://www.planttext.com/planttext
8. Once you're there you can Ctrl + V the text from clipboard, click Refresh and you get your diagram.
I know that this is an annoying list of steps but once you go through them you will find them to be quick. If you want to make them even faster you can create a BAT file that would just run the CMD line from step 6. I include a file like this in the attachments. Notice that it uses an absolute path so you need to modify it to point to your script.
Example Diagram generated this way:
You can also preview a movie visualizing how you go though the steps.
Attached you can find the python script.
NOTE. If you find thet the "message sent" events are not captured by your DETT you need to remove and add again the conditional disable structure in the Message Enqueuer.vi. There seems to be something wrong with that structure, but once you replace it with something exactly the same, it works fine again.
I hope this is useful for someone.
Hi Piotr,
this is exactly what i want to have.
But its a feature of afw provided with LV2015 and i'm tied to LV2014.Is it possibe, to downconvert LV2015's afw to LV2014?
Best regards
Thomas
I think the AF_Debug_Trace is not available with versions <2015
Well the only thing you need to do is to install on some other machine LV2015, convert the AF libraries to previous version (i think everything should be compatible) and you have it.
Alternatively you can just add the functionality to send the user defined trace events yourself to the AF VIs.
Alternatively you can add your own events, take my parser and modify it to parse your events, and model that
LV and Python working in symbiotic love...wonderful! Thanks for the work, Piotr. Can't wait to give it a try!
Allen, are you referring to the AF debug trace tool? I would be interested in this too.
I agree with Michael. "Sequence diagram" is the common name for this sort of diagram. More people will find this if you name it accordingly.
And, thanks. This is the sort of diagram I hoped someone would generate when niACS made the debug traces available.
This looks seriously awesome. Can't wait to try it out.
Is it not possible to show the Actor class names? It is difficult to tell the difference between the various "Actor 6640xx".
You just have to provide the name as the Debug Alias when you launch the actor. That will be used in the diagram.
Powell: I think that shortfall might be on NI... I think we just use "Actor N" in all cases unless you give the actor a debug name. But many systems have actors that are unique per type... I can see where using the class name would've been a good idea.
Hey all, can you please tell me what kind of improvements would you like to see with this tool? I was thinking of building a pure LV version that could be integrated as a tool in to the menus. It wouldn't require internet connection and any python parsing. This however would require me to build a custom toolkit or two. Can you please let me know if you are interested in something like this? I dont want to waste time
I'm interested. I'd love to see the output integrated with the GOOP UML Toolkit, if you can translate the DETT output into a sequence diagram file.
AristosQueue wrote:
I can see where using the class name would've been a good idea.
But possibly impractical. The traces are pretty long as it is. Since you'd still want the unique ID to handle instances where you have two of the same type, the total actor name <actor type>:<unique ID> could get pretty atrocious.
For now I have refined the parser a little bit. It is now removing the word Actor from the names, so be careful about that. Ive done it because i didnt like the prefix actor in front of everything in the diagram It's also parsing the types of messages a little better. The message no longer has to be a part of library to be parsed out. The new version is 1.1
How can this have 500+ downloads ?! I didn't know we had 500 customers using actors in LV
niACS wrote:
Since you'd still want the unique ID to handle instances where you have two of the same type, the total actor name <actor type>:<unique ID> could get pretty atrocious.
Subtract 6640000 from the Actor.vi clone number and you'll only need a couple of digits for the number, saving more characters for the name.
drjdpowell wrote:
Subtract 6640000 from the Actor.vi clone number and you'll only need a couple of digits for the number, saving more characters for the name.
Fair point. I'd need to confirm that we always got the same range of clone numbers, and I'd probably want to keep four digits, just because I hate dink think.
Keep all the digits, just surpress the leading zeros. I don't think the 6640000 number changes (it's some kind of hash of "Actor"), but one can determine it dynamically from the first clone.
Hi Piotr,
thank you for this helpful tool.
I just used it to debug/"re-engineer" my first AF-Project.
I edited the script to handle time-delayed messages and added an additional case:
elif 'created Time-Delayed Message' in msg:
creator, what, typeof = dsplit(msg, ' created ', ' for ')
if '.lvlib:' in typeof:
not_used, typeof, not_used = dsplit(typeof, '.lvlib:', '.lvclass')
else:
typeofarr = typeof.split('.lvclass')
typeof = typeofarr[0]
text = 'create %s\n' % (leg(what))
text += '%s->%s:%s\n' % (leg(creator), leg(what), leg(typeof))
To automise the image creation I replaced planttext with plantUML and used hardcoded paths to avoid the filebrowser.
I'd like to use it in LabVIEW directly.
Let me know if the pure-LV solution is ready for testing
Great tool, Piotr!
Is it possible to add feature, that dialog window for paths selection will start not from the default location, but from the last used one? Just to store to some config file used path, and then set it next time as start path for trace file selection, and for storing of uml diagram text?
Also, are you going to implement it in pure LabVIEW, as some LabVIEW add-on toolkit? I guess it'll be very useful.
Thanks a lot,
Sincrerely, kosist90.
I dont think i will tinker anymore with this python implementation but I am very interested in writing a pure LV version of this tool. I'm still not sure how i would do it but i will keep you posted.
Actually, regarding my last post - the easiest way for me was to modify script, and add to functions fileopenbox, filesavebox default path; so even config file is needed...
Hi Piotr,
Have you had chance to develop this tool completely at LV?
Is this tool working also with non-actor codes?
Regards,
Witold
Hello,I follow your document.
But I got this , can you tell me why
C:\Users\10156>python "C:\Users\10156\Documents\DETT\AFParser.py" Traceback (most recent call last): File "C:\Users\10156\Documents\DETT\AFParser.py", line 37, in for line in af: UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 938: illegal multibyte sequence
I am getting the same unicode error. Anyone got any suggestions?
Here is the error i am getting from both the original and 1.1 version.
Note: I am running Python 3.6 (yes I know that is old, but it is a legacy system and that's what they have installed).
I may see if try to see if I can run it on another PC with a newer version of python.
Tried it on a Linux box with Python 3.11 and got the same error? Anyone have any thoughts?
Hey Sam,
Are you exporting the trace to a TXT file as per step 6 in the original post? It works for me with the export.
try changing line 39 to handle the text encoding as utf-8.
original: with open(path) as af: # With the text file as af
New: with open(path, encoding="UTF-8") as af: # With the text file as af
According to the error code it is failing to convert a byte 0x9d which is not available in Windows cp1252, but according to the link below the UTF8 should support it.
https://stackoverflow.com/questions/49640513/unicodedecodeerror-charmap-codec-cant-decode-byte-0x9d-...
Best of luck
@.aCe.
Yes that was exactly my problem. I read step 5:
"5. Save the trace in TXT file"
As just click on save. However to get a true text file you have to export it.