• 大小: 4.92MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-22
  • 语言: C/C++
  • 标签:

资源简介

倍福TwinCAT3上位机与PLC通信测试(ADS通信) 包含C#和C++代码

程序介绍:https://www.cnblogs.com/JiYF/p/7780948.html
最底部有下载连接,不需要在这里下载

本次测试需要环境:

VS2013,TwinCAT3(本人版本TC31-Full-Setup.3.1.4018.16)

代码:C#代码,PLC程序代码,C++代码

测试部分:

测试包含:bool类型,int类型,long类型,real类型,lreal类型,string类型,数组,以及结构体 部分测试(这里没有结构体嵌套)

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//引用Twincat.ads和Sustem.IO
using TwinCAT.Ads;
using System.IO;


namespace writeread
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       
        //定义所需变量

        private bool  writebool =false;
        private bool  readbool=false ;

        private short  writeint = 0;
        private short  readint = 0;

        private int writelong = 0;
        private int readlong = 0;

        private float writereal = 0;
        private float readreal = 0;

        private double writelreal = 0;
        private double readlreal = 0;
        
        private string writestring = ““;
        private string readstring = ““;
        private int  stringlen = 0;

        //定义结构体类型
        public struct structtype
        {
            public  bool s1;
            public bool dummy1;
            public bool dummy2;
            public bool dummy3;
            public  short s2 ;
            public short dummy4;
                             
            public  int s3 ;
            public  float s4;
            public  double s5 ;
        }
        //实例化结构体
        private  structtype structtest =new structtype ();

        //定义数组,含有五个元素
        private short[] arraytest = new short[5];

        //定义句柄变量
        private int hvar = new int();
        //通讯数据定义
        private TcAdsClient tcclient;//定义通讯协议



        private void Form1_Load(object sender EventArgs e)
        {
            //通讯协议
            tcclient = new TcAdsClient();
            //tcclient.Connect(“控制器NetID“851)
            tcclient.Connect(851);
        }
        //writebool
        private void button1_Click(object sender EventArgs e)
        {
            if (writebool == true)
            {
                writebool = false;
            }
            else
            {
                writebool = true;
            }
            
            try
            {
                hvar = tcclient.CreateVariableHandle(“MAIN.BoolTest“);
                tcclient.WriteAny(hvar writebool );
                tcclient.DeleteVariableHandle(hvar);
            }
            catch (Exception err)
            {
                
            }

        }
        //readbool
        private void button2_Click(object sender EventArgs e)
        {
            try
            {
                hvar = tcclient.CreateVariableHandle(“MAIN.BoolTest“);
                readbool = (bool)(tcclient.ReadAny(hvar typeof(bool)));
                tcclient.DeleteVariableHandle(hvar);
                label1.Text = readbool.ToString();
            }
            catch (Exception err)
            {
               
            }
            
        }
        //writeINt   plc int 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     241664  2014-07-11 13:40  TC3_Ads_Samples\c#程序\writeread\writeread\bin\Debug\TwinCAT.Ads.dll

     文件     467103  2014-07-11 13:40  TC3_Ads_Samples\c#程序\writeread\writeread\bin\Debug\TwinCAT.Ads.xml

     文件      24064  2015-12-05 22:46  TC3_Ads_Samples\c#程序\writeread\writeread\bin\Debug\writeread.exe

     文件      44544  2015-12-05 22:46  TC3_Ads_Samples\c#程序\writeread\writeread\bin\Debug\writeread.pdb

     文件      22704  2017-11-03 09:35  TC3_Ads_Samples\c#程序\writeread\writeread\bin\Debug\writeread.vshost.exe

     文件        490  2012-06-06 02:06  TC3_Ads_Samples\c#程序\writeread\writeread\bin\Debug\writeread.vshost.exe.manifest

     文件      13794  2017-11-03 12:05  TC3_Ads_Samples\c#程序\writeread\writeread\Form1.cs

     文件      31936  2015-08-07 11:06  TC3_Ads_Samples\c#程序\writeread\writeread\Form1.Designer.cs

     文件       5814  2015-08-07 11:06  TC3_Ads_Samples\c#程序\writeread\writeread\Form1.resx

     文件       1231  2017-11-03 09:35  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6267  2017-11-01 10:50  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件      32768  2011-07-10 21:41  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\Interop.TcAdsDll.dll

     文件       4608  2015-06-09 15:55  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件       7736  2017-11-03 09:35  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\writeread.csproj.FileListAbsolute.txt

     文件        847  2015-08-07 11:06  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\writeread.csproj.GenerateResource.Cache

     文件        502  2011-07-10 21:41  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\writeread.csproj.ResolveComReference.cache

     文件       5756  2015-08-07 11:06  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\writeread.csprojResolveAssemblyReference.cache

     文件      24064  2015-12-05 22:46  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\writeread.exe

     文件        180  2015-08-07 11:06  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\writeread.Form1.resources

     文件      44544  2015-12-05 22:46  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\writeread.pdb

     文件        180  2015-08-07 11:06  TC3_Ads_Samples\c#程序\writeread\writeread\obj\Debug\writeread.Properties.Resources.resources

     文件        481  2011-07-10 20:59  TC3_Ads_Samples\c#程序\writeread\writeread\Program.cs

     文件       1446  2011-07-10 20:59  TC3_Ads_Samples\c#程序\writeread\writeread\Properties\AssemblyInfo.cs

     文件       2858  2015-06-09 15:55  TC3_Ads_Samples\c#程序\writeread\writeread\Properties\Resources.Designer.cs

     文件       5612  2011-07-10 20:59  TC3_Ads_Samples\c#程序\writeread\writeread\Properties\Resources.resx

     文件       1109  2015-06-09 15:55  TC3_Ads_Samples\c#程序\writeread\writeread\Properties\Settings.Designer.cs

     文件        249  2011-07-10 20:59  TC3_Ads_Samples\c#程序\writeread\writeread\Properties\Settings.settings

     文件       5015  2015-08-07 11:03  TC3_Ads_Samples\c#程序\writeread\writeread\writeread.csproj

     文件        452  2015-06-09 15:57  TC3_Ads_Samples\c#程序\writeread\writeread\writeread.csproj.user

     文件        917  2015-06-09 15:55  TC3_Ads_Samples\c#程序\writeread\writeread.sln

............此处省略103个文件信息

评论

共有 条评论

相关资源