Page 1 of 1

Read MODBUS controller register from script without tags

Posted: Wed Jan 29, 2014 3:30 am
by iorthree
Hello,
our application needs to read multiple modbus address pools from different modbus slave controllers.

Due to that it is very hard to instance hundreds of tags and then use huges "switch-cases" structures to parse them since we need to "switch the contest" among the devices from the same screen without using a screen for each controller.
The question is:
Is there any way to index a specific modbus address (for read/write) from scripting?
We need to do something like a baseaddress+offset indirect addressing.

thanks very much.

Re: Read MODBUS controller register from script without tags

Posted: Fri Apr 25, 2014 3:40 pm
by stuartm

Code: Select all

public void SetTag(string tagName, VariantValue val) {

			// Use reflection to find everything about Tags class in memory
			Type tagType = Globals.Tags.GetType();
			// Must have an instance in memory to write to otherwise it cannot write to a class directly
			var tag = (GlobalDataItem)tagType.GetProperty( tagName ).GetValue(Globals.Tags, null);
			tag.Value = val;

		}

		void Button_Click(System.Object sender, System.EventArgs e)
		{

			SetTag("Tag1", 5);
		}