PAC can't do sums?

Discussion in 'C-Bus Toolkit and C-Gate Software' started by PeteS, Jul 6, 2012.

  1. PeteS

    PeteS

    Joined:
    Jun 25, 2007
    Messages:
    33
    Likes Received:
    0
    Location:
    Onamalutu Valley, NZ
    Hi Guys,

    I have written a little bit of code for my PAC that reads in some temperatures, subtracts one temperature from another, and then outputs the result.

    Here are my initialisations as Global Variables:-

    {Enter Variable definitions here}
    WBB, WBT, WBDiff, BT, BB, BDiff : Real;

    Here is my code:-

    if
    HasChanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 0))
    or
    Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 1))
    or
    Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 2))
    or
    Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 3))
    then

    begin
    WBT := GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 0);
    WBB := GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 1);
    BT := GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 2);
    BB := GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 3);

    Delay ("00:00:03");

    WBDiff := WBT - WBB;
    BDiff := BT - BB;

    SetRealIBSystemIO("Measurement App Real Value", "Local Network", 6, 0, WBDiff);
    SetRealIBSystemIO("Measurement App Real Value", "Local Network", 6, 1, BDiff);
    end

    The way it works is that it looks for a changed value, then copies all the values into the variables, finds the difference of two sets of variables, and then outputs the result as real numbers to C Bus for my touch screen to read.

    It works just fine most of the time except that sometimes it comes up with a rubbish answer. It is as though the variables are randomly being reset to zero! For example, if the read in values are 52 and 48, the calculation is 52 - 48, the answer should be +4. Sometimes it will announce that the result is +52, and sometimes that it's -48. The only way it can come up with that answer is if one of the variables becomes zero, so the calculation being done is 0 - 48 = -48, or, 52 - 0 = 52. And the only way a variable can be zero is if it is reinitialised, or it is told to be zero.

    I have run Toolkit and watched the application log. The only strange thing is the application "208 security" coming from my Pascal unit every 30 seconds. The numbers from my General Input Module seem to be correct. Screen grab of log window included. This 30 second time period is the same as my GIM broadcast timing. Coincidence?

    I have also run the logic with the measurement manager open, and all the numbers are there to see, the correct stuff coming in from the GIM, and the wrong stuff going out from the PAC, and what I'm getting on my Touch Screen is what is being put out by the PAC. Please see the second screen grab.

    So as I see it the issues could be:-

    1 The 208 message is destroying variables or resetting the variables.

    2 The PAC can't do sums or has Alzheimers.

    3 My code is not working like I think it is.

    Anyone got any ideas?
     

    Attached Files:

    PeteS, Jul 6, 2012
    #1
  2. PeteS

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    You should check to verify that the measurement data is valid before using it. Use the "Measurement App Valid Value" in-built system IO to make sure that there is a valid value for each of the measurement values before doing any calculations with them.
     
    Darren, Jul 8, 2012
    #2
  3. PeteS

    PeteS

    Joined:
    Jun 25, 2007
    Messages:
    33
    Likes Received:
    0
    Location:
    Onamalutu Valley, NZ
    Hi Darren,

    This puzzles me, how could the data be "invalid"? And how does the line
    GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 1)
    know if the data is good or bad?

    All the data I have seen on the logs and measurement manager have been within the normal range of my sensors on the GIM.

    But in the Toolkit Application log a few minutes ago I saw the attached screen grab which shows all the readings normal until the two lines that appear to be generated by the Pascal Unit that say "208, Security.................... Just after that the output values do not reflect what should be calculated by the input values. The second line for device 6 channel 1 give a calculated value of -33C when the input values are 33C and 33C respectively.

    Anyway, I'll put the valid value lines into the code and see what happens, but I'm still concerned about the security message from an application I don't use!

    The If....then, now looks like:-

    HasChanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 0))
    or
    Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 1))
    or
    Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 2))
    or
    Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 3))
    and
    (GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 0)
    and
    GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 1)
    and
    GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 2)
    and
    GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 3))

    Thanks

    Pete
     

    Attached Files:

    PeteS, Jul 8, 2012
    #3
  4. PeteS

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    That is a good question, and it is not explained properly in the help file.

    The PAC will not know the value of the measurement channel until it has seen at least one C-Bus message containing this data. Until that time, the PAC will consider the value to be 0, but the data will be considered to be not "valid".

    That is correct. In this case, "valid" does not mean "within the normal range".

    There should be no connection between the Security App messages and the Measurement App data. If you use the C-Bus Diagnostic Software to capture and post these security messages, we should be able to determine what they are.

    The code above will not work due to the way you have combined OR and AND logic. You either need to move the brackets like this:

    Code:
    if (HasChanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 0)) or
       Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 1)) or
       Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 2)) or
       Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 3))) and
       GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 0) and
       GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 1) and
       GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 2) and
       GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 3) then ...
    
    or nest the logic like this:

    Code:
    if HasChanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 0)) or
       Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 1)) or
       Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 2)) or
       Haschanged(GetRealIBSystemIO("Measurement App Real Value", "Local Network", 4, 3)) then
      begin
        if GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 0) and
           GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 1) and
           GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 2) and
           GetBoolIBSystemIO("Measurement App Valid Value", "Local Network", 4, 3) then ...
      end
    
    The second solution is slightly more efficient because it only checks all of the "valid" settings when something has changed.
     
    Darren, Jul 9, 2012
    #4
  5. PeteS

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,436
    Likes Received:
    64
    Location:
    Adelaide
    I wonder if the PAC is restarting every so often..

    If so it would explain the 2 security application messages you see (these would be the security status request messages, which seem to be on by default unless you turn them off in a PAC project).

    It would also explain why the measurements default to zero every so often until they receive a new value.

    To see if the PAC is restarting you could toggle an unused group address in the initialisation section of the logic.. if that turns out to be the case then we can start looking at why it is happening.

    Nick
     
    NickD, Jul 9, 2012
    #5
  6. PeteS

    PeteS

    Joined:
    Jun 25, 2007
    Messages:
    33
    Likes Received:
    0
    Location:
    Onamalutu Valley, NZ
    Hi Guys,

    Darren, I've modified the code to be as per your second option, it seemed the more elegant solution. Thanks for the code. I've just run diagnostic and the file is attached. The security messages (two of many) occured at 18:08:57 and 18:08:58. Please also look at the message timed at 18:09:01 which also just happens to be from the PAC (unit 2) and is turning off my heating. All the "offs" set heating valves pumps boilers etc.

    Nick, I'll put some code in the initialisation section. I'll be back...........:eek:
     

    Attached Files:

    PeteS, Jul 9, 2012
    #6
  7. PeteS

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    These are the security "status request" messages, They are issued after start-up. They are occurring every 30 second (for example, 18:07:57, 18:08:27, 18:08:57, 18:09:27) which suggests that your PAC may be resetting (as suggested by Nick).

    This is also happening every 30 seconds, a few seconds after the security messages. Without seeing the code, it is hard to know why this is happening, but it is most probably not related to the security messages. It is most probably due to some logic which causes this to be sent shortly after start-up.
     
    Darren, Jul 9, 2012
    #7
  8. PeteS

    PeteS

    Joined:
    Jun 25, 2007
    Messages:
    33
    Likes Received:
    0
    Location:
    Onamalutu Valley, NZ
    Hi Guys,

    It's rebooting. I set my office lights to pulse on for 5 seconds when it initialises and it just has. Several times! Office lights are GA20 and ramp on and ramp off are picked out in bold in the snipped list below.

    So it would appear that the PAC DOES have Alzheimers!:D

    I just took a look at the unit voltages and the PAC has 30.5 volts.

    Traffic analyser has a few small red bits, and it also shows that there are average 2.7 to security messages a minute. I'll keep looking and see if I can work out where the errors are coming from.


    21:09:33 Rx : = Source Unit 6, Measurement, Measurement: Device 4 Channel 0 = 56E0 C
    21:09:43 Rx : 0506E4000E040200000024D9<CR>
    21:09:43 Rx : = Source Unit 6, Measurement, Measurement: Device 4 Channel 2 = 36E0 C
    21:09:53 Rx : 0506E4000E0401000000320E04030000002493<CR>
    21:09:53 Rx : = Source Unit 6, Measurement, Measurement: Device 4 Channel 1 = 50E0 C; Measurement: Device 4 Channel 3 = 36E0 C
    21:09:54 Rx : 050238000A14FFA4<CR>
    21:09:54 Rx : = Source Unit 2, Lighting, GA 20 Ramp to 100% at 4s rate
    21:09:58 Rx : 0502D00009A17F<CR>
    21:09:58 Rx : = Source Unit 2, Security, Security: Status Report 2 Request

    21:09:59 Rx : 0502D00009A080<CR>
    21:09:59 Rx : = Source Unit 2, Security, Security: Status Report 1 Request
    21:09:59 Rx : 050238000A1400A3<CR>
    21:09:59 Rx : = Source Unit 2, Lighting, GA 20 Ramp to 0% at 4s rate
    21:10:03 Rx : 0506E4000E040000000038C7<CR>
    21:10:03 Rx : = Source Unit 6, Measurement, Measurement: Device 4 Channel 0 = 56E0 C
    21:10:14 Rx : 0506E4000E040200000024D9<CR>
    21:10:14 Rx : = Source Unit 6, Measurement, Measurement: Device 4 Channel 2 = 36E0 C
    21:10:23 Rx : 0506E4000E0401000000320E04030000002493<CR>
    21:10:23 Rx : = Source Unit 6, Measurement, Measurement: Device 4 Channel 1 = 50E0 C; Measurement: Device 4 Channel 3 = 36E0 C
    21:10:33 Rx : 0506E4000E040000000038C7<CR>


    And later:-




    21:11:55 Rx : <CR>
    21:11:55 Rx : A3300051<CR>
    21:11:55 Rx : 8603030032300012<CR>
    21:11:55 Rx : = Source Unit 3, System Message
    21:11:59 Rx : 0502D00009A17F<CR>
    21:11:59 Rx : = Source Unit 2, Security, Security: Status Report 2 Request
    21:11:59 Rx : 0502D00009A080<CR>
    21:11:59 Rx : = Source Unit 2, Security, Security: Status Report 1 Request

    21:12:00 Rx : 050238000A1400A3<CR>
    21:12:00 Rx : = Source Unit 2, Lighting, GA 20 Ramp to 0% at 4s rate
    21:12:04 Rx : 0506E4000E040000000038C7<CR>
    21:12:04 Rx : = Source Unit 6, Measurement, Measurement: Device 4 Channel 0 = 56E0 C
     
    PeteS, Jul 9, 2012
    #8
  9. PeteS

    PeteS

    Joined:
    Jun 25, 2007
    Messages:
    33
    Likes Received:
    0
    Location:
    Onamalutu Valley, NZ
    Where next?

    Well it's still rebooting every now and again, so I've been having a play. I've done a search on PAC rebooting and found the causes are apparently power supply problems or C Bus connection problems, or it can be pushed into rebooting when the USB connector is removed. So to eliminate the USB cause, I've run the unit today without a cable plugged into the USB port. Also, the C Bus voltage is 30.1 volts, so I guess that rules that out. And there seem to be plenty of C Bus messages around and nothing else is having trouble. So where next? Internal fault in the unit?

    I worked out why the logic is firing a series of commands out for my heating. It is set to turn every heating device OFF when all the inputs are OFF. As that is the case at the moment, it's doing what it's logic tells it to!

    AND, I've deleted every bit of code that relates to this set of calculations. The Global Variables, and the Module. We'll see.
     
    Last edited by a moderator: Jul 10, 2012
    PeteS, Jul 10, 2012
    #9
  10. PeteS

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    The most common cause is either a logic error causing it to restart, or too much logic code.

    See main help file topic "PAC Resources" and "Controlling the PAC"
     
    Darren, Jul 10, 2012
    #10
  11. PeteS

    PeteS

    Joined:
    Jun 25, 2007
    Messages:
    33
    Likes Received:
    0
    Location:
    Onamalutu Valley, NZ
    Interesting reading.

    Without the troublesome code:-
    88.3% spare!
    Config memory 15360 used out of 131072
    User Settings Memory 4955 spare.
    365 instructions
    Run time 18%

    With the troublesome code:-
    87.7% spare!
    Config memory 16128 used out of 131072
    User Settings Memory 4955 spare.
    421 Instructions
    Run time 22%

    I'm running at the moment without the code in, so I'll see if it falls over.

    Thanks

    Pete
     

    Attached Files:

    PeteS, Jul 10, 2012
    #11
  12. PeteS

    PeteS

    Joined:
    Jun 25, 2007
    Messages:
    33
    Likes Received:
    0
    Location:
    Onamalutu Valley, NZ
    Hi Guys

    When these two lines of code are included the PAC falls over:-

    SetRealIBSystemIO("Measurement App Real Value", "Local Network", 6, 0, WBDiff);
    SetRealIBSystemIO("Measurement App Real Value", "Local Network", 6, 1, BDiff);

    These two lines generate the output onto C Bus of the calculated values for the Touch Screen to receive and display.

    Does anyone have any suggestions as to why this should cause the failure, and what alternative methods are there of getting a number value to display on the touch screen?

    Thanks

    Pete
     
    PeteS, Jul 11, 2012
    #12
  13. PeteS

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,436
    Likes Received:
    64
    Location:
    Adelaide
    This should work, and it shouldn't cause the unit to restart... you're not trying to do this every cycle are you?

    You should have some mechanism to limit the number of measurements you broadcast on the network.

    Here's the code I use in my test project :

    Code:
    once (second = 0) then
    begin
      if GetBoolIBSystemIO("Measurement App Valid Value", "Training Board", 0, 1) then
        begin
          r_temp := GetRealIBSystemIO("Measurement App Real Value", "Training Board", 0, 1);
          SetRealIBSystemIO("Measurement App Real Value", "Training Board", 10, 0, r_temp);
        end
    end
    
     
    NickD, Jul 12, 2012
    #13
  14. PeteS

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    I just tried these lines in a PAC and it didn't cause any problems. Can you send your PAC project archive to tech support and ask them to forward it to me?

    Depending on what the data is, you might be able to map it to a lighting group level.
     
    Darren, Jul 12, 2012
    #14
  15. PeteS

    PeteS

    Joined:
    Jun 25, 2007
    Messages:
    33
    Likes Received:
    0
    Location:
    Onamalutu Valley, NZ
    The input lines are set to "once" and it looks for changed data and valid data, so the output should only happen if the data changes, which as it is water temperature is usually slowly.

    Qun from Tech help already has the file, case number 00023111, but I've attached it here as well.

    Could the problem be when the touch screen sees the message, rather than when the PAC transmits? On second thoughts that can't be, I can send data out from the Diagnostic utility and it appears on the touch screen no problem.

    Could my PAC be sending out a corrupt message?

    This only seem to crash the PAC when it transmits.
     

    Attached Files:

    PeteS, Jul 12, 2012
    #15
  16. PeteS

    PeteS

    Joined:
    Jun 25, 2007
    Messages:
    33
    Likes Received:
    0
    Location:
    Onamalutu Valley, NZ
    Well now I'm really confused. Apparently the commands I've used are fine, but they don't work. The E mails I get back from tech help are really hard to understand. Every comment made so far just seems to confirm that what I've done should work.

    What I thought I'd done is:-

    Read a set of values broadcast from a GIM.
    Do some sums.
    Output the values onto Cbus
    Display them on a touch screen.

    Pretty obviously I've not done that, so, can anyone please tell me, if I have a calculated value in the PAC that is a real number, how do I display it on the Mk2 touch screen?

    Thanks

    Pete
     
    PeteS, Jul 18, 2012
    #16
  17. PeteS

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    There is an issue with the PAC only where it will reset if you try to transmit a value of 0 to a measurement application channel. For an easy work-around, change your code to:

    Code:
       WBDiff := WBT - WBB;
       BDiff := BT - BB;
       if WBDiff = 0 then
         WBDiff := 0.01;
       if BDiff = 0 then
         BDiff := 0.01;
       SetRealIBSystemIO("Measurement App Real Value", "Local Network", 6, 0, WBDiff);
       SetRealIBSystemIO("Measurement App Real Value", "Local Network", 6, 1, BDiff);
     
    Darren, Jul 19, 2012
    #17
  18. PeteS

    PeteS

    Joined:
    Jun 25, 2007
    Messages:
    33
    Likes Received:
    0
    Location:
    Onamalutu Valley, NZ
    Hi Darren,

    Many thanks for that. The PAC really CAN'T do sums:) Well it can, it just can't tell people about a zero result...........
     
    PeteS, Jul 20, 2012
    #18
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.