PutQueueStr

Discussion of issues related to writing ZBasic applications for targets other than ZX devices, i.e. generic targets.
Post Reply
kurakaira
Posts: 77
Joined: 21 March 2007, 1:21 AM
Location: Finland

PutQueueStr

Post by kurakaira »

i have a Nextion serial display and i have problems sending long string data .
i am displaying a scrolling text that is usually over 200 characters ,, strange behavior from Mega2560 :

Code: Select all

Const LcdComB as byte = 7
Const LcdComSpeedL as long = 38400
Const LcdMoSiPin as byte = H.1 ' HW7
Const LcdMiSoPin as byte = H.0 ' HW7


Dim LcdEndST as boundedstring(3) = chr(255) & chr(255) & chr(255)
Dim TST as boundedstring(60)
Dim T2ST as boundedstring(250)

Dim iLCD(1 to 100) as byte
Dim oLCD(1 to 500) as byte

Sub Main()

Call OpenQueue(iLcd, SizeOf(iLcd))
Call OpenQueue(oLcd, SizeOf(oLcd))
Call DefineCom(LcdComB, LcdMiSoPin, LcdMoSiPin, &H08) 
Call OpenCom(LcdComB, LcdComSpeedL, iLcd, oLcd)


Code :

TST = "rul.txt=" ' Name of text variable
T2ST = "Outside Temp " & fmt(TempUlkoBMES, 1) & "°c\r" ' Scrolling text data
T2ST = T2ST & "Outside RH " & fmt(RHulkoBMES, 0) & "%\r"
T2ST = T2ST & "Outside Pres " & fmt(UlkoPresS, 0) & "\r"

'T2ST = T2ST & "Sea Temp " & fmt(MeriTempS, 1) & "°c\r"
T2ST = T2ST & "Sauna Temp " & fmt(SHT31TempS, 0) & "°c\r"
T2ST = T2ST & "Sauna RH " & fmt(SHT31RHS, 0) & "%\r"
T2ST = T2ST & "Sauna Temp B " & fmt(TempSaunaBMES, 0) & "°c\r"
T2ST = T2ST & "Sauna RH B " & fmt(RHsaunaBMES, 0) & "%\r"
T2ST = T2ST & "Sauna Pres " & fmt(SaunaPresS, 0) & "\r"

Call PutQueueStr(oLCD, TST & chr(34) & T2ST)  ' if i divide the text like this it works , most of the time , but still other data to display can be inserted here from other parts of program ... also sometimes the first message does not get sent , only the latter part .

T2ST = "Kive's Temp " & fmt(KiviTempS, 0) & "°c\r"
T2ST = T2ST & "SSR Temp " & fmt(SSRtempS, 0) & "°c\r"
T2ST = T2ST & "Sauna Time " & fmt(SaunaPaallaHS,0) & ":"
If SaunaPaallaMinS < 9.5 then T2ST = T2ST & "0"
T2ST = T2ST & fmt(SaunaPaallaMinS,0) & "\r"
T2ST = T2ST & "Glass Temp " & fmt(LasiTempS, 0) & "°c\r"
T2ST = T2ST & "Kiuas Times " & cstr(SaunaKerratPI) & "x\r"
T2ST = T2ST & "Kiuas Burn " & cstr(SaunaTotalDayI) & "d " & cstr(SaunaTotalHourB) & ":" & cstr(SaunaTotalMinB) & "\r"

Call PutQueueStr(oLCD, T2ST & chr(34) & LcdEndST) ' Send the rest  

i tried dividing the text into different strings but that did not work , it seems the PutQuequeStr has a length limit of about 200 characters ?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: PutQueueStr

Post by dkinzer »

There may be two limitations combining to produce the result you are seeing. Firstly, because the number of characters in a string is contained in a Byte, the maximum string size is 255 characters. There is no way to get around this limit. See sections 2.11 and 3.28 of the ZBasic Language Reference Manual.

Secondly, when a string is built dynamically at run time (using the string append operator) the result is stored in an allocated string where the memory for the string elements (type, length, content) is allocated from the heap as a temporary string. If that resulting string is assigned to a fixed-size string (for example, a BoundedString) the temporary string is copied to the fixed-size string storage. If the result is copied to an allocated string type variable, the temporary string replaces the previous content of the allocated string variable (whose existing heap allocation, if any, is freed). In order for this to work correctly, the heap must be sufficiently large to allow the allocation for the temporary string. For native mode devices with larger amounts of RAM, the default heap size is 512 bytes. This is the case for the mega2560. You can change the default heap size by using Option HeapLimit so you might try setting the heap limit to 1000 bytes or more. See section 3.29 of the ZBasic Language Reference Manual.
- Don Kinzer
Post Reply