Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated declaration of the Controlled Unit added #20

13 changes: 9 additions & 4 deletions axopen.template.simple/ax/apax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variables:
APAX_BUILD_ARGS: [ -d ]
PLC_NAME: "plc_line"
HWCONFIG: "TIA"
AXTARGET: 192.168.0.4
AXTARGET: 10.222.6.1
AXTARGETPLATFORMINPUT: .\bin\1500\
AX_USERNAME: "adm"
AX_TARGET_PWD: "123ABCDabcd$#!"
Expand Down Expand Up @@ -119,6 +119,11 @@ scripts:
# Remove temporary template
dotnet new uninstall ./tmp_templates
rm ./tmp_templates -r
AxProjDir=${PWD}
CuDec="axosimple.Context"
PdDec="axosimple.ProcessData"
TdDec="axosimple.TechnologyData"
dotnet run --project ..\\tools\\AXOpen.Simple.Tools\\AXOpen.Simple.Tools\\AXOpen.Simple.Tools.csproj -- cuadd -x $AxProjDir -n $unitname -d $CuDec -p $PdDec -t $TdDec
delete-unit: |
if [ -z "$1" ]; then
# If no argument, prompt for unitname input
Expand Down Expand Up @@ -149,18 +154,18 @@ scripts:
apax sld load --accept-security-disclaimer -t $AXTARGET -i $AXTARGETPLATFORMINPUT -r -C ./certs/$PLC_NAME/$PLC_NAME.cer
fi
if [[ "$HWCONFIG" == "TIA" ]]; then
apax sld load --accept-security-disclaimer -t $AXTARGET -i $AXTARGETPLATFORMINPUT -r -C $COM_CERT_PATH --password $AX_TARGET_PWD --username $AX_USERNAME
apax sld load --accept-security-disclaimer -t $AXTARGET -i $AXTARGETPLATFORMINPUT -r -C $COM_CERT_PATH --password $AX_TARGET_PWD --username $AX_USERNAME
fi
if [[ "$HWCONFIG" == "TIA-NON-SECURE" ]]; then
apax sld load --accept-security-disclaimer -t $AXTARGET -i $AXTARGETPLATFORMINPUT -r
fi
delta: |
apax build --ignore-scripts
if [[ "$HWCONFIG" == "HWC" ]]; then
apax sld load --accept-security-disclaimer -t $AXTARGET -i $AXTARGETPLATFORMINPUT -C ./certs/$PLC_NAME/$PLC_NAME.cer --mode delta
apax sld load --accept-security-disclaimer -t $AXTARGET -i $AXTARGETPLATFORMINPUT -C ./certs/$PLC_NAME/$PLC_NAME.cer --mode delta
fi
if [[ "$HWCONFIG" == "TIA" ]]; then
apax sld load --accept-security-disclaimer -t $AXTARGET -i $AXTARGETPLATFORMINPUT -C $COM_CERT_PATH --mode delta
apax sld load --accept-security-disclaimer -t $AXTARGET -i $AXTARGETPLATFORMINPUT -C $COM_CERT_PATH --password $AX_TARGET_PWD --username $AX_USERNAME --mode delta
fi
if [[ "$HWCONFIG" == "TIA-NON-SECURE" ]]; then
apax sld load --accept-security-disclaimer -t $AXTARGET -i $AXTARGETPLATFORMINPUT --mode delta
Expand Down
26 changes: 26 additions & 0 deletions axopen.template.simple/ax/certs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Certificate Replacement Guide

## Overview

This project includes a **placeholder certificate** located at:

```
./ax/certs/Communication.cer
```

This certificate is **not valid** and is provided only for development and testing purposes.
Before deploying the project, you **must replace** this placeholder certificate with a valid one obtained using the **TIA Portal**.


### 1. Replace the Placeholder Certificate

After obtaining the valid certificate from TIA Portal:

1. Navigate to the following directory in your project:

```
./ax/certs/
```

2. Replace the file named `Communication.cer` with the newly exported certificate.
- **Ensure** the file name remains `Communication.cer`. If you change the file name, update any configurations or scripts referencing the certificate.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ NAMESPACE axosimple
{#ix-generic:TPlain as POCO}
{#ix-attr:[AXOpen.Data.AxoDataEntityAttribute]}
{#ix-attr:[Container(Layout.Stack)]}
{#ix-set:AttributeName = "<#UnitTemplate#>"}
Payload : SharedDataPayload;
END_VAR
END_CLASS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ NAMESPACE axosimple
{#ix-generic:TPlain as POCO}
{#ix-attr:[AXOpen.Data.AxoDataEntityAttribute]}
{#ix-attr:[Container(Layout.Stack)]}
{#ix-set:AttributeName = "<#UnitTemplate#>"}
Payload : TechnologySharedDataPayload;
END_VAR
END_CLASS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public SharedDataExchange(AXSharp.Connector.ITwinObject parent, string readableT
{
Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail);
PreConstruct(parent, readableTail, symbolTail);
Payload = new axosimple.SharedDataPayload(this, "Payload", "Payload");
Payload = new axosimple.SharedDataPayload(this, "<#UnitTemplate#>", "Payload");
Payload.AttributeName = "<#UnitTemplate#>";
PostConstruct(parent, readableTail, symbolTail);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public TechnologySharedDataExchange(AXSharp.Connector.ITwinObject parent, string
{
Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail);
PreConstruct(parent, readableTail, symbolTail);
Payload = new axosimple.TechnologySharedDataPayload(this, "Payload", "Payload");
Payload = new axosimple.TechnologySharedDataPayload(this, "<#UnitTemplate#>", "Payload");
Payload.AttributeName = "<#UnitTemplate#>";
PostConstruct(parent, readableTail, symbolTail);
}

Expand Down
2 changes: 1 addition & 1 deletion axopen.template.simple/axpansion/twin/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ConnectionConfig

public class TwinConnectorSelector
{
public static string TargetIp { get; } = Environment.GetEnvironmentVariable("AXTARGET"); // <- replace by your IP
public static string TargetIp { get; } = "10.222.6.1";//Environment.GetEnvironmentVariable("AXTARGET"); // <- replace by your IP
private static string Pass => @"123ABCDabcd$#!"; //Environment.GetEnvironmentVariable("AX_TARGET_PWD"); //Environment.GetEnvironmentVariable("AX_TARGET_PWD"); // <- Pass in the password that you have set up for the user. NOT AS PLAIN TEXT! Use user secrets instead.
private static string UserName = "adm"; //Environment.GetEnvironmentVariable("AX_USERNAME"); //<- replace by user name you have set up in your WebAPI settings
private const bool IgnoreSslErrors = true; // <- When you have your certificates in order set this to false.
Expand Down
40 changes: 37 additions & 3 deletions axopen.template.simple/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,43 @@ dotnet tool restore
Set-Location ax
apax install
apax build
axcode .
axcode -g ..\README.md:0
Set-Location ..
Set-Location ..\tools\AXOpen.Simple.Tools\AXOpen.Simple.Tools\.apax
apax install
Set-Location ..\..\..\..\
axcode .\ax\
axcode -g README.md:0
#Set-Location ..

#Create an empty cert file

$filepath = ".\ax\certs\Communication.cer"
$placeholderDisclaimer = "This is a placeholder certificate file and must be replaced with a valid certificate before use."

# Check if the file exists
if (Test-Path $filepath) {
# Read the content of the file (optional, if needed to confirm it contains the placeholder)
$fileContent = Get-Content -Path $filepath

# Check if the file contains the placeholder disclaimer (or just check existence)
if ($fileContent -like "*placeholder*") {
Write-Host "`nIMPORTANT: The file 'Communication.cer' is a placeholder certificate." -ForegroundColor Yellow
Write-Host "You must replace this file with a valid certificate obtained from the TIA Portal." -ForegroundColor Yellow
Write-Host "Please follow the instructions in the README.md file to replace it before deployment.`n" -ForegroundColor Yellow

# Prompt the user for confirmation to continue
$input = Read-Host "Press Enter once you've understood this message and replaced the certificate, or when you're ready to proceed"
} else {
Write-Host "The certificate file 'Communication.cer' has been updated." -ForegroundColor Green
}
} else {
Write-Host "Certificate file 'Communication.cer' not found." -ForegroundColor Red
Write-Host "Please ensure you have the correct file in the './ax/certs/' directory." -ForegroundColor Red

# Wait for user input before continuing
$input = Read-Host "Press Enter to continue after verifying the certificate"
}


dotnet clean this.proj
dotnet build this.proj
dotnet slngen this.proj -o axosimple.sln --folders true --launch false
Expand Down
Loading