Transmitting variables as ASCII strings

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by Extrex, Jun 13, 2007.

  1. Extrex

    Extrex

    Joined:
    Dec 5, 2005
    Messages:
    28
    Likes Received:
    0
    Location:
    Melbourne
    Hi
    I would like to transmit some serial commands using the Write serial command.
    But rather than storing all the string constants that I need , I was wondering if its possible to have the PAC generate them.

    An example of the serial codes I have to use would be something like

    'ABC'#00'ABC'#00#00' ,
    'ABC'#00'ABC'#00#01,
    'ABC'#00'ABC'#00#02

    As you can see the only actual variable is the last digit.
    It would be make my life sooo much more easier if I could just get a loop to work and replace the last digit.

    Any ideas on how to implement this??

    P.S I have tried using 'Append' function but the serial commands do not come out properly ( 0s between the constant and the variable)
     
    Extrex, Jun 13, 2007
    #1
  2. Extrex

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    What would be the process around the PAC generating the codes :confused: :confused: :confused:
     
    Phil.H, Jun 13, 2007
    #2
  3. Extrex

    Extrex

    Joined:
    Dec 5, 2005
    Messages:
    28
    Likes Received:
    0
    Location:
    Melbourne
    Actually storing each individual code in the PAC as constants and then calling them as and when needed
     
    Extrex, Jun 13, 2007
    #3
  4. Extrex

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    How many constants/ASCII packets do you need to store and call ???

    Still not sure anyone could determine what you want/need to do :confused:
     
    Phil.H, Jun 14, 2007
    #4
  5. Extrex

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    Can you give us the code which does not work so we can see why it does not work ? It may also help us to understand what you are trying to do.
     
    Darren, Jun 19, 2007
    #5
  6. Extrex

    Peter_L

    Joined:
    Oct 26, 2004
    Messages:
    12
    Likes Received:
    0
    Location:
    Adelaide
    all functions that i can see will add the integer as a char equv to a string
    eg :

    i:=2;
    format(string1,'ABC'#00'ABC'#00,i);

    will return 'ABC'#00'ABC'#00'2' not 'ABC'#00'ABC'#00#02

    but u need a create a string to use the WriteSerial function

    Solution:
    what you have to do is first define the command constant:

    SERIAL_COMMAND ='ABC'#00'ABC'#00;

    then create a function to return integer as a raw ASCII value:

    function int2ASCII(nVar: integer ): char;
    var
    temp : char;
    begin
    case nVar of
    0 :temp:=#00 ;
    1 :temp:=#01 ;
    2 :temp:=#02 ;
    3 :temp:=#03 ;
    4 :temp:=#04 ;
    5 :temp:=#05 ;
    6 :temp:=#06 ;
    7 :temp:=#07 ;
    8 :temp:=#08 ;
    9 :temp:=#09 ;
    end;
    int2ASCII := temp;
    end;

    then you can actually write the code you are wanting:

    for i := 1 to 4 do
    begin
    Temp:=Int2ASCII(i);
    Format(string1,SERIAL_COMMAND,Temp);
    WriteSerial(SerialPortIndex, string1);
    end;
     
    Last edited by a moderator: Jul 22, 2007
    Peter_L, Jul 22, 2007
    #6
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.