Forum Home › Forums › Communicating with Devices › Modbus › Read individual holding register
- This topic has 8 replies, 3 voices, and was last updated 1 year ago by
Mikhail.
-
AuthorPosts
-
July 21, 2019 at 2:49 pm #5735
ns.fariz
ParticipantHi 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/16Mains high voltage
0
15
9/16-12/16Bus failed to close
0
15
5/16-8/16Bus failed to open
0
15
1/16-4/16Please 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
July 22, 2019 at 2:01 pm #5739Mikhail
ModeratorHi,
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.
July 22, 2019 at 9:41 pm #5740ns.fariz
ParticipantHi 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?
July 23, 2019 at 2:46 pm #5741Mikhail
ModeratorHi,
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.July 23, 2019 at 9:23 pm #5743ns.fariz
ParticipantThanks, I will try it.
But, could you explain what this code mean? I want to understand it, so I can use for another alarm.July 24, 2019 at 2:19 pm #5747Mikhail
ModeratorThis code performs bit operations. It uses C# syntax. You can find &, >> in C# documentation.
Val() gets the channel value.July 27, 2024 at 5:51 am #15035rapidscadaaks
ParticipantHi
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-15Using 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 aboveMany Thanks
July 29, 2024 at 9:22 am #15054Mikhail
ModeratorHi,
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); }
July 29, 2024 at 9:24 am #15055Mikhail
ModeratorOr
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); }
-
AuthorPosts
- You must be logged in to reply to this topic.