2222
2323--- @diagnostic disable : undefined-global , redundant-parameter , missing-parameter
2424
25- --
2625-- CreationTemplateVersion: 3.6.0
2726-- **************************************************************************
2827-- **********************Start Global Scope *********************************
2928-- **************************************************************************
3029
3130-- If app property "LuaLoadAllEngineAPI" is FALSE, use this to load and check for required APIs
3231-- This can improve performance of garbage collection
33-
34- -- _G.availableAPIs = require('Communication/MultiSerialCom/helper/checkAPIs') -- can be used to adjust function scope of the module related on available APIs of the device
32+ _G .availableAPIs = require (' Communication/MultiSerialCom/helper/checkAPIs' ) -- can be used to adjust function scope of the module related on available APIs of the device
3533---- -------------------------------------------------------
3634-- Logger
3735_G .logger = Log .SharedLogger .create (' ModuleLogger' )
@@ -47,44 +45,25 @@ _G.logHandle:applyConfig()
4745local multiSerialCom_Model = require (' Communication/MultiSerialCom/MultiSerialCom_Model' )
4846
4947local multiSerialCom_Instances = {} -- Handle all instances
50- table.insert (multiSerialCom_Instances , multiSerialCom_Model .create (1 )) -- Create at least 1 instance
5148
5249-- Load script to communicate with the MultiSerialCom_Model UI
5350-- Check / edit this script to see/edit functions which communicate with the UI
5451local multiSerialComController = require (' Communication/MultiSerialCom/MultiSerialCom_Controller' )
55- multiSerialComController .setMultiSerialCom_Instances_Handle (multiSerialCom_Instances ) -- share handle of instances
52+
53+ -- Check if specific APIs are available on device
54+ if availableAPIs .specific then
55+ table.insert (multiSerialCom_Instances , multiSerialCom_Model .create (1 )) -- Create at least 1 instance
56+ multiSerialComController .setMultiSerialCom_Instances_Handle (multiSerialCom_Instances ) -- share handle of instances
57+ else
58+ _G .logger :warning (" CSK_SerialCom : Features of this module are not supported on this device. Missing APIs/interfaces." )
59+ end
5660
5761-- **************************************************************************
5862-- **********************End Global Scope ***********************************
5963-- **************************************************************************
6064-- **********************Start Function Scope *******************************
6165-- **************************************************************************
6266
63- --[[
64- --- Function to show how this module could be used
65- local function startProcessing()
66-
67- CSK_MultiSerialCom.setSelectedInstance(1) --> select instance of module
68- CSK_MultiSerialCom.doSomething() --> preparation
69-
70- -- Option A --> prepare an event to trigger processing via this one
71- --Script.serveEvent("CSK_MultiSerialCom.OnNewTestEvent", "MultiSerialCom_OnNewTestEvent") --> Create event to listen to and process forwarded object
72- --CSK_MultiSerialCom.setRegisterEvent('CSK_MultiSerialCom.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_MultiSerialCom.processSomething(data)
78-
79- end
80- end
81-
82- -- Call processing function after persistent data was loaded
83- --Script.register("CSK_MultiSerialCom.OnDataLoadedOnReboot", startProcessing)
84- ]]
85-
86- -- OR
87-
8867--- Function to react on startup event of the app
8968local function main ()
9069
@@ -97,9 +76,31 @@ local function main()
9776 -- If so, the app will trigger the "OnDataLoadedOnReboot" event if ready after loading parameters
9877 --
9978 -- Can be used e.g. like this
79+ --
80+ --[[
81+ CSK_MultiSerialCom.setSelectedInstance(1)
82+ CSK_MultiSerialCom.setInterface('SER1')
83+ CSK_MultiSerialCom.setType('RS232')
84+ CSK_MultiSerialCom.setBaudrate(9600)
85+ CSK_MultiSerialCom.setParity('N')
86+ CSK_MultiSerialCom.setHandshake(false)
87+ CSK_MultiSerialCom.setDataBits(8)
88+ CSK_MultiSerialCom.setStopBits(1)
89+ CSK_MultiSerialCom.setTermination(false)
90+
91+ CSK_MultiSerialCom.setActive(true)
92+
93+ CSK_MultiSerialCom.transmitInstance1('Test') -- Send data on instance 1
94+ CSK_MultiSerialCom.receiveInstance1() -- Receive data on instance 1
95+
96+ --Register on event 'CSK_MultiSerialCom.OnNewData1' to get incoming data
97+ ]]
98+
10099 ---- ------------------------------------------------------------------------------------
101100
102- -- startProcessing() --> see above
101+ if availableAPIs .specific then
102+ CSK_MultiSerialCom .setSelectedInstance (1 )
103+ end
103104 CSK_MultiSerialCom .pageCalled () -- Update UI
104105
105106end
0 commit comments