Read MODBUS controller register from script without tags

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
iorthree
Posts: 2
Joined: Mon Jan 27, 2014 4:41 am

Read MODBUS controller register from script without tags

Post 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.

stuartm
Posts: 61
Joined: Thu Jun 06, 2013 9:21 am

Re: Read MODBUS controller register from script without tags

Post 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);
		}

Post Reply