Modbus TCP – One Element value gives 4 Digital Inputs,

Forum Home Forums Communicating with Devices Modbus TCP – One Element value gives 4 Digital Inputs,

Tagged: , , ,

This topic contains 23 replies, has 3 voices, and was last updated by Avatar IncineratorX2 9 months, 1 week ago.

Viewing 15 posts - 1 through 15 (of 24 total)
  • Author
    Posts
  • #4343
    Avatar
    IncineratorX2
    Participant

    Hi Guys,

    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

    Logging :
    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.
    KR
    John

    #4344
    Avatar
    manjey73
    Participant

    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

    • This reply was modified 9 months, 2 weeks ago by Avatar manjey73.
    #4347
    Avatar
    IncineratorX2
    Participant

    Hi 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.

    #4350
    Mikhail
    Mikhail
    Moderator

    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.

    #4352
    Avatar
    IncineratorX2
    Participant

    OK, so:
    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 :
    19,
    Active yes,
    Digital IN1,
    Calculated Discrete,
    no object,
    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?

    #4355
    Mikhail
    Mikhail
    Moderator

    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 : 1

    #4364
    Avatar
    IncineratorX2
    Participant

    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.

    #4369
    Mikhail
    Mikhail
    Moderator

    OK. Let’s continue when you have a time.

    #4374
    Avatar
    IncineratorX2
    Participant

    Update :

    Communicator Device 1010 POC : https://imgur.com/LZdkK9s
    Device template : https://imgur.com/SpXX8cX
    Device template input : https://imgur.com/pzHHEbV
    Input channel properties : https://imgur.com/1IpzLPv
    Table overview in SCADA website : https://imgur.com/1JbnVwi

    #4379
    Avatar
    IncineratorX2
    Participant

    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 5.1.0.2 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.

    #4381
    Avatar
    manjey73
    Participant

    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

    • This reply was modified 9 months, 1 week ago by Avatar manjey73.
    #4383
    Avatar
    IncineratorX2
    Participant

    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.

    #4385
    Avatar
    manjey73
    Participant

    GetBit (a,b)

    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 MSDN

    • This reply was modified 9 months, 1 week ago by Avatar manjey73.
    • This reply was modified 9 months, 1 week ago by Avatar manjey73.
    • This reply was modified 9 months, 1 week ago by Avatar manjey73.
    #4389
    Avatar
    IncineratorX2
    Participant

    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.

    • This reply was modified 9 months, 1 week ago by Avatar IncineratorX2.
    #4393
    Avatar
    manjey73
    Participant

    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

Viewing 15 posts - 1 through 15 (of 24 total)

The topic ‘Modbus TCP – One Element value gives 4 Digital Inputs,’ is closed to new replies.