Author Topic: ModbusTCPCom Write Bit Failure  (Read 3006 times)

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
ModbusTCPCom Write Bit Failure
« on: August 25, 2016, 07:45:41 PM »
I am using AHMI Version 3.99n which I believe is the latest. I started with adding a ModbusTCPCom driver to the form.
Then I added a DigitalPanelMeter and set its PLCAddress value to 40001. Then I added a MomentaryButton and set its PLCAddressClick to 40001.0.
When I run this program, clicking on the button makes no change to the value in 40001 when it is zero.
If I set it to 1, then clicking the button has no effect until it is released and then the value goes to zero. Using ModRSsim2 I can see the following debug information.

Original Value of zero at beginning:
Button Press: In=0000 And=FFFF Or=0001 Out=0000
Button Release: In=0000 And=FFFE Or=0000 Out=0000

Original Value of one at beginning:
Button Press: In=0001 And=FFFF Or=0001 Out=0001
Button Release: In=0001 And=FFFE Or=0000 Out=0000

It seems that in the case of the Button Press, the And value should be FFFE like it is in the Button Release.

Also, I noticed that if I delete the DigitalPanelMeter and run the program there is no polling or communications at all.
Nothing is sent to the server (ModRSsim2) at all when the button is pressed or released.

Thanks for any help that you can provide.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: ModbusTCPCom Write Bit Failure
« Reply #1 on: August 25, 2016, 09:00:20 PM »
Button Press: In=0000 And=FFFF Or=0001 Out=0000
This doesn't quite look right to me. This is how I think the AND/OR logic should result:

0000 AND FFFF = 0000
0000 OR   0001 =  0001

Therefore
(0000 AND FFFF) OR (0001) = 0001

If I am interpreting the line "In=0000  AND=FFFF Or=0001  Out=0000" correctly, shouldn't Out=0001 ?

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
ModbusTCPCom Write Bit Failure
« Reply #2 on: August 25, 2016, 09:22:08 PM »
Per the Standard Modbus Manual PI-MBUS-300 Rev. J we have this on Page 66.

Result = ( Current Contents AND And_Mask ) OR ( Or_Mask AND Not(And_Mask) )

For example:

                                  HEX       Binary
Current Contents   =      12       0001 0010
  And_Mask           =      F2       1111 0010
     Or_Mask          =      25       0010 0101

   Not(And_Mask)   =     0D       0000 1101

     Result              =    17        0001 0111

In a short summary:
1) If the AND bit is Set, then the existing bit will not be touched.
2) if the AND bit is Not Set, then the output bit will be forced to the OR mask bit value.

Thanks. Doug Lyons

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: ModbusTCPCom Write Bit Failure
« Reply #3 on: August 25, 2016, 09:59:46 PM »
I totally got that incorrect. This will be fixed in version 3.99p

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
ModbusTCPCom Write Bit Failure
« Reply #4 on: August 25, 2016, 10:47:30 PM »
That's great. Thanks, Archie.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: ModbusTCPCom Write Bit Failure
« Reply #5 on: August 25, 2016, 11:03:47 PM »
I appreciate you reporting that and pointing me to the solution.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: ModbusTCPCom Write Bit Failure
« Reply #6 on: August 28, 2016, 10:43:28 PM »
Version 3.99p has been posted with the fix to this.

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
ModbusTCPCom Write Bit Failure
« Reply #7 on: August 29, 2016, 02:23:41 AM »
Archie,

I appreciate your efforts on this, but there is still a problem with the button press.
Here is what we had before as noted above:

Original Value of zero at beginning:
Button Press: In=0000 And=FFFF Or=0001 Out=0000
Button Release: In=0000 And=FFFE Or=0000 Out=0000

Here is what I see with the new version 3.99p:

Original Value of zero at beginning:
Button Press: In=0000 And=0000 Or=0001 Out=0001
Button Release: In=0001 And=FFFE Or=0000 Out=0000

This case does work as expected, but if I put FFFF Hex into the 40001 register here is what we get:

Original Value of FFFF at beginning:
Button Press: In=FFFF And=0000 Or=0001 Out=0001

Since our address was 40001.0 we only wanted to affect the low bit.
But here we have reset all of the other bits except the low bit.
What I would have expected is for the AND to be the same as in the Button Release and be FFFE.
This would have left all of the other bits alone and only affected the low bit.

Hopefully you can review and fix this.

Thanks,
Doug Lyons


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: ModbusTCPCom Write Bit Failure
« Reply #8 on: August 29, 2016, 08:11:30 AM »
I based my logic on this statement from the Modbus specification:

"Note that if the Or_Mask value is zero, the result is simply the logical ANDing of the current contents and And_Mask.  If the And_Mask value is zero, the result is equal to the Or_Mask value."

Now that I re-read it a little more carefully, I see I misinterpreted the last sentence. I will try this again.


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: ModbusTCPCom Write Bit Failure
« Reply #9 on: August 29, 2016, 09:12:15 AM »
Try this patch to see if I got it right this time:

https://sourceforge.net/projects/advancedhmi/files/advancedhmi/3.5/Patches

- Download and extract the V399p patch file
- Copy the file to \AdvancedHMIDrivers\support (over write existing)
- Rebuild the solution

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
ModbusTCPCom Write Bit Failure
« Reply #10 on: August 29, 2016, 09:40:42 AM »
Archie,

I appreciate your persistence on this. How this works is not easily understood.
I have downloaded and installed your latest patch and all seems to be great now.

I will do a bit more testing later, but I think that you have conquered this problem.

Thanks,
Doug Lyons

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: ModbusTCPCom Write Bit Failure
« Reply #11 on: August 29, 2016, 08:14:36 PM »
It was actually quite easy once I got it straight in my head. My biggest problem was that I could not get out of my head the way the other protocols do it.