October 5, 2018 at 10:29 am #4343
i’m quite new to rapid scada/modbus.
I have an rabbit sensor device, with 8 analog ports, 12 Digital in and 8 digital out.
The analog ports are readable and give the correct value’s.
For the 12 Digital inputs, these are given in one channel, so the value should be seen as booleans per input.
How can i use 1 Element value to give boolean state to 12 channels. The looks are that the software always convert the binairy value into hexidecimals/decimals.
Is there a way to interpret the HEX value into booleans and use these for each input seperatly?
I am having troubles understanding or finding explanations for formula’s.
Or how to use in this case virtual channels with the right value’s
I would like to read a certain bit from this 12 bit stream. Somewhat like GetBit().
What i have configured in the device element group,
Read Coils 0x03 Start element adres : 9 element count 1 (2 byte ushort).
Address digital inputs 40009
Request Element group “Digital Input”
Send (12): 00 00 00 00 00 06 01 03 00 08 00 01
Receive (7/7): 00 00 00 00 00 05 01
Receive (4/4): 03 02 0F FE
So i would like to convert 0F FE back to 111111111110 and say channel 12-2 is true and channel 1 is false. First bit first input, 12th bit is input 12.
Any help is welcome.
JohnOctober 5, 2018 at 10:38 am #4344
Read the channel as unsigned.
Then add calculation channels and use the GetBit formula in them
Read the register as HoldingRegisters and then apply the formula in virtual channels
October 5, 2018 at 11:47 am #4347
- This reply was modified 1 year, 7 months ago by manjey73.
thanks for the tips, but can you elaborate on the Unsinged read?
As i can only set a X byte in the Elements settings in the GUI.October 5, 2018 at 2:04 pm #4350
HEX or BIN numbers is just representation. As manjey73 wrote, you should read register as ushort (2 bytes) type (this is in Modbus template) and then use formulas in Administrator to get the required bits. You need to create new input channels of Calculated discrete type in Administrator and use GetBit formula for these channels.October 5, 2018 at 3:29 pm #4352
the inputs are on Holding registers (4X), Start 9 Element count 1, 2 bytes ushort
Communicator log gives the decimal 4094 (so in1 is 0 closed)
Created in Administator, extra channel 19, in order of apperance :
POC Device, (our name of the test device)
Signal 9, (get the data from channel 9?)
Formula used yes,
Formula : Getbit(1,1) (first bit in the row)
Averaging : No
Quantity : State
Format : D
Unit : Off – on
no else configured.
For now it’s ok, i should invert the Getbit as 0 is on, 1 is resting state off.
That is for later concern.
Unfortunatly, i get the complete decimal 4094 -> 11111111110 or F FE from channel 9. Instead of the formula result..
What am i missing?October 7, 2018 at 7:17 am #4355
It’s very difficult to understand without screenshots. You could use image hosting like https://imgur.com/ to upload images and paste links here.
Change format to Enum text
To invert value type: Getbit(1,1) > 0 ? 0 : 1October 8, 2018 at 11:21 pm #4364
Hi Mikhail, All
sorry for the late reply, i will make the screen dumps today and will share them with you.
Unfortunatly i didn’t had time nor access to the test setup this Monday.October 9, 2018 at 3:11 pm #4369
OK. Let’s continue when you have a time.October 9, 2018 at 11:21 pm #4374October 10, 2018 at 10:04 am #4379
Somehow the calculation engine fails on the Getbit formula.
input channels configuration in Administrator : https://imgur.com/a/SGEmJFS
2018-10-10 09:07:57 <PMI-SCADA><SYSTEM><ACT> ScadaServerService 220.127.116.11 is started
2018-10-10 09:07:57 <PMI-SCADA><SYSTEM><ACT> Check the existence of the data directories is completed successfully
2018-10-10 09:07:57 <PMI-SCADA><SYSTEM><ACT> Check the existence of the configuration database files is completed successfully
2018-10-10 09:07:57 <PMI-SCADA><SYSTEM><ACT> Input channels are read from the configuration database. Active channel count: 59
2018-10-10 09:07:57 <PMI-SCADA><SYSTEM><ACT> Ouput channels are read from the configuration database
2018-10-10 09:07:57 <PMI-SCADA><SYSTEM><ACT> Users are read from the configuration database
2018-10-10 09:07:57 <PMI-SCADA><SYSTEM><ACT> Formulas are read from the configuration database
2018-10-10 09:07:57 <PMI-SCADA><SYSTEM><ERR> Error compiling the source code of the formulas:
Line 505, column 56: error CS0103: The name ‘Getbit’ does not exist in the current context
See the file C:\SCADA\ScadaServer\Log\CalcEngine.cs with the source code
2018-10-10 09:07:57 <PMI-SCADA><SYSTEM><ERR> Normal program execution is impossible.October 10, 2018 at 10:40 am #4381
Well, I told you why you had a mistake. You need to check how to call the formula.
Getbit GetBit and it is a different name
October 10, 2018 at 12:31 pm #4383
- This reply was modified 1 year, 7 months ago by manjey73.
Ok formula is excepted,
But i am having troubles understanding the function GetBit(a,b)
What does GetBit do exact? how does this function ticks?
Is the assumption, a = position and b = value to compare?
So if binvalue=1001 (binairy)
So GetBit(4,1) on binvalue, will result in GetBit being 1?
And GetBit (3,1) on binvalue, will result in GetBit being 0?
In the given formula, we check if GetBit > 0.
And after this test we flip the boolean by 0:1?
Sorry i have very very little C(++) experience 20 years ago, and lost that so i am trying to understand the function/way of thinking in this case.October 10, 2018 at 1:08 pm #4385
a – channel data number from which you want to check the required bit
b – is the number of the bit to be checked from 0 to 64 considering that the database always has a double representation. But in fact, if you read one register, you can actually check only from 0 to 15 for example
> 0 ? 0; 1 this entry you do the inversion if it is necessary
Not quite boolen, all variables RapidScada converts to double, this is a feature of the database implementation. However sometimes it is a hindrance 🙂 your perception is, Yes, a boolean.
Use C# help on MSDNOctober 10, 2018 at 3:00 pm #4389
So if i would like to check the first bit in de data value (1111 1111 1110) from signal 9, i should use : GetBit(9,1) and then invert it if needed.
October 10, 2018 at 7:22 pm #4393
- This reply was modified 1 year, 7 months ago by IncineratorX2.
bits in numbers start from zero. Do you want first or zero ?
bits in numbers start from zero. Do you want first or zero ? And not only the signal 9 and the Number 9 (the channel number is used in the formula)
GetBit (channel number, bit number) – you will get the same value as bit 0 or bit 1
GetBit (channel number, bit number) > 0 ? 0: 1 – you will get the opposite value if bit=0 then you will get 1, if bit=1 then you will get 0
- The topic ‘Modbus TCP – One Element value gives 4 Digital Inputs,’ is closed to new replies.