Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Is there something special about CHR(&H0A)?


MinhChauVu Oct 30, 2022 04:37 PM

Does anyone having the same problem like me?  I am trying to compose a time word and send it to the Nortek Z-Cell to set it clock.

The command to set the clock is SC then follow by the time word in binary with the strange format of mmssDDhhYYMM.

My time is 10/30/22 15:50:30 (string before I convert the timeword to binary, SC503030152210)

I then use the CHR() to convert the timeword to Binary and it fail to convert the month of October (10) into binary. I was expecting 0A but the result was 20.

53 43 32 1E 1E 0F 16 20

Then it comes to time is 10/30/22 16:06:10 (string before I convert the timeword to binary, SC061030162210)

I then use the CHR() to convert the timeword to Binary and it fail to convert the month of October (10) and the second (10) into binary.  I was expecting 0As but the result was 20s.

53 43 06 20 1E 10 16 20

I tried just a simple CHR(&H0A) and I also get 20 instead of 0A but if I tried CHR(&H0B), I do get 0B

This mean that the CHR() function fail to convert the number 10 to binary

When I try some other numbers, I found that the CHR(&H0D) also returned 20 and especially when CHR(&H00) is used, the returned was skipped.  It means that if the time is midnight (00:00:00), I would have a big problem.

Any thoughts of overcome this issue?

Cheers,

MinhChau (Hung) Vu


JDavis Nov 1, 2022 06:22 PM

 Here is one program method that may help you. Note that many string processing instructions stop at the first null character. When you output your time word, use SerialOutBlock(). SerialOpen() must not use format 0 or 19.

'This program shows how FormatLong can be used to display the
'  contents of a binary string in a formatted hexadecimal string.
' It displays the true contents of a string, being useful for troubleshooting.
Public BinString As String
Public HexString As String * 64
Dim LongVal As Long
Dim i As Long

'Main Program
BeginProg
  BinString(1,1,1) = CHR(13)
  BinString(1,1,2) = CHR(00)
  BinString(1,1,3) = CHR(14)

  Scan (1,Sec,0,0)
    'Read each character of BinString and build formatted HexString
    HexString = ""
    For i = 1 To 16
      LongVal = ASCII(BinString(1,1,i))
      HexString = HexString & FormatLong (LongVal,"%02X") & " "
    Next
  NextScan
EndProg

 

Log in or register to post/reply in the forum.