Help with RS232 Control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin D
    Ultra Senior Member
    • Oct 2002
    • 4601

    Help with RS232 Control

    I'm having a hard time trying to figure out RS232 control of a 1055. I'm using a third party control system and this is one of my largest programming jobs so far. Previous systems have been through IR or straight RS232 ASCII strings. Really two questions.

    1: What is the 1055 looking for, hex or binary; and do I need to include the 0x headers with every item.

    2: I'm new to checksums and could use some advice on how to calculate them.

    I guess I need to see a command, the correct format that needs to be sent to the unit, and how you arrived at the checksum. I'm sure it's not that hard to get the rest of the commands once I see how one is done.

    Thanks!

    Kevin D.
  • simonb68
    Senior Member
    • Jan 2003
    • 101

    #2
    Kevin

    I wrote a little VB program a while back to control the 1055 via RS232, source is here http://www.sbarnard.nildram.co.uk. The 1055 takes ASCII strings, have you obtained the RS232 spec from the Rotel web site, this, kind of, explains how its all done.

    Checksums are calculated on the entire message string, excluding the 0xfe header and obviously the checksum field at the end. The method to calculate the checksum is to sum the ASCII values of all the characters in the string then mod 256. This value must then be converted to a string, appended to the message string, and the 0xfe header stuck on the front.


    Example command/message string to Mute the 1055 (excluding header and checksum)

    CHR(3) + CHR(195) + CHR(16) + CHR(30)

    which equates to

    Count (bytes from ID to data, always 3) + Unit Type (fixed for 1055) + Command Type (fixed for a Command message) + The Mute Command (see RS232 spec)

    This is the string that the checksum is then calculated on

    Example Basic code to calculate checksum

    Private Function CreateChecksum(strText As String) As String
    Dim i As Integer
    Dim intCS As Integer

    CreateChecksum = ""
    intCS = 0
    For i = 1 To Len(strText)
    intCS = intCS + Asc(Mid(strText, i, 1))
    Next i
    CreateChecksum = Str(intCS Mod 256)
    End Function


    And then example code to send the entire command, note the command string being wrapped by the header and checksum.

    Public Sub SendCommand(intCommand As Integer)

    Dim strOutTemp As String
    Dim strOutput As String

    strOutTemp = Chr(3) + g_strUnit + Chr(16) + Chr(intCommand)
    strOutput = Chr(254) + strOutTemp + Chr(CreateChecksum(strOutTemp))
    frmDisplay.MSComm1.Output = strOutput

    g_filBufferLogFile.WriteLine ("SendCommand: " & strOutput)

    End Sub

    -----------------

    Please feel free to download and make use of the source code, if you need further help dont hesitate to drop me an email - barnards@nildram.co.uk

    Hope that helps
    Simon

    Comment

    Working...
    Searching...Please wait.
    An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

    Please push the back button and reload the previous window.'
    An unexpected error was returned: 'Your submission could not be processed because the token has expired.

    Please push the back button and reload the previous window.'
    An internal error has occurred and the module cannot be displayed.
    There are no results that meet this criteria.
    Search Result for "|||"