今回の記事ではctrlX SDKを導入する方法を紹介します。ITでずっと仕事をなさった方なら楽だと思うかもしれませんが、自分がOT側の人間でこのあたりの知識は大変不足しています。これからも色々勉強してctrlXを楽しもうと思っています。
よろしくお願いします。
ctrlX SDK?
ctrlX SDKは、ctrlX AUTOMATIONデバイス、特にLinuxベースのctrlX COREデバイス用のソフトウェアアプリケーション(APPS)を開発するためのソフトウェア開発キットです。SDKを使用するより、様々な高級言語でAPPSを開発することが可能です。
ctrlXにGithubにはDevelop-Environmentのセットアップガイド、ライブラリ、ドキュメント、REST-APIの説明などさまざまなサンプルが含まれています。つまり、私達もAPPを簡単に作成することができます!
さ、自分がもってるソフトウェアやノウハウをctrlX AUTOMATIONのエコシステムと連携しアプリケーションの可能性を開きましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1020-1024x363.png)
Before..
ctrlX AUTOMATION SDKを使用してctrlX COREアプリケーションを開発するには、Ubuntu 20.04 Linuxオペレーティングシステムに特別なソフトウェアパッケージをインストールし、そしてApp Build Environmentが必要です。
こちらはSDK やApp Build Environmentに関するドキュメントです。
Prerequisites
- ctrlX WORKS >= 1.20 なおかつ function ‘App Build Environment’ が同時インストールされたPC
- インタネット接続
Reference Link
Build
ctrlX WORKSを起動し、App Build Environmentsをクリックします。
![](http://soup01.com/wp-content/uploads/2023/05/image-1021.png)
+ボタンでctrlX CORE App Build Environment を追加します。
![](http://soup01.com/wp-content/uploads/2023/05/image-1022-1024x377.png)
App Build Environmentの名前を入れて、OKで進みます。
![](http://soup01.com/wp-content/uploads/2023/05/image-1023.png)
App Build Environmentが自動的にServerからImagesをDownloadし環境を構築し始めます。
![](http://soup01.com/wp-content/uploads/2023/05/image-1024-1024x304.png)
!のマークをクリックすると大体15分で終わります(自分は10分くらいで完了した)。
![](http://soup01.com/wp-content/uploads/2023/05/image-1025-1024x504.png)
PCにも実際Terminalが起動され、いまのインストール進捗状況を確認できます。
![](http://soup01.com/wp-content/uploads/2023/05/image-1026-1024x533.png)
Done!
![](http://soup01.com/wp-content/uploads/2023/05/image-1027-1024x541.png)
Start The build app
Stateは空でなにもマークが表示されてない状態になるはずです。
![](http://soup01.com/wp-content/uploads/2023/05/image-1028-1024x320.png)
StartボタンでApp Build Environmentを起動します。
![](http://soup01.com/wp-content/uploads/2023/05/image-1029-1024x519.png)
Setup VSCODE
ctrlX AUTOMATION SDK公式ドキュメントでは統合開発環境(IDE)としてVisual Studio Codeを使用することをお勧めしてるようです。Visual Studio Codeの拡張機能を使ってctrlXアプリケーションの開発に必要なすべての機能を利用したり、SSHでLoginしたりの感じです。
こちらの記事はWindows上でWSLとVSCodeの開発環境構築がメインですが、VSCode部分は共通なので参考にしてください。簡単に言いますと、SSH 拡張機能をインストールさえインストールさえすれば今回の記事では問題ありません。
(もちろんVSCODEはMustではないので)
![](http://soup01.com/wp-content/uploads/2023/05/image-1030.png)
Reference Link
Connnet
SSH欄からApp Build EnvironmentのSSH Login アドレスを確認できます。注意するのはctrlX App Build EnvironmentのSSH Login Portは10022です。
![](http://soup01.com/wp-content/uploads/2023/05/image-1031.png)
VSCodeからRemoteを選び>SSH のところから新しいRemote Serverを追加します。
![](http://soup01.com/wp-content/uploads/2023/05/image-1032.png)
SSH Server名を設定します。
![](http://soup01.com/wp-content/uploads/2023/05/image-1033.png)
boschrexroth@127.0.0.1:10022を入力します。
![](http://soup01.com/wp-content/uploads/2023/05/image-1034.png)
Passwordはboschrexrothです。
![](http://soup01.com/wp-content/uploads/2023/05/image-1035.png)
Configを選びます。とりあえず1つ目で行きましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1036-1024x266.png)
接続すると、VSCodeの右下にSSH:127.0.0.1:10022が表示されます。
![](http://soup01.com/wp-content/uploads/2023/05/image-1037.png)
Host key verification failed
SSH Loginするときにverification failedのエラーが発生したときの対処法を紹介します。
—————– [08:13:22.971] > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ [08:13:22.986] > @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ > IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! > Someone could be eavesdropping on you right now (man-in-the-middle attack)! > It is also possible that a host key has just been changed. > The fingerprint for the ECDSA key sent by the remote host is > SHA256:FXXOSTwCswLlQ25/xTW2BqAhrhA0CoA/7/B5Ap+7YOo. > Please contact your system administrator. > Add correct host key in C:\\Users\\root/.ssh/known_hosts to get rid of this mess > age. > Offending ECDSA key in C:\\Users\\root/.ssh/known_hosts:1 > ECDSA host key for [127.0.0.1]:10022 has changed and you have requested strict c > hecking. > Host key verification failed. > The process tried to write to a nonexistent pipe. > [08:13:24.277] “install” terminal command done [08:13:24.278] Install terminal quit with output: Host key verification failed. [08:13:24.279] Received install output: Host key verification failed. [08:13:24.280] Failed to parse remote port from server output [08:13:24.282] Resolver error: Error: at m.Create (c:\Users\root\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:584145) at t.handleInstallOutput (c:\Users\root\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:582705) at t.tryInstall (c:\Users\root\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:681881) at async c:\Users\root\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:644110 at async t.withShowDetailsEvent (c:\Users\root\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:647428) at async t.resolve (c:\Users\root\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:645160) at async c:\Users\root\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:720916 [08:13:24.297] —— ——————— |
Host PCの下記Pathに行ってください。
C:\Users\root\.ssh |
known_hostsをNodpadなどのEditorを開いてください。
![](http://soup01.com/wp-content/uploads/2023/05/image-1038.png)
中にLoginできないKeyを削除してください。
![](http://soup01.com/wp-content/uploads/2023/05/image-1039.png)
Reference Link
https://note.affi-sapo-sv.com/ssh-verification-failed.php
https://www.codelab.jp/blog/?p=3240
Download the Example
次はSDKのSamplesをDownloadしApp Build Environmentを構築します。
https://github.com/boschrexroth/ctrlx-automation-sdk
ctrlXはPythonだけではなくGO/Node/cppなど様々高級言語のSampleも用意してくれます。
![](http://soup01.com/wp-content/uploads/2023/05/image-1040.png)
Code>Downlaod ZipでExampleをDownloadしましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1041.png)
もう1つのVSCODEを起動し、File>Open Folderします。
![](http://soup01.com/wp-content/uploads/2023/05/image-1042.png)
先程GithubでDownlaodしたZipを解凍し、Open FolderでVSCodeから開きましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1043-1024x517.png)
このように左と右でApp Build EnvironmentとLocalを同時に開いてる状態のほうが作業しやすいです。
![](http://soup01.com/wp-content/uploads/2023/05/image-1044-1024x335.png)
Move to your APP Build
今回記事では使用するExampleはdatalayer.client.lightで、FolderをそのままApp Build EnvironmentにLoginされたVSCODE側にひっばりって行きましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1045-1024x603.png)
Yes, I trust the authorsをクリックし進みます。
![](http://soup01.com/wp-content/uploads/2023/05/image-1046.png)
Copy FolderですべてのFileを移動します。
![](http://soup01.com/wp-content/uploads/2023/05/image-1047.png)
Done!
![](http://soup01.com/wp-content/uploads/2023/05/image-1048.png)
Necessary Script
注意するのはApp Build Environmentの/home/boschrexroth/scripts/ディレクトリには、APPを作成するには大事なスクリプトのセットが含まれています。
そして/home/boschrexroth/scripts/README.mdに、すべてのファイルがリストアップされ説明されています。
ctrlX AUTOMATION SDKの他に、ctrlx-datalayer debianパッケージ、snapcraft、クロスビルド用ライブラリがインストールされています。
ではinstall-sdk.shからctrlx-datalayer debianパッケージ、snapcraft、クロスビルド用ライブラリなどをインストールしましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1049.png)
こちらのコマンドでSource Listを更新> install-sdk.shを実行できるように権限変更>最後はShell Script install-sdk.shを実行します。大体5分くらいかかります。
boschrexroth@app-builder-amd64:~$ sudo apt-get update boschrexroth@app-builder-amd64:~$ chmod +x install-sdk.sh boschrexroth@app-builder-amd64:~$ /.install-sdk.sh |
Shell Scriptが実行されたあとApp Build Environmentに様々なPackagesがインストールされました。例えばvirtualenv:
boschrexroth@app-builder-amd64:~$ pip3 install virtualenv Requirement already satisfied: virtualenv in /usr/lib/python3/dist–packages (20.0.17) |
pipとか。
boschrexroth@app-builder-amd64:~$ pip3 –version pip 20.0.2 from /usr/lib/python3/dist–packages/pip (python 3.8) |
Test with Example!
では実際ctrlX GithubからDownloadしたExampleを導入しましょう。
各Exampleにもinstall-venv.shというShell Scriptが入っています。
![](http://soup01.com/wp-content/uploads/2023/05/image-1050.png)
中にPythonの仮想環境作成>そして仮想環境を有効>最後はrequirements.txtに記述されたLibraryをPip コマンドでInstallします。
![](http://soup01.com/wp-content/uploads/2023/05/image-1051.png)
Shell Scriptを実行してください。
boschrexroth@app-builder-amd64:~$ chmod +x install-venv.sh boschrexroth@app-builder-amd64:~$ ./install-venv.sh |
次はmain.pyを実行してみましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1052.png)
もしエラーが発生した場合はCtrlx Virtual CoreなどのRuntimeが起動したかをCheckしてくださいね。
boschrexroth@app-builder-amd64:~$ source datalayer.client.light/venv/bin/activate (venv) boschrexroth@app-builder-amd64:~$ python datalayer.client.light/main.py System architecture: x86_64 ================================================================= sdk-py-datalayer-client – A ctrlX Data Layer Client App in Python ================================================================= ERROR Connecting tcp://boschrexroth:boschrexroth@10.0.2.2?sslport=8443 failed. |
ctrlX RuntimeのWeb ServerにアクセスしSettingsを開きます。
![](http://soup01.com/wp-content/uploads/2023/05/image-1053.png)
Data Layer を開きます。
![](http://soup01.com/wp-content/uploads/2023/05/image-1054.png)
Data Layerのツリーが表示されました。
![](http://soup01.com/wp-content/uploads/2023/05/image-1055.png)
このExampleが読み込まれるSubscriptionの設定とCPUの使用状態ですが、Subscription設定はこのように確認できます。
![](http://soup01.com/wp-content/uploads/2023/05/image-1056.png)
Reference Link
PIPをインストールする手順:
https://linuxize.com/post/how-to-install-pip-on-ubuntu-20.04/
Virtualenvの使用方法:
Modify your apps
次はPython Scriptを少し修正します。ctrlX PLC Engineeringを起動し、GVLの中に整数を定義し周期で加算します。
![](http://soup01.com/wp-content/uploads/2023/05/image-1057.png)
その変数をDataLayer_RealtimeのOutputとして追加しましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1058.png)
Web Serverからひとまず確認しましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1059.png)
PLC RuntimeのCounter変数のアクセスPathを複製します。
![](http://soup01.com/wp-content/uploads/2023/05/image-1060.png)
ExampleのPythonScriptにLine80ではSubscribeするTopicを設定しています。
先程CopyしたアクセスPathに変更しましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1061-1024x429.png)
Done!Counter値がDataLayer_Realtime経由で取得できました。
![](http://soup01.com/wp-content/uploads/2023/05/image-1062.png)
Build to Snap
最後はPython scriptをSnapにビルドししctrlX RuntimeにInstallしてみます。
アプリケーションを作成したFolderまでcdコマンドで移動してください。
その中に.build-snap-amd64.shのShell Scriptが入っています。
![](http://soup01.com/wp-content/uploads/2023/05/image-1063.png)
build-snap-amd64.shを実行できるように変更し、そのShell Scriptを実行しましょう。
boschrexroth@app-builder-amd64:~$ chmod +x build-snap-amd64.sh boschrexroth@app-builder-amd64:~$ /.build-snap-amd64.sh |
ヒルドされたsnapを右クリックし>DownloadでLocal PCにDownloadします。
![](http://soup01.com/wp-content/uploads/2023/05/image-1064.png)
ctrlX VirtualcoreのWebServerにアクセスし、Install an appでAppをインストールします。
![](http://soup01.com/wp-content/uploads/2023/05/image-1065.png)
Intall from fileをクリックします。
![](http://soup01.com/wp-content/uploads/2023/05/image-1066.png)
先程Downloadしたsnapを選び>Openします
![](http://soup01.com/wp-content/uploads/2023/05/image-1067-1024x470.png)
少々お待ち下さい…
![](http://soup01.com/wp-content/uploads/2023/05/image-1068.png)
Installで進みます。
![](http://soup01.com/wp-content/uploads/2023/05/image-1069.png)
また少々お待ち下さい…
![](http://soup01.com/wp-content/uploads/2023/05/image-1070.png)
Done!
![](http://soup01.com/wp-content/uploads/2023/05/image-1071.png)
Appsがインストールされました!このExampleは本来ConsoleでずっとDataLayer_Realtime経由で読み込まれた変数を表示するだけなので、実用性はありませんが、これからSDKを使用し自分のAPP を作っていきたいと思います!
![](http://soup01.com/wp-content/uploads/2023/05/image-1072.png)
Stop the App Build Environment
最後はApp Build EnvironmentをStopしましょう。
![](http://soup01.com/wp-content/uploads/2023/05/image-1073.png)
実際その環境をStopするにもPasswordが必要です。
Default Passwordはboschrexrothです。
![](http://soup01.com/wp-content/uploads/2023/05/image-1074.png)
コメント
nice