Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Wed Nov 22, 2017 5:44 am

All times are UTC - 7 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Oct 06, 2009 11:22 pm 

Joined: Fri Sep 18, 2009 10:59 pm
Posts: 19
Location: Mumbai, India.
Dear sir,

I am developing an application using Qlarity Foundry 2.50 for QTERM-G75 touch screen. I want to read a text file (abc.txt) that I have kept in the flash of the touch screen. The text file is as follows:

Hello World!!
My name is Jay

I want to read single line at a time. My code is as follows:

dim fd as filedesc
dim oneLine as string

fd = OpenFile("/abc.txt", FILE_READ AND FILE_TEXT)
ReadFile(fd, oneLine)
labelName.Value = oneLine

However, the text appearing in the labelName (of type LabelV2) is the entire contents of the file and not just the one line of text as expected. I read the documentation for the ReadFile() API and it tells that it will read only one line in the text mode and convert it to the type of variable in which it will be stored. However, I am not able to get the desired result. What am I missing?

Thank you.

- Jay

PostPosted: Wed Oct 07, 2009 9:17 am 
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
The issue is that "FILE_TEXT" is poorly named. It should really be called record mode.

If you create the file with Qlarity, it reads the data out just fine one record at a time, but it was never really intended for work with other sources of data (at the time FILE_TEXT was created, getting files onto the Qlarity terminal was much more difficult than it is now).

You have two options here. The first is to read the file in binary format, then parse it line by line. This is fairly straightforward.

'Sample code to show a concept.  It is untested

dim fileContents[] as byte
dim filePos as integer
func LoadFile(name as string)
    dim desc as filedesc
    dim leng as integer

    desc = OpenFile(name, FILE_READ AND FILE_BINARY)
    SetFilePos(desc, -1, true)
    leng = GetFilePos(desc)
    SetFilePos(desc, 0, true)

    redim(fileContents, leng)
    ReadFile(desc, fileContents)

    filePos = 0

func GetNextLine() returns string
    dim pos as integer
    dim retVal as string
    pos = find(fileContents, filePos, -1, "\n")

    if pos < 0 then
        'Not found, so throw
        throw("GetNextLine", "No more lines int the file")

    retVal = mid(fileContents, filePos, pos-filePos-1)
    filePos = pos+1

    return retVal

func UseFile()
    labelName.value = GetNextLine()

The other approach would be to modify the text file so that it was in the format that the Qlarity firmware expects for text files. This means you should enclose string lines in quotes.

"Hello World!!"
"My name is Jay"

Numeric lines would not be in quotes.


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 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:  
Powered by phpBB® Forum Software © phpBB Group