Read individual holding register

Forum Home Forums Communicating with Devices Modbus Read individual holding register

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #5735
    ns.fariz
    Participant

    Hi Mikhail,
    I have successfully connect rapidscada to modbus device with function 3. And now, I have problem for reading some function, it’s explained that one modbus address can be divided to some output.

    9
    Mains low voltage
    0
    15
    13/16-16/16

    Mains high voltage
    0
    15
    9/16-12/16

    Bus failed to close
    0
    15
    5/16-8/16

    Bus failed to open
    0
    15
    1/16-4/16

    Please look above data, it divide 16 bit data to represent 4 output. How can I achieve that with rapidscada?

    Sorry for my English, I hope I can explain it better.

    Thank you for great software

    #5739
    Mikhail
    Moderator

    Hi,

    I’m not sure that I understand the question. But likely you need to create extra input channels of the Calculated real type. And use the Formula field of these channels to define the calculations.

    #5740
    ns.fariz
    Participant

    Hi Mikhail,

    I need to read alarm from register offset 2048. But manufacturer put it 4 alarm at one register 16 bit. So 1-4 bit is High Oil Temperature, 5-8 High Coolant Temperature, 9-12 Low Oil Pressure, 13-16 Emergency Stop. And modbus device will return value from 0-15 depending on alarm condition. So I need to read 1-4 bit of register offset 2048. what formula it is I can use?

    #5741
    Mikhail
    Moderator

    Hi,
    The idea I wrote before is true.

    For example, to get bits 5-8, you need a formula:
    ((UInt16)Val(101) & 0x0078) >> 4
    where 101 is the source input channel.
    Note: I didn’t test the formula.

    #5743
    ns.fariz
    Participant

    Thanks, I will try it.
    But, could you explain what this code mean? I want to understand it, so I can use for another alarm.

    #5747
    Mikhail
    Moderator

    This code performs bit operations. It uses C# syntax. You can find &, >> in C# documentation.
    Val() gets the channel value.

    #15035
    rapidscadaaks
    Participant

    Hi

    I have connected a device to Rapid Scada using Modbus.
    There are 8 Statues stored in the same address 1080.
    Status A is in BIT0-1
    Status B is in BIT2-3
    Status C is in BIT4-6
    Status D is in BIT7-9
    Status E is in BIT10
    Status F is in BIT11-12
    Status G is in BIT13
    Status H is in BIT14-15

    Using Bitmask, individual channels have been automatically created by Rapid Scada for each BIT with GetBit formula.
    Please suggest formula to get 2 and 3 BITS in one Channel as required above

    Many Thanks

    #15054
    Mikhail
    Moderator

    Hi,

    public double GetBits(double val, int start, int end)
    {
        UInt64 uintVal = (UInt64)val;
        int bitCnt = end - start + 1;
        int maskShift = 64 - bitCnt;
        return (uintVal >> start) & ((0xFFFFFFFFFFFFFFFF << maskShift) >> maskShift);
    }
    #15055
    Mikhail
    Moderator

    Or

    public double GetBits(double val, int n, int len)
    {
        ulong ulVal = (ulong)val;
        return (ulVal >> n) & (ulong)((1 << len) - 1);
    }
    
    public CnlData GetBits(CnlData cnlData, int n, int len)
    {
        return NewData(GetBits(cnlData.Val, n, len), cnlData.Stat);
    }
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.