Convert integer to a hex value then write serial

Discussion in 'Pascal Logic Code Examples' started by Pie Boy, Nov 21, 2012.

  1. Pie Boy

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    Hi All virgin post hope its easy to understand

    I am using a 5500paca to write serial to a integra av receiver

    Code:

    {this code gets a c-bus group address level converts to percent and then writes the appropriate % to serial to an Integra av receiver}

    {Initialisation}

    OpenSerial(1, 1, 9600, 8, 1, scNoFlowControl, scNoParity);

    { constants }
    S:string;

    { variables }
    Volume : integer; { stores c-bus group address level }


    { module code }

    {if Group address has changed then write serial }

    if haschanged (GetLightingLevel(Group01) ) then
    begin
    Volume := LevelToPercent(GetLightingLevel(group01));
    format(s, '!1MVL', Volume:1, #13);
    Writeserial(1, s);
    end;

    my problem being that the integra reciever is looking for a hex value for the volume string which looks like this '!1MVL00'(CR/#13) for 0% the last two digits determine the volume so '00' to '64' in hex

    how do i convert the volume integer into hex before writing the serial port

    any ideas?
     
    Pie Boy, Nov 21, 2012
    #1
  2. Pie Boy

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,427
    Likes Received:
    64
    Location:
    Adelaide
    I have an Onkyo receiver I'm controlling from logic the same way.. here's a few of the relevant snippets from my code.
    Code:
    {constants}
    Z1VolUp = '!1MVLUP';
    Z1VolDn = '!1MVLDOWN';
    Z1GetVol = '!1MVLQSTN';
    Z1VolSet = '!1MVL';
    
    {variables}
    StrWorking : String;
    IntWorking : Integer;
    Z1Volume : Integer;
    
    {module}
    ...
          IntWorking := GetIntSystemIO("IntSysZ1Vol"); {get the level}
          OutString := Z1VolSet; {set the first part of the command string}
          IntToHexString(IntWorking,0,StrWorking); {set the variable part of the command }
          Append(OutString,StrWorking); {append the two}
          Z1Volume := IntWorking;
    
    ...
      if (OutString <> '') then
        begin
          {If we have something to send, send it, otherwise go to the
          receive state to see if we have received an unsolicited notification}
          WriteSerial(1,OutString);
          WriteSerial(1,#13);
          CommTimeout := 1;
        end;
    
    Nick
     
    NickD, Nov 22, 2012
    #2
  3. Pie Boy

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    Cheers NickD Got it sorted
     
    Pie Boy, Nov 25, 2012
    #3
  4. Pie Boy

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    Feedback

    Hi NickD

    I have finished writing my modules for my Integra receiver
    would you be keen to review my code and give me some feedback??
     
    Pie Boy, Jul 7, 2014
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.