本文的网络地址为:http://www.cnblogs.com/dathlin/p/8723961.html
using HslCommunication;
using HslCommunication.Profinet.Omron;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
private OmronFinsNet omronFinsNet ;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
omronFinsNet = new OmronFinsNet("192.168.250.1", 9600);
omronFinsNet.SA1 = 34; // PC网络号,PC的IP地址的最后一个数
omronFinsNet.DA1 = 0x01; // PLC网络号,PLC的IP地址的最后一个数
omronFinsNet.DA2 = 0x00; // PLC单元号,通常为0
OperateResult connect = omronFinsNet.ConnectServer();
if (connect.IsSuccess)
{
MessageBox.Show("连接成功");
}
else
{
MessageBox.Show("连接失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
System.Diagnostics.Stopwatch stopwathch = new System.Diagnostics.Stopwatch();
stopwathch.Start();
short short_D100 = omronFinsNet.ReadInt16("D300").Content;
stopwathch.Stop();
TimeSpan timeSpan = stopwathch.Elapsed;
double mimilliseconds = timeSpan.TotalMilliseconds;
textBox3.Text = short_D100.ToString();
textBox2.Text = mimilliseconds.ToString();
}
}
}