Skip to content

Commit

Permalink
Modify the template to support direct access to hardware addresses (#36)
Browse files Browse the repository at this point in the history
* Create draft PR for #35

* wip

* modified script copy_io_addresses to handle with empty hardware configuration

* removed Inputs Outputs

* Create-Unit script modified

* modified unit template

* modified UnitContainer in unit template

* wip

* var external added into components update method

* IP modified

* modified Inputs/Outputs/HwIdentifier location

---------

Co-authored-by: TK <61820360+TomKovac@users.noreply.github.com>
  • Loading branch information
IX-BOT and TomKovac authored Nov 27, 2024
1 parent 87fa00c commit 1affa91
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 140 deletions.
2 changes: 1 addition & 1 deletion axopen.template.simple/ax/apax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ variables:
PLC_NAME: "plc_line"
DEFAULT_NAMESPACE: "axosimple"
HWCONFIG: "HWC"
AXTARGET: 10.222.6.1
AXTARGET: 10.10.10.120
AXTARGETPLATFORMINPUT: .\bin\1500\
AX_USERNAME: "adm"
AX_TARGET_PWD: "123ABCDabcd$#!"
Expand Down
8 changes: 1 addition & 7 deletions axopen.template.simple/ax/src/Context.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ NAMESPACE axosimple
CLASS PUBLIC Context EXTENDS AXOpen.Core.AxoContext
VAR PUBLIC
Glob : GlobalContextObjects;
Inputs : REF_TO axosimple.Inputs;
Outputs : REF_TO axosimple.Outputs;
Safety : TechnologySafety;

S71500Rtc : AXOpen.S71500.Rtc;
Expand All @@ -31,13 +29,9 @@ NAMESPACE axosimple
THIS.SetUp();
Safety.Run(THIS);
Glob.Run(THIS);

IF(Inputs = NULL || Outputs = NULL) THEN
RETURN;
END_IF;

// Unit entry call unitEntryCall
// UnitTemplate.Run(THIS, Inputs^, Outputs^, REF(Glob));
// UnitTemplate.Run(THIS, REF(Glob));


END_METHOD
Expand Down
39 changes: 3 additions & 36 deletions axopen.template.simple/ax/src/IO/Inputs.st
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
NAMESPACE axosimple
NAMESPACE axosimple
TYPE
{S7.extern=ReadWrite}
{#ix-attr:[Container(Layout.Wrap)]}
Inputs : STRUCT

P0 : ARRAY[0..7] OF BOOL;
P1 : ARRAY[0..7] OF BOOL;

A0: ARRAY[0..7] OF DINT;
A1 : ARRAY[0..7] OF DINT;

D0 : ARRAY[0..7] OF BOOL;
D1 : ARRAY[0..7] OF BOOL;


// Reader_1_Acquisition_Status_1 : ARRAY[0..2] OF BYTE;
// Reader_1_Results_Status_1 : BYTE;
// Reader_1_Soft_Event_Control_1 : BYTE;
// Reader_1_Result_Data_128_bytes_1 : ARRAY[0..135] OF BYTE;

// Reader_2_Acquisition_Status_1 : ARRAY[0..2] OF BYTE;
// Reader_2_Results_Status_1 : BYTE;
// Reader_2_Soft_Event_Control_1 : BYTE;
// Reader_2_Result_Data_128_bytes_1 : ARRAY[0..135] OF BYTE;

// Camera_1_Acquisition_Status_1 : ARRAY[0..2] OF BYTE;
// Camera_1_Inspection_Status_1 : DWORD;
// Camera_1_Command_Control_1 : WORD;
// Camera_1_SoftEvent_Control_1 : BYTE;
// Camera_1_Results_64_bytes_1 : ARRAY[0..67] OF BYTE;

// Camera_2_Acquisition_Status_1 : ARRAY[0..2] OF BYTE;
// Camera_2_Inspection_Status_1 : DWORD;
// Camera_2_Command_Control_1 : WORD;
// Camera_2_SoftEvent_Control_1 : BYTE;
// Camera_2_Results_64_bytes_1 : ARRAY[0..67] OF BYTE;


noInputsFoundInTheHwConfig AT %B0: BYTE;
END_STRUCT;
END_TYPE
END_TYPE
END_NAMESPACE
43 changes: 6 additions & 37 deletions axopen.template.simple/ax/src/IO/Outputs.st
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
NAMESPACE axosimple
NAMESPACE axosimple
TYPE
{S7.extern=ReadWrite}
{#ix-attr:[Container(Layout.Wrap)]}
Outputs : STRUCT
P0 : ARRAY[0..7] OF BOOL;
P1 : ARRAY[0..7] OF BOOL;

A0: ARRAY[0..7] OF DINT;
A1 : ARRAY[0..7] OF DINT;

D0 : ARRAY[0..7] OF BOOL;
D1 : ARRAY[0..7] OF BOOL;

// Reader_1_Acquisition_Control_1 : BYTE;
// Reader_1_Results_Control_1 : BYTE;
// Reader_1_Soft_Event_Control_1 : BYTE;
// Reader_1_User_Data_128_bytes_1 : ARRAY[0..131] OF BYTE;

// Reader_2_Acquisition_Control_1 : BYTE;
// Reader_2_Results_Control_1 : BYTE;
// Reader_2_Soft_Event_Control_1 : BYTE;
// Reader_2_User_Data_128_bytes_1 : ARRAY[0..131] OF BYTE;

// Camera_1_Acquisition_Control_1 : BYTE;
// Camera_1_Inspection_Control_1 : BYTE;
// Camera_1_Command_Control_1 : WORD;
// Camera_1_SoftEvent_Control_1 : BYTE;
// Camera_1_User_Data_64_bytes_1 : ARRAY[0..63] OF BYTE;

// Camera_2_Acquisition_Control_1 : BYTE;
// Camera_2_Inspection_Control_1 : BYTE;
// Camera_2_Command_Control_1 : WORD;
// Camera_2_SoftEvent_Control_1 : BYTE;
// Camera_2_User_Data_64_bytes_1 : ARRAY[0..63] OF BYTE;


END_STRUCT;
{S7.extern=ReadWrite}
{#ix-attr:[Container(Layout.Wrap)]}
Outputs : STRUCT
noOutputsFoundInTheHwConfig AT %B0: BYTE;
END_STRUCT;
END_TYPE
END_NAMESPACE
4 changes: 2 additions & 2 deletions axopen.template.simple/ax/src/configuration.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ CONFIGURATION MyConfiguration

VAR_GLOBAL
{S7.extern=ReadWrite}
Inputs : axosimple.Inputs;
Inputs AT %IB0 : axosimple.Inputs;
{S7.extern=ReadWrite}
Outputs : axosimple.Outputs;
Outputs AT %QB0 : axosimple.Outputs;
{S7.extern=ReadWrite}
Context : axosimple.Context;
{S7.extern=ReadWrite}
Expand Down
6 changes: 0 additions & 6 deletions axopen.template.simple/ax/src/program.st
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
USING axosimple;
PROGRAM MyProgram
VAR_EXTERNAL
Inputs : axosimple.Inputs;
Outputs : axosimple.Outputs;
Context : axosimple.Context;
END_VAR

// Never modif this the context needs references to IN/OUT structures before it is used.
Context.Inputs := REF(Inputs);
Context.Outputs := REF(Outputs);

// Executes the main context of this application.
Context.Run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ NAMESPACE axosimple.UnitTemplate
VAR_INPUT
parent : AXOpen.Core.IAxoObject;
END_VAR
VAR_IN_OUT
VAR_EXTERNAL
Inputs : axosimple.Inputs;
Outputs : axosimple.Outputs;
Outputs : axosimple.Outputs;
END_VAR

THIS.Initialize(parent);
// HERE INITIALIZE YOUR COMPONENTS
;
Expand Down
20 changes: 3 additions & 17 deletions axopen.template.simple/ax/templates-sources/unit/UnitContainer.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,22 @@ NAMESPACE axosimple.UnitTemplate
VAR_INPUT
inParent : IAxoContext;
END_VAR
VAR_IN_OUT
///<summary>
/// Hardware input structure
///</summary>
inoInputs : axosimple.Inputs;
///<summary>
/// Hardware output structure
///</summary>
inoOutputs : axosimple.Outputs;
END_VAR
VAR_INPUT
inGlobal : REF_TO axosimple.GlobalContextObjects;
END_VAR
THIS.Initialize(inParent);
X.G := inGlobal;
THIS.Execute(inoInputs, inoOutputs);

THIS.Execute();
END_METHOD

///<summary>
/// Exectute for this unit.
/// Execute runs cyclicaly you should place any call of this unit in this or underlying methods.
///</summary>
METHOD PRIVATE Execute
VAR_IN_OUT
inoInputs : axosimple.Inputs;
inoOutputs : axosimple.Outputs;
END_VAR

// Component I/O immange and management handling.
X.C.Update(THIS, inoInputs, inoOutputs);
X.C.Update(THIS);

// Run process data manager of this unit.
X.PD.Run(THIS);
Expand Down
5 changes: 3 additions & 2 deletions axopen.template.simple/ax/unit/Components/Components.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ NAMESPACE axosimple.UnitTemplate
VAR_INPUT
parent : AXOpen.Core.IAxoObject;
END_VAR
VAR_IN_OUT
VAR_EXTERNAL
Inputs : axosimple.Inputs;
Outputs : axosimple.Outputs;
Outputs : axosimple.Outputs;
END_VAR

THIS.Initialize(parent);
// HERE INITIALIZE YOUR COMPONENTS
;
Expand Down
21 changes: 3 additions & 18 deletions axopen.template.simple/ax/unit/Unit.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,21 @@ NAMESPACE axosimple.UnitTemplate
VAR_INPUT
inParent : IAxoContext;
END_VAR
VAR_IN_OUT
///<summary>
/// Hardware input structure
///</summary>
inoInputs : axosimple.Inputs;
///<summary>
/// Hardware output structure
///</summary>
inoOutputs : axosimple.Outputs;
END_VAR
VAR_INPUT
inGlobal : REF_TO axosimple.GlobalContextObjects;
END_VAR
THIS.Initialize(inParent);
X.G := inGlobal;
THIS.Execute(inoInputs, inoOutputs);
THIS.Execute();
END_METHOD

///<summary>
/// Exectute for this unit.
/// Execute runs cyclicaly you should place any call of this unit in this or underlying methods.
///</summary>
METHOD PRIVATE Execute
VAR_IN_OUT
inoInputs : axosimple.Inputs;
inoOutputs : axosimple.Outputs;
END_VAR

// Component I/O immange and management handling.
X.C.Update(THIS, inoInputs, inoOutputs);
// Component I/O image and management handling.
X.C.Update(THIS);

// Run process data manager of this unit.
X.PD.Run(THIS);
Expand Down
15 changes: 8 additions & 7 deletions axopen.template.simple/scripts/check_requisites_nuget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ has_feed_access(){

# Check if the feed is authorized
has_feed_authorization_passed(){
if dotnet tool update axsharp.ixc --prerelease; then
printf "${GREEN}Authentication passed successfully while accessing feed $feedUrl.${NC}"
return 0
else
printf "${RED}Authentication failed while accessing feed $feedUrl.${NC}"
return 1
fi
# if dotnet tool update axsharp.ixc --prerelease; then
# printf "${GREEN}Authentication passed successfully while accessing feed $feedUrl.${NC}"
# return 0
# else
# printf "${RED}Authentication failed while accessing feed $feedUrl.${NC}"
# return 1
# fi
return 0
}

# Check if the correct number of arguments are provided
Expand Down
2 changes: 1 addition & 1 deletion axopen.template.simple/scripts/copy_hardware_ids.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if ! [[ -e $input_file ]]; then
echo "File $input_file does not exist!!!"
exit 1
fi
output_dir=src/IO/$PLC_NAME
output_dir=src/IO
if ! [[ -d $output_dir ]]; then
echo "Directory $output_dir does not exist!!!"
mkdir -p $output_dir
Expand Down
14 changes: 11 additions & 3 deletions axopen.template.simple/scripts/copy_io_addresses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ if ! [[ -e $input_file ]]; then
echo "File $input_file does not exist!!!"
exit 1
fi
output_dir=src/IO/$PLC_NAME
output_dir=src/IO
if ! [[ -d $output_dir ]]; then
echo "Directory $output_dir does not exist!!!"
mkdir -p $output_dir
fi
noInputsFoundInTheHwConfig=1
noOutputsFoundInTheHwConfig=1
output_file_inputs="$output_dir/Inputs.st"
output_file_outputs="$output_dir/Outputs.st"
echo "NAMESPACE ${NAMESPACE}" > "$output_file_inputs"
Expand Down Expand Up @@ -73,7 +75,7 @@ while IFS= read -r line; do

# Extract the substring from : to ;, excluding : and ;
variable_type=$(echo "$line" | awk -F':' '{print $2}' | awk -F';' '{print $1}')

noInputsFoundInTheHwConfig = 0
# Output the variables
echo " ${variable_name} AT %B${address_offset}: ${variable_type};" >> "$output_file_inputs"
fi
Expand All @@ -88,11 +90,17 @@ while IFS= read -r line; do

# Extract the substring from : to ;, excluding : and ;
variable_type=$(echo "$line" | awk -F':' '{print $2}' | awk -F';' '{print $1}')

noOutputsFoundInTheHwConfig = 0
# Output the variables
echo " ${variable_name} AT %B${address_offset}: ${variable_type};" >> "$output_file_outputs"
fi
done < "$input_file"
if [ $noInputsFoundInTheHwConfig -eq 1 ]; then
echo " noInputsFoundInTheHwConfig AT %B0: BYTE;" >> "$output_file_inputs"
fi
if [ $noOutputsFoundInTheHwConfig -eq 1 ]; then
echo " noOutputsFoundInTheHwConfig AT %B0: BYTE;" >> "$output_file_outputs"
fi
echo " END_STRUCT;" >> "$output_file_inputs"
echo " END_STRUCT;" >> "$output_file_outputs"
echo " END_TYPE" >> "$output_file_inputs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public Task AddControlledUnit( [Option('x',Description = "Simatic-ax project fo
{
entryCallShift = entryCallShift + " ";
}
lines.Add(entryCallShift + CuName + ".Run(THIS, Inputs ^, Outputs ^, REF(Glob));");
lines.Add(entryCallShift + CuName + ".Run(THIS, REF(Glob));");
}
}
}
Expand Down

0 comments on commit 1affa91

Please sign in to comment.