Beijer Electronics (formerly QSI Corporation)

Accessing user header data
Page 1 of 1

Author:  Tim W. [ Wed Aug 15, 2012 10:36 am ]
Post subject:  Accessing user header data

I am looking at adding a version string to the user header as described in Appendix C and E of the Programmer's Reference Manual. Appendix E states that the data from the user header can be retrieved from the application with GetBinaryResource. I would like to be able to pull the version string from the header and display it to the user on screen. Do you have an example of how to access user header data from within the application?

I am using Qlarity 2.63 and a QTERM-G56.


Author:  Jeremy [ Wed Aug 15, 2012 10:49 am ]
Post subject:  Re: Accessing user header data

Here is a brief code sample that demonstrates how to use GetBinaryResource to parse a variable initial value from the user header.

#option _SS_Lines
#option _SS_Marquee

dim VerStr as string
init VerStr := "Version 1.01"

func Startup ()
    handles MSG_INIT

    dim userHeader as string
    dim Version as string
    dim pos1, pos2 as integer
    userHeader = GetBinaryResource(bff_user_header)

    pos1 = find(userHeader, 0, -1, "VerStr=\"")
    pos2 = find(userHeader, pos1+8, -1, "\"")

    version = mid(userHeader, pos1+8, pos2-pos1-8)
    _print("The version is {" + version + "}")

Note that for this sample to work, you need to go to Tools->Settings->Compile and add
-uhi VerStr

to the Extra compiler flags box.

Author:  Jeremy [ Wed Aug 15, 2012 10:54 am ]
Post subject:  Re: Accessing user header data

Note that in general, parsing an initial value from the user header within Qlarity isn't particularly useful -- after all you can just use the variable directly. Where it becomes more useful is for external tools to be able to look at a .bff file and extract the version information.

GetBinaryResource(bff_user_header) is more useful to the Qlarity application if you are interested in the date that the BFF was compiled.

Author:  Tim W. [ Wed Aug 15, 2012 1:35 pm ]
Post subject:  Re: Accessing user header data


Thanks for the quick response. I want to be able to choose the version number at build time. I'm actually generating the version number externally and loading it into the header via the -uhs compiler option. I was able to adapt your solution to pull out the version number. In this case, it looks like the value isn't wrapped in quotes, but starts with VerStr= and ends with a newline (\n). Is each field in the user header always expected to be terminated with a newline?

The big missing piece for me was the bff_user_header resource name. I didn't see it in the documentation anywhere. We have a utility on the system to which the handheld is attached that can load new versions of the handheld software. Having the version number in the header would allow the utility to check the version before trying to load new software.

Thanks again!

Author:  Jeremy [ Thu Aug 16, 2012 6:26 am ]
Post subject:  Re: Accessing user header data

I can see how that might not be obvious.

For reference, if you are interested: bff_user_header is briefly documented with the GetBinaryResource function. Also, if you type GetBinaryResource( in CodeView, the autocomplete help will provide bff_user_header as an option.

Also, an alternative implementation which may be more convenient for a script-based system would be to place the init VerStr line of code in a separate file and then use
#include "VersionFile.txt"
in your global code. Then you can have your script just update that file as needed.

Yes, the compiler will emit a newline between each entry in the user header. (I would recommend not putting a newline in the content of your entries to make parsing easier).

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group