2020-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121-- SOFTWARE.
2222
23- --- @diagnostic disable : undefined-global , redundant-parameter , missing-parameter
23+ -- luacheck: no max line length
2424
25- --
26- -- CreationTemplateVersion: 3.6.0
2725-- **************************************************************************
2826-- **********************Start Global Scope *********************************
2927-- **************************************************************************
30-
31- -- If app property "LuaLoadAllEngineAPI" is FALSE, use this to load and check for required APIs
28+ -- If App property "LuaLoadAllEngineAPI" is FALSE, use this to load and check for required APIs
3229-- This can improve performance of garbage collection
30+ _G .availableAPIs = require (' Communication/MultiIOLinkSMI/helper/checkAPIs' ) -- can be used to adjust function scope of the module related on available APIs of the device
3331
34- -- _G.availableAPIs = require('Communication/MultiIOLinkSMI/helper/checkAPIs') -- can be used to adjust function scope of the module related on available APIs of the device
3532---- -------------------------------------------------------
3633-- Logger
3734_G .logger = Log .SharedLogger .create (' ModuleLogger' )
3835_G .logHandle = Log .Handler .create ()
3936_G .logHandle :attachToSharedLogger (' ModuleLogger' )
40- _G .logHandle :setConsoleSinkEnabled (false ) -- > Set to TRUE if CSK_Logger is not used
37+ _G .logHandle :setConsoleSinkEnabled (false ) -- > Set to TRUE if LoggingModule is not used
4138_G .logHandle :setLevel (" ALL" )
4239_G .logHandle :applyConfig ()
4340---- -------------------------------------------------------
@@ -47,64 +44,81 @@ _G.logHandle:applyConfig()
4744local multiIOLinkSMI_Model = require (' Communication/MultiIOLinkSMI/MultiIOLinkSMI_Model' )
4845
4946local multiIOLinkSMI_Instances = {} -- Handle all instances
50- table.insert (multiIOLinkSMI_Instances , multiIOLinkSMI_Model .create (1 )) -- Create at least 1 instance
5147
5248-- Load script to communicate with the MultiIOLinkSMI_Model UI
5349-- Check / edit this script to see/edit functions which communicate with the UI
5450local multiIOLinkSMIController = require (' Communication/MultiIOLinkSMI/MultiIOLinkSMI_Controller' )
55- multiIOLinkSMIController .setMultiIOLinkSMI_Instances_Handle (multiIOLinkSMI_Instances ) -- share handle of instances
51+
52+ if _G .availableAPIs .ioLinkSmi and Engine .getEnumValues (' IOLinkMasterPorts' ) ~= nil then
53+ _G .logger :info (" IOLinkSMI API Support = true" )
54+ table.insert (multiIOLinkSMI_Instances , multiIOLinkSMI_Model .create (1 ))
55+ multiIOLinkSMIController .setMultiIOLinkSMI_Instances_Handle (multiIOLinkSMI_Instances ) -- share handle of instances
56+ else
57+ _G .logger :warning (" CSK_MultiIOLinkSMI: Features of this module are not supported on this device. Missing APIs." )
58+ end
5659
5760-- **************************************************************************
5861-- **********************End Global Scope ***********************************
5962-- **************************************************************************
6063-- **********************Start Function Scope *******************************
6164-- **************************************************************************
6265
63- --[[
64- --- Function to show how this module could be used
65- local function startProcessing()
66-
67- CSK_MultiIOLinkSMI.setSelectedInstance(1) --> select instance of module
68- CSK_MultiIOLinkSMI.doSomething() --> preparation
69-
70- -- Option A --> prepare an event to trigger processing via this one
71- --Script.serveEvent("CSK_MultiIOLinkSMI.OnNewTestEvent", "MultiIOLinkSMI_OnNewTestEvent") --> Create event to listen to and process forwarded object
72- --CSK_MultiIOLinkSMI.setRegisterEvent('CSK_MultiIOLinkSMI.OnNewTestEvent') --> Register processing to the event
73-
74- --Script.notifyEvent('OnNewTestEvent', data)
75-
76- -- Option B --> trigger processing via function call
77- local result = CSK_MultiIOLinkSMI.processSomething(data)
78-
79- end
80- end
81-
82- -- Call processing function after persistent data was loaded
83- --Script.register("CSK_MultiIOLinkSMI.OnDataLoadedOnReboot", startProcessing)
84- ]]
85-
86- -- OR
87-
88- --- Function to react on startup event of the app
8966local function main ()
9067
91- multiIOLinkSMIController .setMultiIOLinkSMI_Model_Handle (multiIOLinkSMI_Model ) -- share handle of Model
92-
93- ---- ------------------------------------------------------------------------------------
68+ if _G .availableAPIs .ioLinkSmi then
69+ multiIOLinkSMIController .setMultiIOLinkSMI_Model_Handle (multiIOLinkSMI_Model ) -- share handle of model
70+ CSK_MultiIOLinkSMI .setSelectedInstance (1 )
71+ CSK_MultiIOLinkSMI .pageCalled ()
72+ end
73+ ---- ------------------------------------------------------------------------------------
9474 -- INFO: Please check if module will eventually load inital configuration triggered via
9575 -- event CSK_PersistentData.OnInitialDataLoaded
96- -- (see internal variable _G.multiIOLinkSMI_Model .parameterLoadOnReboot)
76+ -- (see internal variable _G.deepLearningObjects .parameterLoadOnReboot)
9777 -- If so, the app will trigger the "OnDataLoadedOnReboot" event if ready after loading parameters
9878 --
9979 -- Can be used e.g. like this
80+ --
81+ --[[
82+ CSK_MultiIOLinkSMI.setSelectedInstance(1)
83+ CSK_MultiIOLinkSMI.setPort('S1')
84+ CSK_MultiIOLinkSMI.activateInstance(true)
85+ -- Optionally register to 'OnNewPortEvent'-event
86+
87+ local deviceIdentification = CSK_MultiIOLinkSMI.getDeviceIdentification('S1')
88+ CSK_MultiIOLinkSMI.applyNewDeviceIdentification(deviceIdentification)
89+ -- Optionally register to 'CSK_MultiIOLinkSMI.OnNewDeviceIdentificationApplied'-event
90+
91+ -- Read message handling
92+ CSK_MultiIOLinkSMI.createIODDReadMessage()
93+ CSK_MultiIOLinkSMI.setIODDReadMessageName('readMessageTitle')
94+ CSK_MultiIOLinkSMI.setSelectedIODDReadMessage('readMessageTitle')
95+ -- Register to "CSK_MultiIOLinkSMI.readMessage[port][readMessageTitle]"-event
96+
97+ -- Write message handling
98+ CSK_MultiIOLinkSMI.createIODDWriteMessage()
99+ CSK_MultiIOLinkSMI.setIODDWriteMessageName('writeMessageTitle')
100+ CSK_MultiIOLinkSMI.setSelectedIODDWriteMessage('writeMessageTitle')
101+ -- Register to "CSK_MultiIOLinkSMI.writeMessage[port][writeMessageName]"-event
102+
103+ -- Direct data reading
104+ local readProcessDataSuccess, readProcessDataResult = CSK_MultiIOLinkSMI.readProcessData()
105+ local readParameterSuccess, readParameterResult = CSK_MultiIOLinkSMI.readParameter(index, subindex)
106+ local resultProcessByteArray = CSK_MultiIOLinkSMI.readProcessDataByteArray()
107+ local resultParameterByteArray = CSK_MultiIOLinkSMI.readParameterByteArray(index, subindex)
108+ local success1, jsonReceivedData = CSK_MultiIOLinkSMI.readIODDMessage('messageName') -- after defining a read message in UI or IODD module
109+
110+ -- Direct data writing
111+ local writeSuccess = CSK_MultiIOLinkSMI.writeProcessData(jsonDataToWrite)
112+ local success2, errorDescription1 = CSK_MultiIOLinkSMI.writeParameter(index, subindex, byteArrayToWrite)
113+ local success3, errorDescription2 = CSK_MultiIOLinkSMI.writeProcessDataByteArray(byteArrayToWrite)
114+ local success4, errorDescription3 = CSK_MultiIOLinkSMI.writeParameterByteArray(index, subindey, byteArrayToWrite)
115+ local success5 = CSK_MultiIOLinkSMI.writeIODDMessage(messageName, jsonDataToWrite) -- after defining a write message in UI or IODD module
116+ ]]
100117 ---- ------------------------------------------------------------------------------------
101118
102- -- startProcessing() --> see above
103- CSK_MultiIOLinkSMI .pageCalled () -- Update UI
104-
105119end
106120Script .register (" Engine.OnStarted" , main )
107121
108122-- **************************************************************************
109123-- **********************End Function Scope *********************************
110- -- **************************************************************************
124+ -- **************************************************************************
0 commit comments