Skip to main content

Reply to "Sending TMCC Commands to Legacy Base over Serial Connections"

BillYo, yes, I test fire it with the Legacy remote before I try to trigger it with my program.

Here's the current version of my core code, and still no luck.   There's alot of other code, mostly superfluous I think (borrowed from Google searches), but since I'm getting a response in the SER when I try to write to the com port, I think the rest is fine.  My guess is the error lies in this part of my code.  I shamelessly borrow from public code snippets, so no credit for coming up with what I do have all on my own!  I've also gotten some coaching from Harvy Ackermanns, many thanks to him!

Sub TestEngine66RearCoupler()

intPortID = 3
Call Terminate 'make sure port is available
Call Initialize(intPortID) 'open port
TMCC1String = "11111110"
EngineNum = Dec2Bin(66, 7) 'convert engine number to binary
CommandVal = "00110"
CmdString = "00" & EngineNum & "00" & CommandVal
CmdStringLeft = Left(CmdString, 8) 'parse string into two bytes, number 1
CmdStringRight = Right(CmdString, 8) 'parse string into two bytes, number 2
CmdByte(1) = bin2Byte(TMCC1String) 'try to convert byte string into a byte array - THIS IS WHERE I THINK MY ERROR IS
CmdByte(2) = bin2Byte(CmdStringLeft) 'try to convert byte string into a byte array - THIS IS WHERE I THINK MY ERROR IS
CmdByte(3) = bin2Byte(CmdStringRight) 'try to convert byte string into a byte array - THIS IS WHERE I THINK MY ERROR IS
Call ComPortCmd(intPortID, CmdByte) 'Call the routines that send the message
Call Terminate

End Sub


Function bin2Byte(ByVal s As String) As Byte() 'THIS FUNCTIONS CONVERTS THE STRING INTO THE BYTE ARRAY
    Dim bitsIn As Long
    bitsIn = 8

    Dim i As Long
    'pad with zeros
    If Len(s) Mod bitsIn <> 0 Then
        For i = 1 To bitsIn - Len(s) Mod bitsIn
            s = "0" & s
        Next i
    End If
     
    i = Len(s)
    Dim bytes() As Byte
    Dim byteCount As Long
    byteCount = -1
    Dim sByte As String
    Do While LenB(s) > 0
        byteCount = byteCount + 1
        ReDim Preserve bytes(byteCount)
         
        sByte = Mid$(s, Len(s) - bitsIn + 1)
        'sByte = Mid$(s, 1, bitsIn)
        For i = 0 To 7 Step 1
            bytes(byteCount) = bytes(byteCount) + CLng(Mid$(sByte, 8 - i, 1)) * 2 ^ i
        Next i
        s = Mid$(s, 1, Len(s) - bitsIn)
        's = Mid$(s, bitsIn + 1)
    Loop
    bin2Byte = bytes
End Function

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653
800-980-OGRR (6477)
www.ogaugerr.com

×
×
×
×
×