Author Topic: Reading DINT.bit returns bit position value, not true/false (v3.97c)  (Read 1262 times)

spaderkung

  • Newbie
  • *
  • Posts: 7
    • View Profile
Same for INT, DINT.

For example: Read(IntegerTag.1) will return 0 or 2. I would expect 0 or 1.


AdvancedHMIDrivers.EthernetIPforCLXCom connectionAdvancedHMI;
connectionAdvancedHMI = new AdvancedHMIDrivers.EthernetIPforCLXCom();
... connecting and validating other read/write operations ...
connectionAdvancedHMI.Read("IntegerTag.1");
« Last Edit: January 19, 2015, 07:30:25 AM by spaderkung »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5276
    • View Profile
    • AdvancedHMI
Re: Reading DINT.bit returns bit position value, not true/false (v3.97c)
« Reply #1 on: January 19, 2015, 07:54:31 AM »
Try this to see if it fixes it. Open EthernetIPforCLXCom.vb and go to line 373, then modify the code like this:

If Responses(SequenceNumber).Values.Count > ElementNumber Then
   d(i) = Convert.ToString(((Convert.ToInt32(Responses(SequenceNumber).Values(ElementNumber)) And Convert.ToInt32(2 ^ BitNumber))) > 0)
End If


spaderkung

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Reading DINT.bit returns bit position value, not true/false (v3.97c)
« Reply #2 on: January 19, 2015, 08:05:40 AM »
Thanks,

Looks like it should work right (but some bit might give a negative value?); I will edit this reply after I run my test suite.

spaderkung

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Reading DINT.bit returns bit position value, not true/false (v3.97c)
« Reply #3 on: January 19, 2015, 11:06:00 AM »
' And this is my revision because
'  2^31 can not be cast as int32
'  last bit is sign bit giving a negative value for dint.31

d(i) = Convert.ToString(((Convert.ToInt32(Responses(SequenceNumber).Values(ElementNumber)) And Convert.ToInt32(1 << BitNumber)) <> 0))

I have run the following tests:
Code: [Select]
WritePLC Lx.DINT.31 1
WritePLC Lx.DINT.17 1
WritePLC Lx.DINT.0 1
WritePLC Lx.udt.DINT.31 1
WritePLC Lx.udt.DINT.17 1
WritePLC Lx.udt.DINT.0 1
WritePLC Lx.arrayudt.DINT.31 1
WritePLC Lx.arrayudt.DINT.17 1
WritePLC Lx.arrayudt.DINT.0 1
WritePLC Lx.INT.15 1
WritePLC Lx.Int.7 1
WritePLC Lx.Int.0 1
WritePLC Lx.udt.INT.15 1
WritePLC Lx.udt.Int.7 1
WritePLC Lx.udt.Int.0 1
Compare  = Lx.DINT.31 1
Compare  = Lx.DINT.17 1
Compare  = Lx.DINT.0 1
Compare  = Lx.udt.DINT.31 1
Compare  = Lx.udt.DINT.17 1
Compare  = Lx.udt.DINT.0 1
Compare  = Lx.udt.INT.15 1
Compare  = Lx.udt.Int.7 1
Compare  = Lx.udt.Int.0 1
Compare  = Lx.INT.15 1
Compare  = Lx.Int.7 1
Compare  = Lx.Int.0 1
Compare  = Lx.arrayudt.DINT.31 1
Compare  = Lx.arrayudt.DINT.17 1
Compare  = Lx.arrayudt.DINT.0 1
WritePLC Lx.DINT.31 0
WritePLC Lx.DINT.17 0
WritePLC Lx.DINT.0 0
WritePLC Lx.udt.DINT.31 0
WritePLC Lx.udt.DINT.17 0
WritePLC Lx.udt.DINT.0 0
WritePLC Lx.arrayudt.DINT.31 0
WritePLC Lx.arrayudt.DINT.17 0
WritePLC Lx.arrayudt.DINT.0 0
WritePLC Lx.INT.15 0
WritePLC Lx.Int.7 0
WritePLC Lx.Int.0 0
WritePLC Lx.udt.INT.15 0
WritePLC Lx.udt.Int.7 0
WritePLC Lx.udt.Int.0 0
Compare  = Lx.DINT.31 0
Compare  = Lx.DINT.17 0
Compare  = Lx.DINT.0 0
Compare  = Lx.udt.DINT.31 0
Compare  = Lx.udt.DINT.17 0
Compare  = Lx.udt.DINT.0 0
Compare  = Lx.udt.INT.15 0
Compare  = Lx.udt.Int.7 0
Compare  = Lx.udt.Int.0 0
Compare  = Lx.INT.15 0
Compare  = Lx.Int.7 0
Compare  = Lx.Int.0 0
Compare  = Lx.arrayudt.DINT.31 0
Compare  = Lx.arrayudt.DINT.17 0
Compare  = Lx.arrayudt.DINT.0 0

With this tag list
Code: [Select]
Tag PLC-adress
Lx.DINT.31 di0.31
Lx.DINT.17 di0.17
Lx.DINT.0 di0.0
Lx.INT.15 i0.15
Lx.Int.7 i0.7
Lx.Int.0 i0.0
Lx.udt.DINT.31 t.di0.31
Lx.udt.DINT.17 t.di0.17
Lx.udt.DINT.0 t.di0.0
Lx.udt.INT.15 t.i0.15
Lx.udt.Int.7 t.i0.7
Lx.udt.Int.0 t.i0.0
Lx.arrayudt.DINT.31 t.dia[0].31
Lx.arrayudt.DINT.17 t.dia[0].17
Lx.arrayudt.DINT.0 t.dia[0].0