Beijer Electronics (formerly QSI Corporation)

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

All times are UTC - 7 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Jun 14, 2011 12:19 pm 
Offline
User avatar

Joined: Wed Feb 02, 2011 9:20 am
Posts: 20
I want to be able to write values as a .txt file to a USB flash drive from within my Qlarity application. Is there a way to do this either as timed multiple writes or just as a single write?

I am using an A12 with Qlarity CE and Qlarity Foundry 2.63.


Top
 Profile  
 
PostPosted: Tue Jun 14, 2011 12:43 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
This is very much possible.

The USB thumb drives are exposed in the Qlarity file system as the folders "/usb1", "/usb2", etc. I would suggest inserting a FileBrowserV2 object to your workspace when you get started so you can be familiar with how they appear and can better debug your application.

As far as writing to them goes, here is how I usually do it. (There are other options such as the data logger and file objects). This example would go in a button's click event, but you could move it anywhere.

Code:
func Click()
    dim desc as filedesc
    check error
        'make sure you use FILE_BINARY, even though this is a text file.
        desc = OpenFile("/usb1/MyFile.txt", FILE_WRITE and FILE_BINARY)
    on error
        _ClearException()
        'Do whatever you want if you are unable to open the file
        return
    enderr

    check error
        WriteFile (desc, "Line 1\r\n")
        WriteFile (desc, "Line 2\r\n")
        WriteFile (desc, "Line 3\r\n")
    on error
        _ClearException()
        'Do whatever you want If you are unable to write
    enderr

    CloseFile(desc)
endfunc


(Note, this code is untested)

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Wed Jun 15, 2011 9:32 am 
Offline
User avatar

Joined: Wed Feb 02, 2011 9:20 am
Posts: 20
Is there a way to write to the same file without writing over previously saved data? I want to write to the same file periodically to make a data trend. I tried moving CloseFile() to a location that isnt run periodically but cant seen to get the order down. Thanks.


Top
 Profile  
 
PostPosted: Wed Jun 15, 2011 9:32 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Open with FILE_APPEND instead of FILE_WRITE

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Wed Jun 15, 2011 1:05 pm 
Offline
User avatar

Joined: Wed Feb 02, 2011 9:20 am
Posts: 20
I seem to be getting an open file error when I change WRITE_FILE to APPEND_FILE. I have tried creating the file first using WRITE_FILE first and then putting information into the .txt file with FILE_APPEND and I have tried using FILE_APPEND on its own but both dont seem to work. Am I missing something?


Top
 Profile  
 
PostPosted: Wed Jun 15, 2011 1:37 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Sorry, that was my lapse. You should add FILE_APPEND, not replace FILE_WRITE.
Code:
        desc = OpenFile("/usb1/MyFile.txt", FILE_APPEND and FILE_BINARY and FILE_WRITE)

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Wed Jun 15, 2011 4:02 pm 
Offline
User avatar

Joined: Wed Feb 02, 2011 9:20 am
Posts: 20
Thanks. Works great now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 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