help with code

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by justinw, Jun 27, 2006.

  1. justinw

    justinw

    Joined:
    Nov 3, 2004
    Messages:
    21
    Likes Received:
    0
    Location:
    christchurch
    Hello there everyone just need a litttle guidance with logic codes and string variables.
    What i need to go is capture infomation from a the serial port of a pac (readserial) but do not seem to be able to get my coding right keeps coming up with identifier not declared error, can someone please help with the right sequence of things to do with declaring my string variable.
    Also the info that i am sending begins and ends with a non charactor ascii code (etx and stx) how do we deal with them as part of a string. or do they work when you type control b and c but you just cant seem them.

    cheers justinw
     
    justinw, Jun 27, 2006
    #1
  2. justinw

    sasha

    Joined:
    Apr 10, 2006
    Messages:
    11
    Likes Received:
    0
    If you are getting the error "identifier not declared" it is probably caused by you forgetting to declare your string variable. In the global variables section, declare the string variable like so :

    MyString : string;

    Non-ASCII characters can be added to a string like so :

    MyString := 'fred'#13#10;

    The "string type" topic in the logic help file describes how this all works.
     
    sasha, Jun 28, 2006
    #2
  3. justinw

    justinw

    Joined:
    Nov 3, 2004
    Messages:
    21
    Likes Received:
    0
    Location:
    christchurch
    more help

    Thanks sasha
    OK needmore help with reading a string from serial.
    I believe that i have got hat string but no real way of telling.
    Anyway the string is 38 charactors long I want the 22-26charcter
    this will be a 4 digit number and i need to do things with it (current room temp)
    can i mask out the other charctors or somehow pull the infomation out of the string. as it is allready a number should be easy to do stuff with it.
    cheers justin
     
    justinw, Jul 3, 2006
    #3
  4. justinw

    JohnC

    Joined:
    Apr 6, 2005
    Messages:
    554
    Likes Received:
    1
    Location:
    Sydney
    Hi There

    I have never done any Pascal programming, but the thing you want to do is to get a "SUBSTRING".

    I searched "SubString" in the PICED Logic manual and found that the COPY Procedure will do exactly what you want. Just declare a Variable to hold the extracted temp, then use it thus :

    Code:
    Copy(string1, string2, Index, Count);
    
    string1 is a string variable (new declared var to store the data into)
    string2 is a string (where you need to suck the info from)
    Index is the position (22 in your case)
    Count is the number of characters to suck (4 in your case)
    After running that, string2 will contain those 4 characters that you yearn for :)

    Cheers, John

    PS: You may need to use StringToInt Function if you want to do mathematical stuff with those 4 characters, as I think the data type will still be "String". after running that Copy procedure (that make sense?)
     
    Last edited by a moderator: Jul 3, 2006
    JohnC, Jul 3, 2006
    #4
  5. justinw

    JohnC

    Joined:
    Apr 6, 2005
    Messages:
    554
    Likes Received:
    1
    Location:
    Sydney
    Search the PICED help file for "Displaying Data"...

    Code:
    For example, to write the text 'Counter =' followed
    by the value of the variable called MyCounter :
    
    WriteLn('Counter = ', MyCounter);
    
    If the value of MyCounter was 123, then the Output
    Window would have the following line written to it :
    
    Counter = 123
    So, you can use that kind of thing to find out if you captured the string that you wanted.
     
    JohnC, Jul 3, 2006
    #5
  6. justinw

    justinw

    Joined:
    Nov 3, 2004
    Messages:
    21
    Likes Received:
    0
    Location:
    christchurch
    thanks

    cheers johncthat should be evrything ha i need to know.:) :)
     
    justinw, Jul 12, 2006
    #6
  7. justinw

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    Phil.H, Jul 14, 2006
    #7
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.