Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Tue Nov 21, 2017 3:56 pm

All times are UTC - 7 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Mon Jan 05, 2009 9:59 am 
Offline
User avatar

Joined: Fri Feb 01, 2008 4:50 pm
Posts: 101
I am trying to use FTPClientV2 to download files, but I am finding it ambiguous in terms of what the DownloadFile() function actually does. I ended up just looking at the code because the description gave no hints, and I am left just as clueless as before. Everything seems to get saved to the private variable dataBuff, but that is all I can figure out. Please help!

Thanks,

Ryan


Top
 Profile  
 
PostPosted: Mon Jan 05, 2009 10:14 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Ok, the help could be a little more descriptive.

The general idea is pretty simple though -- if you call FTPClient.DownloadFile() it downloads the file that you request from the server (this assumes you have previously established a connection from the FTPClient object to the FTP server). The file will be saved to the local file system.

Because the FTPClient object tries to save the file with EXACTLY the same name you requested, this does lead to one possible pitfall. The easiest solution is to change the Qlarity terminal's current directory (ChangeCurDir) to be the directory where you want the file saved. Next, you want to change the remote directory (FTPClient.ChangeDirectory) to be the one that contains the file you wish to download. Then you can finally call FTPClient.DownloadFile.

Here is an example
Code:
func click()
    changeCurDir("/sim:")
    ftpclient_1.ChangeDirectory("_PersistantVariables/WeatherStation")
    ftpclient_1.DownloadFile("WeatherStation.dat")
endfunc

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Mon Jan 05, 2009 10:24 am 
Offline
User avatar

Joined: Fri Feb 01, 2008 4:50 pm
Posts: 101
Thanks for the quick reply Jeremy.

I now have another question. To check the file system on the terminal I have been using a ftp server on the terminal and connecting to it with an ftp client (filezilla). Just now I connected and noticed all of the files that I had downloaded to the terminal, but which previously didn't show up even after reconnecting multiple times. I am doing this all in the simulator. Do you have any idea what I am doing wrong?


Top
 Profile  
 
PostPosted: Mon Jan 05, 2009 10:28 am 
Offline
User avatar

Joined: Fri Feb 01, 2008 4:50 pm
Posts: 101
Also, how can I tell when the download is finished? And is there any way to download the file to memory and get the array reference passed back rather than having it saved to the file system? I want to be able to download system upgrades, but the memory is larger than the file system so I feel like it might be better to upgrade from the memory rather than the file system.


Top
 Profile  
 
PostPosted: Mon Jan 05, 2009 10:46 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Quote:
I now have another question. To check the file system on the terminal I have been using a ftp server on the terminal and connecting to it with an ftp client (filezilla). Just now I connected and noticed all of the files that I had downloaded to the terminal, but which previously didn't show up even after reconnecting multiple times. I am doing this all in the simulator. Do you have any idea what I am doing wrong?


Not off hand. If ever in doubt, I would suggest the a command line FTP client or even the FileBrowserV2 object.
Quote:
Also, how can I tell when the download is finished? And is there any way to download the file to memory and get the array reference passed back rather than having it saved to the file system? I want to be able to download system upgrades, but the memory is larger than the file system so I feel like it might be better to upgrade from the memory rather than the file system.


Hrm, I haven't ever needed to do this -- usually we download system upgrades directly using TFTP by using SoftReset(RESET_LOADAPP). Instead of trying to manually pull upgrades using the FTP object. It is probably possible to modify the FTPClient object to store the result in an array instead of to the file system.

To do so, I would probably modify dataBuff to be public, or modify ParseDataBuff to somehow publish the data instead of writing it to a file. (This will probably require you to create a new template and "copy the code of an existing template in a library")

Finally the FileReceived event is triggered on file download complete. This event could be new to 2.60, seems like we recently added it.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Mon Jan 05, 2009 11:14 am 
Offline
User avatar

Joined: Fri Feb 01, 2008 4:50 pm
Posts: 101
So you just set up the tftp server to upgrade the system when the downloadComplete function is called?

EDIT: Basically, I want to be able to use the terminal to download a file and upgrade itself, without intervention from a computer.


Top
 Profile  
 
PostPosted: Mon Jan 05, 2009 11:18 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
No, I guess I was unclear. Every time *I* have needed to upgrade, I was able to have a remote TFTP client push the new data to me (reboot to download mode first, then the remote computer pushes the data via TFTP).

This does not sound like it meets your needs, however. Where you want the terminal to be in full control of the upgrade process and the remote device needs to be a passive device only used for file transfer. If you want to do that and decide you don't have enough room in the file system to hold the new file upgrade, then you will probably need to modify the FTPClient object as I described.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Mon Jan 05, 2009 12:11 pm 
Offline
User avatar

Joined: Fri Feb 01, 2008 4:50 pm
Posts: 101
Okay, thank you Jeremy. I was having trouble downloading a 150KB file, so I would need to keep it in memory.

Where can I get version 2.60 of Qlarity Foundry?


Top
 Profile  
 
PostPosted: Mon Jan 05, 2009 12:40 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
www.qsicorp.com/engfiles

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Wed Jan 07, 2009 12:24 pm 
Offline
User avatar

Joined: Fri Feb 01, 2008 4:50 pm
Posts: 101
Jeremy,

I have gotten the FTP Client to work okay, but I still have a couple questions. First, what if I try to connect to a server and the login credentials are wrong? As far as I have used it my program only knows that it is connected, but doesn't get any notice that the user/pass combo was wrong. How can I differentiate between connected & logged in and connected & not logged in? Second, is there any connection timeout? It seems like it just hangs if it can't make a connection.

Thanks,

Ryan


Top
 Profile  
 
PostPosted: Thu Jan 08, 2009 8:08 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
If the credentials are incorrect, the FTPError event will be triggered and data[] will contain the exact error message. I think a bad password is error 530 in FTP.

You can use the FTPCmdIn and FTPCmdOut events to monitor communication -- the event stream looks very different in the case of connected but not logged in versus connected and logged in.

The EthernetError should fire when the connection times out. However, it looks like there may be a bug in the object, at least for non-existent hosts that causes the event not to fire.

You can work around the bug by adding the following code to your object instance:
Code:
func CommError(errcode as integer, errmsg[] as byte)
    handles MSG_COMM_ERROR
    dim socket as comm

    socket := GetComMessageSource()
    default()

    if socket == COM_INVALID then
        EthernetError(errcode, errmsg)
    endif
endfunc

func EthernetError(errcode as integer, errmsg[] as byte)
   'Replace the _Print with whatever you want to have happen here
    _print ("EErr: " + errmsg)
endfunc


Note: Once we fix the bug in the base object you will want to remove the CommError function or else your EthernetError event will fire twice.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group