PyModbus Updating Server can't write or read registers










0















I am using this exakt example: https://pymodbus.readthedocs.io/en/v2.1.0/source/example/updating_server.html except changing 'localhost' to the IP adress of the Raspberrypi the program is running on.



The server is up and running, and I can connect to my windows client software (QModMaster).
The code adds "1" to the registers up every 5 seconds.
I tried to read every register (Holding, Coils, Input, Discrete), but I always get the same starting value, "17".
Here's what the shell puts out:



RESTART: /home/pi/Documents/Tests/PythonModbus/pymodbus-master/examples/common/TestUpdatingserver.py
INFO:pymodbus.server.async:Starting Modbus TCP Server on 10.21.39.27:5020
DEBUG:pymodbus.server.async:Running in Main thread
DEBUG:pymodbus.server.async:Client Connected [IPv4Address(type='TCP', host='10.21.39.27', port=5020)]
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [18, 18, 18, 18, 18]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [19, 19, 19, 19, 19]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5
DEBUG:pymodbus.server.async:Data Received: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x0 0x0 0x5
DEBUG:pymodbus.framer.socket_framer:Processing: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x0 0x0 0x5
DEBUG:pymodbus.factory:Factory Request[3]
DEBUG:pymodbus.datastore.context:validate[3] 1:5
DEBUG:pymodbus.datastore.context:getValues[3] 1:5
DEBUG:pymodbus.server.async:send: b'00010000000d01030a00110011001100110011'
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [20, 20, 20, 20, 20]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5


and so on....



Could anybody help me or tell me where/in which registers the program writes the values and how I can properly write/read holding registers?



I think it has something to do with this block of code under the updating_writer function from the example, especially with register = 3, but I cannot really grasp what it does. I started diving into the logging module, but It I found it to be a little too complex for me as a beginner:



log.debug("updating the context")
context = a[0]
register = 3
slave_id = 0x00
address = 0x10
values = context[slave_id].getValues(register, address, count=5)
values = [v + 1 for v in values]
log.debug("new values: " + str(values))
context[slave_id].setValues(register, address, values)


Any help is appreciated!










share|improve this question






















  • If you want to read a register from a modbus-slave device, you should use the ModbusTcpClient. Look at here.

    – Benyamin Jafari
    Nov 18 '18 at 7:50















0















I am using this exakt example: https://pymodbus.readthedocs.io/en/v2.1.0/source/example/updating_server.html except changing 'localhost' to the IP adress of the Raspberrypi the program is running on.



The server is up and running, and I can connect to my windows client software (QModMaster).
The code adds "1" to the registers up every 5 seconds.
I tried to read every register (Holding, Coils, Input, Discrete), but I always get the same starting value, "17".
Here's what the shell puts out:



RESTART: /home/pi/Documents/Tests/PythonModbus/pymodbus-master/examples/common/TestUpdatingserver.py
INFO:pymodbus.server.async:Starting Modbus TCP Server on 10.21.39.27:5020
DEBUG:pymodbus.server.async:Running in Main thread
DEBUG:pymodbus.server.async:Client Connected [IPv4Address(type='TCP', host='10.21.39.27', port=5020)]
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [18, 18, 18, 18, 18]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [19, 19, 19, 19, 19]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5
DEBUG:pymodbus.server.async:Data Received: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x0 0x0 0x5
DEBUG:pymodbus.framer.socket_framer:Processing: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x0 0x0 0x5
DEBUG:pymodbus.factory:Factory Request[3]
DEBUG:pymodbus.datastore.context:validate[3] 1:5
DEBUG:pymodbus.datastore.context:getValues[3] 1:5
DEBUG:pymodbus.server.async:send: b'00010000000d01030a00110011001100110011'
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [20, 20, 20, 20, 20]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5


and so on....



Could anybody help me or tell me where/in which registers the program writes the values and how I can properly write/read holding registers?



I think it has something to do with this block of code under the updating_writer function from the example, especially with register = 3, but I cannot really grasp what it does. I started diving into the logging module, but It I found it to be a little too complex for me as a beginner:



log.debug("updating the context")
context = a[0]
register = 3
slave_id = 0x00
address = 0x10
values = context[slave_id].getValues(register, address, count=5)
values = [v + 1 for v in values]
log.debug("new values: " + str(values))
context[slave_id].setValues(register, address, values)


Any help is appreciated!










share|improve this question






















  • If you want to read a register from a modbus-slave device, you should use the ModbusTcpClient. Look at here.

    – Benyamin Jafari
    Nov 18 '18 at 7:50













0












0








0


1






I am using this exakt example: https://pymodbus.readthedocs.io/en/v2.1.0/source/example/updating_server.html except changing 'localhost' to the IP adress of the Raspberrypi the program is running on.



The server is up and running, and I can connect to my windows client software (QModMaster).
The code adds "1" to the registers up every 5 seconds.
I tried to read every register (Holding, Coils, Input, Discrete), but I always get the same starting value, "17".
Here's what the shell puts out:



RESTART: /home/pi/Documents/Tests/PythonModbus/pymodbus-master/examples/common/TestUpdatingserver.py
INFO:pymodbus.server.async:Starting Modbus TCP Server on 10.21.39.27:5020
DEBUG:pymodbus.server.async:Running in Main thread
DEBUG:pymodbus.server.async:Client Connected [IPv4Address(type='TCP', host='10.21.39.27', port=5020)]
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [18, 18, 18, 18, 18]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [19, 19, 19, 19, 19]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5
DEBUG:pymodbus.server.async:Data Received: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x0 0x0 0x5
DEBUG:pymodbus.framer.socket_framer:Processing: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x0 0x0 0x5
DEBUG:pymodbus.factory:Factory Request[3]
DEBUG:pymodbus.datastore.context:validate[3] 1:5
DEBUG:pymodbus.datastore.context:getValues[3] 1:5
DEBUG:pymodbus.server.async:send: b'00010000000d01030a00110011001100110011'
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [20, 20, 20, 20, 20]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5


and so on....



Could anybody help me or tell me where/in which registers the program writes the values and how I can properly write/read holding registers?



I think it has something to do with this block of code under the updating_writer function from the example, especially with register = 3, but I cannot really grasp what it does. I started diving into the logging module, but It I found it to be a little too complex for me as a beginner:



log.debug("updating the context")
context = a[0]
register = 3
slave_id = 0x00
address = 0x10
values = context[slave_id].getValues(register, address, count=5)
values = [v + 1 for v in values]
log.debug("new values: " + str(values))
context[slave_id].setValues(register, address, values)


Any help is appreciated!










share|improve this question














I am using this exakt example: https://pymodbus.readthedocs.io/en/v2.1.0/source/example/updating_server.html except changing 'localhost' to the IP adress of the Raspberrypi the program is running on.



The server is up and running, and I can connect to my windows client software (QModMaster).
The code adds "1" to the registers up every 5 seconds.
I tried to read every register (Holding, Coils, Input, Discrete), but I always get the same starting value, "17".
Here's what the shell puts out:



RESTART: /home/pi/Documents/Tests/PythonModbus/pymodbus-master/examples/common/TestUpdatingserver.py
INFO:pymodbus.server.async:Starting Modbus TCP Server on 10.21.39.27:5020
DEBUG:pymodbus.server.async:Running in Main thread
DEBUG:pymodbus.server.async:Client Connected [IPv4Address(type='TCP', host='10.21.39.27', port=5020)]
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [18, 18, 18, 18, 18]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [19, 19, 19, 19, 19]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5
DEBUG:pymodbus.server.async:Data Received: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x0 0x0 0x5
DEBUG:pymodbus.framer.socket_framer:Processing: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x0 0x0 0x5
DEBUG:pymodbus.factory:Factory Request[3]
DEBUG:pymodbus.datastore.context:validate[3] 1:5
DEBUG:pymodbus.datastore.context:getValues[3] 1:5
DEBUG:pymodbus.server.async:send: b'00010000000d01030a00110011001100110011'
DEBUG:root:updating the context
DEBUG:pymodbus.datastore.context:getValues[3] 17:5
DEBUG:root:new values: [20, 20, 20, 20, 20]
DEBUG:pymodbus.datastore.context:setValues[3] 17:5


and so on....



Could anybody help me or tell me where/in which registers the program writes the values and how I can properly write/read holding registers?



I think it has something to do with this block of code under the updating_writer function from the example, especially with register = 3, but I cannot really grasp what it does. I started diving into the logging module, but It I found it to be a little too complex for me as a beginner:



log.debug("updating the context")
context = a[0]
register = 3
slave_id = 0x00
address = 0x10
values = context[slave_id].getValues(register, address, count=5)
values = [v + 1 for v in values]
log.debug("new values: " + str(values))
context[slave_id].setValues(register, address, values)


Any help is appreciated!







python server client cpu-registers pymodbus






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 10:17









j.frankj.frank

1




1












  • If you want to read a register from a modbus-slave device, you should use the ModbusTcpClient. Look at here.

    – Benyamin Jafari
    Nov 18 '18 at 7:50

















  • If you want to read a register from a modbus-slave device, you should use the ModbusTcpClient. Look at here.

    – Benyamin Jafari
    Nov 18 '18 at 7:50
















If you want to read a register from a modbus-slave device, you should use the ModbusTcpClient. Look at here.

– Benyamin Jafari
Nov 18 '18 at 7:50





If you want to read a register from a modbus-slave device, you should use the ModbusTcpClient. Look at here.

– Benyamin Jafari
Nov 18 '18 at 7:50












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297780%2fpymodbus-updating-server-cant-write-or-read-registers%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297780%2fpymodbus-updating-server-cant-write-or-read-registers%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3