Get string from 3rd party device by TCPIP

Discussion in 'C-Bus Wiser 1 Controller' started by damonfung, May 10, 2012.

  1. damonfung

    damonfung

    Joined:
    Apr 15, 2011
    Messages:
    11
    Likes Received:
    0
    Location:
    tuen mun
    Hello,

    I am using Wiser to communication with 3rd party device.

    I would like to build up the LOGIC and open the port for the message rerceiving.

    The string are,

    repeat
    ReadClientSocket (1, ABC, #13#10);
    if ABC = '1' then
    begin
    SetLightingState(1, ON);
    end;
    until ABC = '0';

    However, it cannot pass the complies test and I don't know what's going wrong on this!

    Thank you for all buddy help!
     
    damonfung, May 10, 2012
    #1
  2. damonfung

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    If you declare a string called ABC, then the code you have provided will compile. To do this, in the Global Variables section, add this line:

    Code:
    ABC : string;
    Although this will make it compile, it will not make the code work. You need to put a delay in the loop, something like this:

    Code:
    repeat
      ReadClientSocket (1, ABC, #13#10);
      if ABC = '1' then
      begin
        SetLightingState(1, ON);
      end;
      delay(0.2);
    until ABC = '0';
     
    Darren, May 10, 2012
    #2
  3. damonfung

    damonfung

    Joined:
    Apr 15, 2011
    Messages:
    11
    Likes Received:
    0
    Location:
    tuen mun
    Sorry, thank a lot!

    But i don't know where can i place the "ABC : string;" as well.

    However, I have follow the "LOGIC ENGINE" for the following statement, it still not pass the complie.

    ReadClientSocket(1, ReceivedCommand, #13#10);
    ReceivedCommand := string;

    if length(ReceivedCommand) > 0 then
    begin
    if pos('on', ReceivedCommand) = 1 then
    begin
    Copy(GroupString, ReceivedCommand, 4, 3);
    Group := StringToInt(GroupString);
    SetLightingState(Group, ON);
    end
    else
    if pos('off', ReceivedCommand) = 1 then
    begin
    Copy(GroupString, ReceivedCommand, 5, 3);
    Group := StringToInt(GroupString);
    SetLightingState(Group, OFF);
    end
    else
    end;

    How can I solve it?

    Thank a lot for your help since I just the begin to be the programmer!
     
    damonfung, May 14, 2012
    #3
  4. damonfung

    Dave Byron

    Joined:
    Aug 3, 2004
    Messages:
    835
    Likes Received:
    0
    Location:
    Casurina
    To do this, in the Global Variables section, add this line:
    {Enter Variable definitions here}
    Groupstring : string;
    ReceivedCommand : string;
    Group : integer;

    then in the module part put; two things try indenting your code, makes it easyier to read and debug also do not use things that can be reserver words like "group", maybe use some thing like "mygroup".

    ReadClientSocket(1, ReceivedCommand, #13#10);

    if length(ReceivedCommand) > 0 then
    begin
    if pos('on', ReceivedCommand) = 1 then
    begin
    Copy(GroupString, ReceivedCommand, 4, 3);
    Group := StringToInt(GroupString);
    SetLightingState(Group, ON);
    end​
    else
    if pos('off', ReceivedCommand) = 1 then
    begin
    Copy(GroupString, ReceivedCommand, 5, 3);
    Group := StringToInt(GroupString);
    SetLightingState(Group, OFF);
    end​
    end;


    and it will compile.

    Dave
     
    Last edited by a moderator: May 14, 2012
    Dave Byron, May 14, 2012
    #4
  5. damonfung

    damonfung

    Joined:
    Apr 15, 2011
    Messages:
    11
    Likes Received:
    0
    Location:
    tuen mun
    damonfung, May 15, 2012
    #5
  6. damonfung

    Dave Byron

    Joined:
    Aug 3, 2004
    Messages:
    835
    Likes Received:
    0
    Location:
    Casurina
    Of coarse you do as you have not used the Global Variables section

    To do this, in the Global Variables section, add this line:
    {Enter Variable definitions here}
    Groupstring : string;
    ReceivedCommand : string;
    Group : integer;
     
    Dave Byron, May 15, 2012
    #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.