Echelon LNS User Manual

Page 329

Advertising
background image

LNS Programmer's Guide

315

Dim fileBuffer as Variant

Dim byte1 as Byte

fileBuffer = MyFileTransfer.ReadFile()

byte1 = fileBuffer(1)

The ReadFile() method returns an array of bytes of the length transferred.

Your application should query the returned Variant to determine the number of

available bytes, which could be as little as 0 if an error occurred.

To write a file to a device or group of devices, follow these steps:

1. Obtain

a

FileTransfer object from the System object's FileTransfer

property.

Dim MyFileTransfer as LcaFileTransfer

Set MyFileTransfer = System.FileTransfer

2. Set the properties of the object to specify the characteristics of the file transfer

session. Random access will be used in the file transfer if the StartPosition

property is set to a non-zero value. This requires that the device you are writing

to supports random access file transfer. Sequential file access will be used if the
StartPosition property is set to 0.

MyFileTransfer.RxTimeOut = 0

MyFileTransfer.TxTimeOut = 0

MyFileTransfer.StartPosition = 0

MyFileTransfer.FileIndex = 0

If you set the RxTimeOut and TxTimeOut properties to 0, LNS will calculate the

values for those properties automatically, based on the network topology and

channel delays on your network. See the LNS Object Server Reference Help file
for a complete list of the properties of the FileTransfer object.

3. Select the device you want to write the file to, and call the AddTarget() method.

Pass in the device containing the file as the appDeviceObject element

MyFileTransfer.AddTarget(appDeviceReceivingFile)

4. Write the file to the device.

MyFileTransfer.WriteFile(fileBuffer)

NOTE: You can use this procedure to write a file buffer to more than one application

device at a time, by repeating step 3 for each device to be written to. The file index
written to, and the file buffer to write, must be the same for all target devices. In order to

write to more than one application device at a time, an output network variable of type
SNVT_file_req on the LNS Server’s Network Service Device must be bound to the file

request input network variable on each of the target devices for the file transfer. In

addition, an input network variable of type

SNVT_file_status

on the LNS Server’s

Network Service Device must be bound to the file status output network variable on each
of the target devices. If random access is used for the file transfer, then an input network
variable of type SNVT_file_pos on the NetworkServiceDevice object of the LNS Server

must be bound to the file position input NV on each of the targets. If necessary, you can

add these network variables to the Network Services Device with your LNS application.

See the Creating Dynamic Network Variables section for instructions on this.

You should also be aware that LNS does not support writing to the LonMark

configuration property template or value files using file transfer. The template file

Advertising