Reply To: Communication of Allen Bradley PLC and Visual Studio C#

#1360
Fred Graham
Fred Graham
Keymaster
  • Topics: 13
  • Replies: 158
  • Total Posts: 171

Hi Sefa and welcome to the forums!

Okay, you’ve decided on Ingear drivers to access a PLC directly versus OPC (I’m assuming Logix here as you’ve not stated). I’m sure as you can imagine the “second step” you’ve listed here is a little bit too broad for any forum. Perhaps I can get you going at least on the reading and writing of a tag. The following code sample will show you a basic workflow for reading/writing a tag regardless if you’re using WinForms, WPF, ASP.NET etc.

// Simple Read Tag Logic

// create instance of Tag class and immediately read
Tag ControlLogixTag = new Tag(ControlLogix, tagname);

if (ControlLogixTag.QualityCode == Logix.ResultCode.QUAL_GOOD)
{
string Value = ControlLogixTag.Value.ToString());
}
else
// display the error
string errorString = ControlLogixTag.ErrorString;

//Simple Write Tag Logic

// create instance of Tag class and immediately read
Tag ControlLogixTag = new Tag(ControlLogix, tagname);

/// update the .Value property
ControlLogixTag.Value = someValueYouWantToAssign;

ControlLogixTag.Length = 1;

if (Logix.WriteTag(ControlLogixTag) !=ResultCode.E_SUCCESS)
{
// Throw a failed to write message – only enters this “if statement” if the PLC write fails
}

Hope that helps!