beautypg.com

Echelon i.LON SmartServer 2.0 User Manual

Page 401

background image

i.LON SmartServer 2.0 Programmer’s Reference

21-49

End

If

' -------------- CREATING DISCOVERED LONWORKS DEVICES--------------

'Create a new LON_Device_Cfg Item and add it to ItemCfgColl

Dim

my_LON_Device

As

New

iLON_SmartServer.LON_Device_Cfg()

itemCfgColl.Item(i - 1) = my_LON_Device

'subtract 1 for the metaData item in Data Logger

'parse Neuron ID and Program ID from Data Logger

Dim

NID_PID

As

[String] = dataLoggerData.UCPTvalue(0).Value

Dim

NID

As

[String] = NID_PID.Substring(0, 12)

Console.WriteLine(

"Neuron ID = "

& NID)

Dim

PID

As

[String] = NID_PID.Substring(13, 16)

Console.WriteLine(

"Program ID = "

& PID)


'set Neuron ID, which is a byte[]

my_LON_Device.UCPTuniqueId = (HexStringToArray(NID))

'set Program ID, which is a byte[]

my_LON_Device.UCPTprogramId = (HexStringToArray(PID))

'set template

Dim

xSelect

As

New

iLON_SmartServer.E_xSelect()

xSelect.xSelect =

"//Item[@xsi:type=""TemplateManager_Cfg""]

[UCPTfileType=""TEMPLATE_OR_XIF""]

[UCPTprogramId="""

& PID &

"""]"

itemColl = SmartServer._iLON.List(xSelect)

Dim

template

As

iLON_SmartServer.TemplateManager_Surrogate_Cfg =

DirectCast

(itemColl.Item(0), iLON_SmartServer.TemplateManager_Surrogate_Cfg)

Dim

templateName

As

[String] = template.UCPTname

Console.WriteLine(

"Device Template = "

& templateName)

my_LON_Device.UCPTurlTemplate = templateName

'set the device name

'1. get the name of the channel ("Net/LON")

xSelect.xSelect =

"//Item[@xsi:type=""LON_Channel_Cfg""][UCPThidden=0]"

itemColl = SmartServer._iLON.List(xSelect)

Dim

channel

As

iLON_SmartServer.Item = itemColl.Item(0)


'2. get the name of the xif

Dim

separator

As

String

() =

New

String

() {

"/"

}

Dim

templateName_justxif

As

[String]() = templateName.Split(separator, 0)

Dim

templateNameLength

As

Integer

= templateName_justxif.Length

Dim

xifName

As

[String] = templateName_justxif(templateNameLength - 1)

Console.WriteLine(

"XIF Name = "

& xifName)


'3. name device using channel name, /device [index], and xif name ("Net/LON/Device 1 (ai-10v3.xif)")

Dim

deviceName

As

[String] = ((channel.UCPTname &

"/"

&

"Device "

) & i &

" ("

) &

xifName

&

")"

Console.WriteLine(

"Device Name = "

& deviceName)

Console.WriteLine(

"========================================================"

)

my_LON_Device.UCPTname = deviceName

'set Commission status

Dim

commissionStatus_LonString

As

New

iLON_SmartServer.E_LonString()

commissionStatus_LonString.Value =

"COMMISSIONED"

my_LON_Device.UCPTcommissionStatus = commissionStatus_LonString

'set Application status

Dim

applicationStatus_LonString

As

New

iLON_SmartServer.E_LonString()

applicationStatus_LonString.Value =

"APP_RUNNING"

my_LON_Device.UCPTapplicationStatus = applicationStatus_LonString

'set tree and app icon; based on program ID

my_LON_Device.UCPTannotation = PID

'&&&&send device commands&&&&&&

'commission device

'create a command array to store device commands to be sent