基本信息
源码名称:c#与Omron通讯(通过Fins命令读写Omron PLC)
源码大小:1.59M
文件格式:.rar
开发语言:C#
更新时间:2019-05-28
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
2. 运行"OPC动态库注册"里的install.exe,会自动注册相关的PLC动态库。
3. 这样,就可以运行软件了。
使用前,使用说明:
1. 请安装OMRON SYSMAC OPC Server V2 FinsGateway 2003. 并在TCP处添加相应的PLC地址,然后加载AMP.sdb(打开过一次即可)。2. 运行"OPC动态库注册"里的install.exe,会自动注册相关的PLC动态库。
3. 这样,就可以运行软件了。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pro_Fins.PublicClass;
namespace Pro_Fins
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private Common common = new Common();
private OmronPLC omronPLC = new OmronPLC();
public string[] PLCAdrress = null; //PLC服务器地址
private string readplc(int PLCAdrressIndex)
{
return omronPLC.ReadPLC(PLCAdrressIndex - 1); //习惯从1排,故这样写
}
private bool writeplc(int PLCAdrressIndex, object value)
{
return omronPLC.WritePLC(PLCAdrressIndex - 1, value); //习惯从1排,故这样写
}
private void button1_Click(object sender, EventArgs e)
{
string[] opcServerNames = null;
opcServerNames = omronPLC.getOpcServerNames();
if (opcServerNames != null)
{
for (int i = 0; i <= opcServerNames.Length - 1; i )
{
cbbPLC.Items.Add(opcServerNames[i]);
}
if (cbbPLC.Items.Count > 0)
{
cbbPLC.SelectedIndex = 0;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
//连接PLC
if (omronPLC.ConnectOpcServer(cbbPLC.Text) == false)
{
MessageBox.Show("连接Omron PLC服务器失败!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
//初始化PLC数据标签项
PLCAdrress = new string[15];
PLCAdrress[0] = "IP13.WR.FZJC01";
PLCAdrress[1] = "IP13.WR.FZJC02";
PLCAdrress[2] = "IP13.WR.FZJC03";
PLCAdrress[3] = "IP13.WR.FZJC04";
PLCAdrress[4] = "IP13.WR.FZJC05";
PLCAdrress[5] = "IP13.WR.FZJC06";
PLCAdrress[6] = "IP13.WR.FZJC07";
PLCAdrress[7] = "IP13.WR.FZJC08";
PLCAdrress[8] = "IP13.WR.FZJC09";
PLCAdrress[9] = "IP13.WR.FZJC10";
PLCAdrress[10] = "IP13.WR.FZJC11";
PLCAdrress[11] = "IP13.WR.FZJC12";
PLCAdrress[12] = "IP13.WR.FZJC13";
PLCAdrress[13] = "IP13.WR.FZJC14";
PLCAdrress[14] = "IP13.WR.FZJC15";
omronPLC.CreateOpcGroup(PLCAdrress); //创建组与标签项
}
private void button3_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
for (int i = 1; i <= 15; i )
{
listBox1.Items.Add("变量" i.ToString() "=" readplc(i));
}
listBox1.Items.Add("读完毕!!");
}
private void button4_Click(object sender, EventArgs e)
{
writeplc(2, 1); //扫码完成=0
writeplc(5, 0); //是不是零度位置=0
writeplc(7, 0); //读取零度角度完成=0
writeplc(11, 90.5); //旋转数据读取完成=0
writeplc(12, 0); //旋转角度读取次数=0
writeplc(13, 0); //全部数据读取完毕=0
writeplc(14, 0); //是不是合格1=0
writeplc(15, 0); //是不是合格2=0
}
}
}