Variables in Modbus SetRegisterS16


Recommended Posts


A few months ago you helped me with working how to talk to a modbus instrument - an SEW Modbus gateway to control motor speed. Just got back to lookling at this and have a small problem.

The code we used was


the first address is 4 and the three values are - 518 turns the motor on and the second value (10928) sets the speed with 16384 being equal to maximum speed which can be set to the actual max speed of the mote , in this case 1500 rpm so the 10928 is 1000 rpm, the third does not matter.

The above code works but I want to be able to vary the motor speed by changing a variable which is then sent to the controller e.g. to set it at 900 rpm the calculation

speed = 900/1500 * 16384 which would put speed = 9830 would be done and then the code would read


this doesn't work, gives me an error

C1000 Channel or function not found: MyStart Line 3 - Uncaught error in sequence MyStart

Any ideas?



Link to comment
Share on other sites

You can't put anything but constants inside of {} notation. What you need to do is use a variable for all three values. Something like this:

global myVar = {518,10928, 2730}

(use a better name than myVar)

then to write:


Now to change the second number, you just do:

myVar[1] = 9830

and call the device.movitrac..... code again

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.