News:

  • May 30, 2026, 07:55:51 PM

Login with username, password and session length

Author Topic: Modbus to Peristaltic Pump Round 2  (Read 13400 times)

MBAutomation

  • Sr. Member
  • ****
  • Posts: 60
Modbus to Peristaltic Pump Round 2
« on: August 03, 2021, 09:15:55 PM »
I am trying to write to my pump now that the pump has been fixed.  I can read from the pump, but not write.   When I read from the pump I have to use subscribe.   I convert 2 elements from v3000 as real DWORD and swap words.   

     The raw number I am getting is 4 bytes. 2.442463E-041.   It is reading 600 after the conversion. How do I write back to the register in the format it is wanting?


Thank you

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Modbus to Peristaltic Pump Round 2
« Reply #1 on: August 04, 2021, 01:40:01 AM »
Looks like you need word swapping.

0x4416 0000 = 2.442463E-041

0x0000 4416 = 600.0

Also, double check to make sure you're not off by 1 register.  Flipping the word order when you're off by one register can give deceptively correct results, especially if both adjacent words are zero.  Try to get a value that takes non-zero values in both words and read that to check.  Plus just sending something and confirming what the pump thinks it heard is helpful too.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

MBAutomation

  • Sr. Member
  • ****
  • Posts: 60
Re: Modbus to Peristaltic Pump Round 2
« Reply #2 on: August 04, 2021, 08:46:27 AM »
when writing back to the register, do I need to have it converted back to hex, or will it accept it in decimal?   I did have it on one register ahead.  I am writing register 1003 that is 4 bytes (real).   I added 1 because I thought we added a 1 to Modbus registers.

How do I write back to the 2.4424 number?    Currently, I am using publish, but I'm not sure if it's necessary.   

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Modbus to Peristaltic Pump Round 2
« Reply #3 on: August 04, 2021, 11:04:04 AM »
So after correcting the off-by-one condition, you no longer need to word swap, correct?  Did you verify the off-by-one diagnosis by generating other data where off-by-one and word order would not mimic each other in decoding?
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Modbus to Peristaltic Pump Round 2
« Reply #4 on: August 04, 2021, 11:09:14 AM »
Sometimes it's helpful to read more consecutive words (like say 4) so you can look at the raw data and figure out the word order and offset issues at the same time, but you're still going to need unique data in the registers to know you've got it correct.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

MBAutomation

  • Sr. Member
  • ****
  • Posts: 60
Re: Modbus to Peristaltic Pump Round 2
« Reply #5 on: August 04, 2021, 11:43:37 AM »
No, I removed my plus one address and utilized the correct address the pump is supposed to be on.

I went from 1003 to 1002 which it's supposed to be on.

I also still have to word swap and move it to an R address

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Modbus to Peristaltic Pump Round 2
« Reply #6 on: August 04, 2021, 12:24:38 PM »
You cannot skip this step.   You have to do this before you do anything else, or you're going to waste your time.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

MBAutomation

  • Sr. Member
  • ****
  • Posts: 60
Re: Modbus to Peristaltic Pump Round 2
« Reply #7 on: August 04, 2021, 01:39:44 PM »
I apologize.    Which step should'nt skip?

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Modbus to Peristaltic Pump Round 2
« Reply #8 on: August 04, 2021, 04:14:50 PM »
Being sure you're inferring the word order and register addressing convention correctly for the server in question.   One way to do that is to have unique byte values in enough consecutive registers that only one combination of word order and register address offset produces the correct floating point value.

For example if you have three consecutive words represented in hex as 0x0000 0x4416 0x0000, and you know the encoded floating point value is 600.0, it's equally possible that you should be reading the first two words with word swap, or the second and third words with no swap.  You have to know positively which scenario you have for us to be able to answer the original question, but in fact also just to get your reads to work consistently.

Let's assume you can get a value of 3.3 into the previous floating point slot, which maps to the two previous words.   3.3 will encode as 0x4053 0x3333 without word swap, so in scenario 1 in the previous paragraph, those three registers would still read the same, with the previous two as 0x3333 0x4053.   In scenario 2, they'd be 0x3333 0x4416 0x0000 (with the previous word at 0x4053), so you'd be able to divine both word order and register translation.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

MBAutomation

  • Sr. Member
  • ****
  • Posts: 60
Re: Modbus to Peristaltic Pump Round 2
« Reply #9 on: August 05, 2021, 08:12:48 PM »
Ok, Thank you for clarifying.  I noticed that when I try and use the first address the MRX immediately faults out.   The other night I was able to read this address and use it.  Tonight I cannot.  the other part that makes it difficult is this pump is in Cali and I'm in  Colorado.     I am reading certain things correctly,  some other things I am not.   I am going to dig into this more when someone in Cali will turn it back on.


MBAutomation

  • Sr. Member
  • ****
  • Posts: 60
Re: Modbus to Peristaltic Pump Round 2
« Reply #10 on: August 07, 2021, 07:33:44 PM »
I finally was able to get to the bottom of it.     The Modbus registers did need to be moved forward one bit.    I was also able to write to them, I had to revers the numbers from and R value to V in the Do-More program.

Thank you for your help!

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Modbus to Peristaltic Pump Round 2
« Reply #11 on: August 07, 2021, 08:08:09 PM »
Good deal!  Glad you got it working!
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

MBAutomation

  • Sr. Member
  • ****
  • Posts: 60
Re: Modbus to Peristaltic Pump Round 2
« Reply #12 on: August 08, 2021, 01:07:00 AM »
I do have a question now.   After I had it working, I started organizing things more and now its all kind of lost its mind.     The pump wont turn off when commanded to.     When I would re-download to the plc it would turn off for a second,  then turn back on.   Right now it just decided to turn off.

Could I have collisions going on and keeping it on?

MBAutomation

  • Sr. Member
  • ****
  • Posts: 60
Re: Modbus to Peristaltic Pump Round 2
« Reply #13 on: August 08, 2021, 04:12:24 PM »
My plc's ethernet port quit working. I am wondering if that could be affecting the problem as well. I am waiting for for new PLC.   I was putting my setpoint unto a R data type,  then changing it to a word swapped V data type and writing it.   I was doing e
This with all values. And it was working fine.