using libplctag;
using libplctag.DataTypes;
using Microsoft.VisualBasic;
namespace PLC_Communication
{
public partial class Form1 : Form
{
Tag<DintPlcMapper, int> N7;
Tag<RealPlcMapper, float> F8;
public Form1()
{
InitializeComponent();
N7 = new Tag<DintPlcMapper, int>()
{
Name = "N7:0",
Gateway = "192.168.1.1",
PlcType = PlcType.MicroLogix,
Protocol = Protocol.ab_eip,
Timeout = TimeSpan.FromSeconds(5)
};
F8 = new Tag<RealPlcMapper, float>()
{
Name = "F8:0",
Gateway = "192.168.1.1",
PlcType = PlcType.MicroLogix,
Protocol = Protocol.ab_eip,
Timeout = TimeSpan.FromSeconds(5)
};
Thread plcUpdateThread=new Thread(new ThreadStart(plcThread));
plcUpdateThread.Start();
}
void plcThread()
{
while (true)
{
F8.Read();
int temp = N7.Value;
float temp2=F8.Value;
tempField.Text = Convert.ToString(Convert.ToString(temp2));
dintField.Text = Convert.ToString(temp);
}
}
private void dintField_TextChanged(object sender, EventArgs e)
{
status.Text = "Value Update";
}
private void change2_Click(object sender, EventArgs e)
{
string input=Interaction.InputBox("Input Value", "Input new Value");
if(input != null)
{
int val;
if (Int32.TryParse(input, out val))
{
N7.Value = val;
N7.Write();
} else
{
MessageBox.Show("Invalid Input", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}