Codesys interface properties in ST - interface

I'm trying to make a interface with properties in st instead of having to add them as property with getter and setting by doing a lot of clicking.
How I am doing it now
How I want to do it:
INTERFACE Door
VAR
sensorBack : BOOL;
END_VAR
Is there a possibility to do something like this or do you always need to add them through the program structure?

Structured Text in codesys always felt like an after thought.
The short answer is that you need to use the GUI to add them one by one.
The long answer is, you can use the bultin (ScriptEngine) Python APIs to simplify the generation of interfaces with many properties:
from __future__ import print_function
import re
import sys
app = projects.primary.active_application
# Fill in the following:
interface_name = '' # Example 'IMyInterface'
base_interface_type = None # Example 'IMyBaseInterface', leave as None if there's no base interface
interface_properties = [
{
'name': '', # Example 'MyProperty'
'return_type': '', # Example 'BOOL'
'getter': True, # Set to False if you want no getter
'setter': True # Set to False if you want no setter
}# , # Include as many properties as you want in a comma (,) separated list
# {
# 'name': ''
# 'return_type': ''
# 'getter': True,
# 'setter': True
# }
]
# Don't touch the code below
if base_interface_type is None:
interface = app.create_interface(name=interface_name)
else:
interface = app.create_interface(name=interface_name, baseInterfaces=base_interface_type)
for property_data in interface_properties:
property_name = property_data['name']
return_type = property_data['return_type']
include_getter = property_data['getter']
include_setter = property_data['setter']
property = interface.create_property(name=property_name, return_type=return_type)
getter = property.find('Get')[0]
setter = property.find('Set')[0]
if not include_getter:
getter.remove()
if not include_setter:
setter.remove()
Save the above script as a *.py file, change the parameters according to your needs and run the script:
View -> Scripting -> scripting Immediate:
Press on the three dots (...):
Navigate to the script (*.py) file and open it. A new Interface with the desired properties should be generated.
Heres an example of me running the script with the following parameters:
interface_name = 'IMyInterface'
base_interface_type = None
interface_properties = [
{
'name': 'MyProperty1',
'return_type': 'BOOL',
'getter': True,
'setter': False
},
{
'name': 'MyProperty2',
'return_type': 'INT',
'getter': False,
'setter': True
},
{
'name': 'MyProperty3',
'return_type': 'DINT',
'getter': True,
'setter': True
},
{
'name': 'MyProperty4',
'return_type': 'WORD',
'getter': False,
'setter': False
},
{
'name': 'MyProperty5',
'return_type': 'BOOL',
'getter': True,
'setter': False
}
]

You need to add them via the program structure as far as I know.

Related

VS Code Formatting JSX with new lines in useCallback()

VSC's jsx formatting looks weird.
If there's no param in useCallback it looks fine, but there's new line when there's param. And also there's new line in dependency array when useCallback method has params.
I want to change this as in the case where there are no parameters.
Any Ideas?
const onSubmitEditing = useCallback(
({nativeEvent}) => {
setSearchQuery(nativeEvent.text);
},
[setSearchQuery],
);
const clearText = useCallback(() => {
setSearchBoxText('');
}, [setSearchBoxText]);
This is my .prettierrc.js.
And I use 'Prettier - Code formatter' as default formatter.
module.exports = {
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
};

Perl's OpenAPI::Client - how to pass additionalProperties in OpenAPI GET query request?

I'm trying to pass filter variables in a GET request to an OpenAPI route with this specification:
- in: query
name: params
schema:
type: object
additionalProperties:
type: string
style: form
explode: true
I've tried various different ways of passing the data at request time:
my $client = OpenAPI::Client->new(...);
my $tx = $client->findApps({
params => { 'id' => '1' }
});
my $tx = $client->findApps({ 'id' => '1' });
What is the correct way to do this?

how to create a CreativeAsset in dfp api

I'm trying to create an asset (CreativeAsset) to be used in a template Creative later. I cannot find in the documentation any way to create the asset itself, only to provide the base64 bytes, but I'd like to use this asset in multiple places, so I would prefer to load it once..Is there a way to create only a CreativeAsset?
https://developers.google.com/doubleclick-publishers/docs/reference/v201705/CreativeService.CreativeAsset
Here is the solution from the DFP API team:
A CreativeAsset must be created as a part of a creative. There is no dedicated service to create a CreativeAsset alone. But then, you can use the assetId to copy a CreativeAsset to a new creative. Basically, you can first create a creative, then get the creative asset's assetId and use it to create multiple creatives
This is a code example using python:
with open(f, "rb") as html_file:
html_file_data = base64.b64encode(html_file.read())
html_file_data = html_file_data.decode("utf-8")
# USING TEMPLATE
creative1 = {
'xsi_type': 'TemplateCreative',
'name': '',
'advertiserId': '',
'size': {'width': 1, 'height': 1},
'creativeTemplateId': '',
'creativeTemplateVariableValues': [
{
'xsi_type': 'AssetCreativeTemplateVariableValue',
'uniqueName': 'HTMLFile',
'asset': {
'assetByteArray': html_file_data,
'fileName': ''
}
}
# other variables
]
}
# USING CUSTOM
creative2 = {
'xsi_type': 'CustomCreative',
'name': '',
'advertiserId': '',
'size': {'width': 1, 'height': 1},
'destinationUrl': '',
'customCreativeAssets': []
}
creative2['customCreativeAssets'].append({
'xsi_type': 'CustomCreativeAsset',
'macroName': '',
'asset': {
'assetByteArray': html_file_data,
'fileName': ''
}
})
creative_service = dfp_client.GetService('CreativeService', version='v201702')
upload_creative1 = creative_service.createCreatives(creative1)
upload_creative2 = creative_service.createCreatives(creative2)
I hope this works.

How to set 'Author' for a node type on a custom form?

I have following code...
I have a node type called MY_NODE_TYPE.
I have set up a cusdtom URL for my node type: 'node/%/bla'). At this URL my 'default author' field is set to 'Anonymous' when it should be admin (uid 1).
I'd like to know where I should set uid to be 1 if following code does not work. (How can I make this code work?)
function bla_menu() {
$items['node/%/bla'] = array(
'title' => t('Bla'),
'page callback' => 'bla_callback',
);
}
function bla_callback () {
module_load_include('inc', 'node', 'node.pages');
$new_node = new stdClass;
$new_node->type = 'bla';
node_object_prepare($new_node);
$new_node->language = LANGUAGE_NONE;
$new_node->uid = 1;//This is wehre I set uid to be one and is not effective
return drupal_get_form('MY_NODE_TYPE_form', $new_node);
}
You should implement hook_node_presave to set the values you need to change there.
Code sample:
function MODULE_node_presave($node) {
if($node->type === 'MY_NODE_TYPE')
$node->uid = 1;
}

Extjs - autocomplete filter 2 properties

By following this example http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/form/forum-search.html
I could apply the auto-complete feature on my combo box, using php/postgresql query retrieves the names then:
{
xtype: 'combo',
store: ds,
hideTrigger:true,
typeAhead: false,
id: 'search_input_text',
width: 187,
queryMode: 'remote',
hideLabel: true,
queryParam: 'query',
displayField: 'first_name',
valueField: 'first_name',
listConfig: {
loadingText: 'Loading...',
getInnerTpl: function() {
return '{first_name}';
}}
listeners: {
buffer: 50,
change: function() {
var store = this.store;
store.clearFilter();
store.filter({
property: 'first_name',
anyMatch: true,
value : this.getValue()
});
}
}
}
Now, I need to edit this to let user enter either the first or last name of the student, and then each name entered (first or last) will be shown in the combo box.
So, I edited the query to make it retrieve the names :
SELECT first_name, last_name FROM students WHERE first_name ILIKE '%$query%' OR last_name ILIKE '%$query%' ";
and:
displayField: 'first_name'+'last_name',
valueField: 'first_name'+'last_name',
return '{first_name}'+'{last_name}';
store.filter({
property: 'first_name',
anyMatch: true,
value : this.getValue()
},
{
property: 'last_name',
anyMatch: true,
value : this.getValue()
}
but still, it retrieves only first names according to what user types,
Note that if I use this alone:
store.filter({
property: 'last_name',
anyMatch: true,
value : this.getValue()
});
it works fine with last names only.
You can apply multiple filters to data store like this:
var filters = [
new Ext.util.Filter({
filterFn: function(item){return item.get('first_name') == this.getValue() || item.get('last_name') == this.getValue();
}
})
];
store.filter(filters);
The above code block is just an idea on how to apply multiple filters in the same field. Notice the double-pipe "||". You can use "&&" as per your needs. It is like SQL query.