Beijer Electronics (formerly QSI Corporation)

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

All times are UTC - 7 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Character Strings
PostPosted: Tue Jul 03, 2012 11:46 am 
Offline

Joined: Thu Oct 09, 2008 2:37 pm
Posts: 13
Hi,
Have a byte stream with some character strings being received by the A12 panel using Qlarity 2.63.
The end of the string is marked by a NULL, 0 and is stored in aArray[] (dim as BYTE)
Problem I have is with terminating the string when displayed via a LabelV2 object.
When assigning Label.value = aArray the value shown is
"password" followed 6 characters that look like square boxes. How do I get rid of the 6 square boxes that follow the string?

Have tried Trim, _CharStrToStr, but no luck.


Top
 Profile  
 
 Post subject: Re: Character Strings
PostPosted: Tue Jul 03, 2012 11:52 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
In Qlarity, NUL characters in a string are perfectly permissible. If you are receiving such a string from an external source, you must manually find the NUL and terminate. Here is an example.

Code:
dim pos as integer
pos = Find(aArray, 0, -1, "\0")
if pos >= 0 then
    redim(aArray, pos)
endif

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
 Post subject: Re: Character Strings
PostPosted: Wed Jul 04, 2012 2:49 pm 
Offline

Joined: Thu Oct 09, 2008 2:37 pm
Posts: 13
Hi,

Tried the following:
dim sPassword as charstr
init sPassword := ""

func ProcessSetPasswordCommand(data[] as byte, nLen as integer)

dim index, i, pos as integer
init index := 3
init i := 0
dim arr[15] as byte
dim arr2[15] as byte

' copy the password string with NUL termination.
for i=0 to 10 step 1
arr[i] = data[index+i]
next

pos = Find(arr, 0, -1, "\\0")

if (pos >= 0) then
redim(arr, pos)
endif

sPassword = charstr(arr)


' DEBUG
Label_DebugMsg.value = sPassword

return

endfunc 'ProcessSetPasswordCommand

Label_DebugMsg.value will show "helloworld" with 6 square box symbols following. Can't figure out
how to get rid of the junk after "helloworld"


Top
 Profile  
 
 Post subject: Re: Character Strings
PostPosted: Thu Jul 05, 2012 6:53 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
For debugging purposes, try doing this:

' DEBUG
Label_DebugMsg.value = str(sPassword)

This will let you see exactly what characters are associated with each index of that array. Perhaps it is not a NUL in the array, but some other non-printable character (the box is the "replacement" character, and displayed whenever a character exists in the string that the font doesn't define).

Also, should you be using nLen somewhere?

_________________
Jeremy
http://www.beijerinc.com


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