HMI Pad Forums Old forum Common Support Requests (old) Time formatter

This topic contains 1 reply, has 1 voice, and was last updated by  John 6 years, 6 months ago. This post has been viewed 1074 times

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #20041

    John
    Keymaster

      Hello,

      I am trying to create a template for our NanoLine controller using your software. We have 32 bit registers that can be formatted in HH:MM:SS. The first byte is seconds, the second byte is minutes, third bytes is hrs. I cannot figure out how to display this properly as HH:MM:SS. I’ve been trying to use the examples on page 61/100 of your 2.2.7 version of the manual, but have not been able to piece this together. Can you please offer a suggestion? I’m sure I have many mistakes, but please believe me, I have tried many different ways to get this to work without any success.

      This is one of the many commands I tried…

      time_Reg_01 DINT HR03 page=”Registers”; section=”Registers”; label = “time”; value = [(time_Reg_01).byte.to_s].join(“:”);

      #20042

      John
      Keymaster

        Please Try this:

        timeRegister DINT HR03 page=”Registers”; hidden=true;
        timeDisplay STRING INTERNAL page=”Registers”; value=format( “%02d:%02d:%02d”, ((timeRegister/65536).to_i%256).to_i, ((timeRegister/256).to_i%256).to_i, (timeRegister%256).to_i );

        This uses division and modulo operators to extract the relevant parts of the number and then converts them to a properly formatted string. This assumes seconds are on the least significant byte, if it is opposite you just need to reverse the partial expressions extracting the bytes.

      Viewing 2 posts - 1 through 2 (of 2 total)

      You must be logged in to reply to this topic.

      Copyright © SweetWilliam, S.L 2009-2013. All rights reserved.
      Science and Technology Park of the University of Girona, Emili Grahit, 91 (NarcĂ­s Monturiol building, Office P3-B03) 17003-Girona. Phone +34972183244