Thinking back to the previous thread, I think the issue is that the string is being passed between several subs and functions before being output. Calling the output function directly doesn't show the issue. Also, it only appears if the first call is a short string then it is called with a longer string.
The code which is causing the muddled output is:
Code: Select all
TStr = FloatToStr(Temperature,1)
XML_CreateChild("Temperature",TStr)
FloatToStr is the standard implementation in Convert.bas. XML_CreateChild itself calls another routine which passes the string to the output routine:
Code: Select all
Public Dim XMLWrite As BTComms.BTWrite // Routine to write to XML output.
Public Sub XML_CreateTag(Rdata As String, open_close As Boolean = true)
XMLWrite("<")
If open_close = false Then XMLWrite("/") EndIf // If called with false then create a close tag
XMLWrite(Rdata)
XMLWrite(">")
End Sub
// Output a formatted child element. Call with the name of the child element and what to output
Public Sub XML_CreateChild(Cdata As String, Element As String)
XML_CreateTag(Cdata,true)
XMLWrite(Element)
XML_CreateTag(Cdata,false)
End Sub
There is no defined path to what is output, the unit is programmed to respond to commands sent to it. I would guess this alone makes it harder to evaluate the longest possible string.
If I add this before the program gets in to the main loop then it fixes the output problem. This is the only direct call to BTWrite, all others go via the XML_xxx commands.
Code: Select all
BTWrite("<BlueWeld><Build>",VersionStr,"</BlueWeld></Build>",13,10)
I did wonder if it was my output routine that was the source of the error, but I tried changing the code to create the output directly using BTWrite without calling the XML_CreateChild sub and it worked fine. It seems the issue only happens when I pass the string on from one sub to another.
The only other thought I've had, I believe Swordfish passes strings by value by default? I don't need this as I don't modify the string at all when outputting it. The issue I have is that some of the strings I pass are variables, some are consts.
Does Swordfish overloading allow multiple otherwise identical routines to be created with all possible combinations of ByRef and ByRefConst? All I'd need to do is copy and paste the sub and change them. It would mean a slightly larger code size but would use less ram and avoid this problem completely.