CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Mon Aug 26, 2019 6:19 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Thu Jul 16, 2015 7:46 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
I've been trying to upload application and log into my device but it is running in "SIL2" mode which locks the memory access so
before login/upload I have to set my "PLC" or device into "Debug mode" using the CODESYS granted GUI menu "SIL2/Enter Debug Mode..."

So far there is no entry point or sub method to access/call that menu (from codesys ScriptEngine), but I found a way to read the GUID of those menus:

Code:
# cmds = IScriptCommands
cmds = system.commands

# cmd = IScriptCommand
for cmd i cmds.GetEnumerator():
    print(cmd.name)
    print(cmd.guid)


This gives me a GUID of the searched command, but is there a way to call/execute this menu using the GUID
(like its done in codesys/Test Manager python scripts)?

Thanks


Top
   
PostPosted: Thu Jul 16, 2015 7:58 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, etamgul,

The following should work (I did not test it myself, I don't have the SIL2 extension installed here):

Code:
system.commands["sil2_commands", "enter_debug_mode"].execute("{device object guid"})

or alternatively, using the command guid
Code:
system.commands["{B4C6C2D3-CFDA-4A01-9065-E9AD98FADFA4}"].execute("{device object guid"})


You need to pass the guid of the device in question.

Remark:
The execute() function of the commands is officially undocumented and unsupported (as we do not intend to document the command interface for end users), but it may be used as an "emergency exit" in cases like this. Usually, this indicates a missing "official" scripting API. I'll talk to the SIL2 guys whether they intend to add an official scripting API for SIL2.

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Thu Jul 16, 2015 12:03 pm 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
Hi

Thank you for the snippet, that was thing I was looking for!
Its working but now i got a new problem: somehow I have to answer a pop-up windows that is asking me whether I really want to put my PLC into debug mode.

I found the ISystem.prompt_answers Property but so far I had no luck using it,
could you help me with this one also?

Tried to print out the question list and place many answers everywhere but seems that the execute command is halting the execution of the script too.

Code:
system.prompt_answers["sil2_commands"]= PromptResult.OK
system.prompt_answers["enter_debug_mode"]= PromptResult.OK

system.commands["sil2_commands", "enter_debug_mode"].execute(str(proj_device.guid))

system.prompt_answers["sil2_commands"]= PromptResult.OK
system.prompt_answers["enter_debug_mode"]= PromptResult.OK


system.delay(1000)

system.prompt_answers["sil2_commands"]= PromptResult.OK
system.prompt_answers["enter_debug_mode"]= PromptResult.OK

for i in system.prompt_answers:
    print str(i)


And I'm sure that I'm not using the prompt_answer correctly.


Top
   
PostPosted: Thu Jul 16, 2015 4:16 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi,

The key for the prompt_answers dictionary neds to be the message key of the dialog in question, not the command name.

The message key for the prompt in question is "EnterDebugMode_Prompt".

There's another dialog coming up later, which is a simple info dialog. You can either catch it using the message key "EnterDebugMode_Info_PlcEnteredDebugMode", or by unsetting the ForwardSimplePrompts flag - unsetting this flag simply suppresses all dialogs with only a single OK button and no choice to the user.

In general, you can learn about unknown message keys by setting the "LogMessageKeys" flag at the beginning of your script:
Code:
system.prompt_handling |= PromptHandling.LogMessageKeys

This will log all message keys to the message view.

In your case, there are two more message keys you could get: "EnterDebugMode_Error_PlcDeniesDebugMode" and "EnterDebugMode_Exception" - they can happen when something goes wrong.

HTH,
Markus

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Fri Jul 17, 2015 7:14 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
Thank you again, I think I've managed it. I had to experiment a bit but just for the others who would like to do the same:

If I got it right

Code:
system.prompt_handling |= PromptHandling.ProcessScriptPrompts # this forwards prompts to script
system.prompt_handling &= ~PromptHandling.ForwardSimplePrompts # this silences other prompts

system.prompt_answers["EnterDebugMode_Prompt"]=PromptResult.OK # you have to put it before the execute
system.commands["sil2_commands", "enter_debug_mode"].execute(str(proj_device.guid))


What I did not understand is why I had to pre-answer a prompt but its working so far so I dont mind :)


Top
   
PostPosted: Fri Jul 17, 2015 7:41 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi,

The ProcessScriptPrompts is only about the prompts issued by the script itsself, via system.ui - it is disabled by default so a script which disables ForwardSimplePrompts can still show its own prompts.

You need to "pre-answer" the prompts for the following reason: Command execution is synchroneous[1], like any other function or method call. Control only returns back to the script after the command is finished. So when the script lines after the command are executed, all prompts have already been shown. The only way to solve this is to preload the answers for the expected prompts[2].

[1] Even if it was asynchroneous, there'd be a race condition.

[2] Or to invent a time traveling device, of course... :D

HTH,
Markus

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Thu Aug 13, 2015 7:45 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
I was experimenting with this system.commands["", ""] interface and I'm trying to figure out
where did you get those strings ("sil2_commands", "enter_debug_mode").

When i list all the commands i get the same guid but with different name:
b4c6c2d3-cfda-4a01-9065-e9ad98fadfa4 - "Enter debug mode..."

Could you tell me how can I get a list of the available/searchable tokens that can be searched for
using the IScriptCommands' [] get interface?

To be more excact: I'm trying to figure out how could I set and enable a breakpoint using the script.
I'm not sure if its managable at all (or available but just with limitation e.g. script executed under GUI).

Thanks!


Top
   
PostPosted: Thu Aug 13, 2015 7:57 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
Never mind, i found it:

Code:
for cmd in system.commands.GetEnumerator(): 
    print("{0} - {1} - {2}".format(cmd.guid, cmd.name, cmd.tokens));


b4c6c2d3-cfda-4a01-9065-e9ad98fadfa4 - Enter debug mode... - Array[str](('sil2_commands', 'enter_debug_mode'))
37fbe729-b4ba-41fe-9f74-4987df16c487 - Create coverage info - Array[str](('sil2_commands', 'createcoverageinfo'))


Top
   
PostPosted: Sun Aug 16, 2015 8:31 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi,

Happy you found a solution - on the other hand, you can also use the guid as key in the [index] operator - a little bit more ugly, but it should work, too.

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Fri Sep 18, 2015 10:10 am 
Offline

Joined: Thu Aug 27, 2015 8:51 am
Posts: 3
Code:
system.prompt_handling |= PromptHandling.ProcessScriptPrompts # this forwards prompts to script
system.prompt_handling &= ~PromptHandling.ForwardSimplePrompts # this silences other prompts

system.prompt_answers["EnterDebugMode_Prompt"]=PromptResult.OK # you have to put it before the execute
system.commands["sil2_commands", "enter_debug_mode"].execute(str(proj_device.guid))


I had the same issue and this works fine for me but I'm still wondering, if there is an easy/easier way to find out the project device guid? I found the guid in an exported file (Project -> Export...) but i hope there is a more elegant solution (maybe another python script?).


Top
   
PostPosted: Fri Sep 18, 2015 10:19 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi,

The objects in a project all have a "guid" property - so you could use projects.primary.find("DeviceName")[0].guid if the device is the only object with this name.

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Wed May 11, 2016 1:26 pm 
Offline

Joined: Wed Jun 18, 2014 4:55 pm
Posts: 33
I am trying to execute the command : ('Update structured variables', <System.Guid object at 0x00000000000000F9 [714fa2c5-b677-45b2-85d8-3144aba5d531]>, Array[str](('recipes', 'updatestructuredvariables')))
This is a workaround for me because recipe management is not available through scripts

I need to update the structured variables of all the recipes from the script. I thought the argument to the execute command would be the guid of the recipe. But I get the error : object reference not set to an instance of an object. Am I missing some argument?

Code:
cmd = system.commands['{714fa2c5-b677-45b2-85d8-3144aba5d531}'] #get the update structured variables command
cmd.execute('{f992dc78-635a-4094-bcb4-56c1e53ee1de}')#execute command using recipe guid


Top
   
PostPosted: Thu May 12, 2016 4:19 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi,

Please note that using the undocumented command interface is not a supported usecase. We might use it for workaorunds sometimes.

The command in question does not take any arguments. Instead, it works on the currently selected Recipe Definition Editor. If the active view is not a Recipe Definition Editor, it will throw a null reference exception.

HTH,
Markus

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 13 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited