Coder Social home page Coder Social logo

Comments (7)

gavinying avatar gavinying commented on May 28, 2024

Hi, the holding_register writing function can be achieved via MQTT publish, take the online modsim as an example, when you run modpoll with MQTT broker specified,

modpoll --tcp modsim.topmaker.net --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv --mqtt-host mqtt.eclipseprojects.io

the tool will automatically subscribe to the topic modpoll/modsim001/set, so if you want to write to a specific holding_register, you can use any MQTT client tool, like mosquitto-clients or MQTTX, publish the following message to the target device's topic, e.g. modpoll/modsim001/set for device modsim001,

{
  "object_type": "holding_register",
  "address": 40001,
  "value": 12
}

Attention: you need to keep the modpoll tool running (subscriber) while you publish new values, open a new terminal, here is an example command using mosquitto_pub,

mosquitto_pub -h mqtt.eclipseprojects.io -t modpoll/modsim001/set -m "{\"object_type\":\"holding_register\",\"address\":40001,\"value\":12}"

After the message succesfully published, you will see the value changed in modpoll output.
image

Hope it helps.
Thanks for your interest for modpoll. Cheers.

Gavin

from modpoll.

gavinying avatar gavinying commented on May 28, 2024

BTW, you can find more details here in README.

from modpoll.

pythonlubo avatar pythonlubo commented on May 28, 2024

Hi Gavin, with your documentation i've no positive result on my RPi-system....

now I've check what journalctl says to published messages on the modpoll RPi.....

My Inverter has a Remote Shutdown Register : {"object_type": "holding_register", "address": 420, "value": 0} to swich off (..and "1" for on)

Modpoll has in .csv the lines:


device,wr1,1,,

poll,holding_register,400,50,BE_BE

ref,rs1,420,int16,rw # ( rs1 means remote switch 1 )


In mosquitto broker will publish the register in /hs36/wr/wr1/rs1/"1" (...for ON)

...works fine....

Now I published with mosquitto_pub from an other system:

mosquitto_pub -h xxx.xxx.xxx.xxx -p 1883 -t /hs36/wr/wr1/set -m "{"object_type": "holding_register", "address": 420, "value": 0}" #...for shut down the inverter...

journalctl shows an error:

Fail to parse json message: b'{object_type: holding_register, address: 420, value: 0}'


If I give the message without " ---- -m "{.........}" as {....}

Error Message from mosquitto:

Error: Unknown option 'holding_register,'.


If I give the message with -m '{....}'

It will break the modpoll completly....

AttributeError: 'ModbusIOExeption' object has no attribute 'function_code'


...what other solutions I've to test....?

Thanks for help....

from modpoll.

pythonlubo avatar pythonlubo commented on May 28, 2024

Hello again,
the right mosquitto_pub line is:

mosquitto_pub -h xxx.xxx.xxx.xxx -p 1883 -t /hs36/wr/wr1/set -m '{"object_type": "holding_register", "address": 406, "value": 1}'

(for example)

In journalctl i've see that the message arrive....after polling all csv-lines modpoll give the message:

  • Writing Register(s): device=wr1, address=406, value=1 -

...after that modpoll stops with errorcode:

return.result.function_code < 0x80
AttributError: 'ModbusIOException' object has no attribute 'function_code'

My Inverter need to write a register the functioncode 10H .....

modpoll has the possibility to give the function_code "10H" to the inverter ?

Thanks a lot.....

from modpoll.

gavinying avatar gavinying commented on May 28, 2024

Yes, modpoll does support "10H", which writes mutiple registers, but in your case, looks only writing a single register, which shall use function code "06".

In fact, modpoll supports the following function codes, fyi.

  • read coils (01)
  • read descrete inputs (02)
  • read holding registers (03)
  • read input registers (04)
  • write single coil (05)
  • write single register (06)
  • write multiple coils (15 or 0x0F)
  • write multiple registers (16 or 0x10)

Can you share the complete logs? including the command you used to start modpoll for further investigation.

from modpoll.

pythonlubo avatar pythonlubo commented on May 28, 2024

...now I try "minimalmodbus" to write the Inverter registers - it works fine....

The correct "minimalmodbus"-Line here is:

instrument.write_register(324, 560, 0, 16)

324 is the registeraddress
560 is the value without decimal - means 56.0 Volt finaly
0 - i dont know for what....
16 is the right command to write the register

I think modpoll should use the "16" command to write - not "10" or "6"....
Ii it possible to advise modpoll to use the 16 command for writing registers...?
tks.....

from modpoll.

gavinying avatar gavinying commented on May 28, 2024

Close it due to no activities for long time.

from modpoll.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.