I came back to my esp8266 project and got it working but i battled for a while with aliased variables in decoding the return.
I tried
dim strNTPTime as string * 4
dim ulNPTTime as unsignedlong alias strNPTTime
but i don't think this worked as expected. Regardless of what i put in the string i got the same number.
I changed it to
dim ulNPTime as unsignedlong
dim byTime(0 to 3) as byte alias ulNPTTime
and inserted the string return byte by byte into byTime and it works.
should the first example have worked ?
Should this work
Re: Should this work
No, because of the way that fixed-length strings are stored in memory. In addition to the bytes for the characters of the string there are two additional bytes, one giving the string length and the other identifying the string type. In contrast, the Byte array that you got to work utilizes exactly the number of bytes specified. See the manual page below for string implementation details.FFMan wrote:should the first example have worked ?
http://www.zbasic.net/doc/ZBasicRef.php?page=105
You can observe what I've described using this simple test program that does work because it takes the string storage overhead into account.
Code: Select all
Const strLen as Integer = 4
Dim strNTPTime as String * strLen
Dim ulNPTTime as UnsignedLong Based StrAddress(strNTPTime)
Dim b(1 to strLen+2) as Byte Based strNTPTime.DataAddress
Sub Main()
Dim i as Integer
strNTPTime = "abcd"
Call dspTime(ulNPTTime)
Debug.Print
Debug.Print "Bytes of the string storage:"
Debug.Print "[";
For i = LBound(b) to UBound(b)
Debug.Print CStrHex(b(i));
Next i
Debug.Print "]"
End Sub
Sub dspTime(ByVal uval as UnsignedLong)
Dim s as String
Debug.Print "Characters of the string as an UnsignedLong value:"
s = CStrHex(uval)
Debug.Print "["; s; "]"
End Sub
- Don Kinzer