• 大小: 0.42M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-04-23
  • 语言: C#
  • 标签: INCA  例子  读写  程序  NC  

资源简介


资源截图

代码片段和文件信息

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;
using System.Runtime.InteropServices;


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 ;
        }
        //定义结构体类型
        [StructLayout(LayoutKind.Sequential Pack = 1)]
        public struct structtype1
        {
            [MarshalAs(UnmanagedType.I1)]
            public bool s1;
           // [MarshalAs(UnmanagedType.I2)]
            public short s2;
          //  [MarshalAs(UnmanagedType.I4)]
            public int s3;
          //  [MarshalAs(UnmanagedType.R4)]
            public float s4;
          //  [MarshalAs(UnmanagedType.R8)]
            public double s5;
        }

        //实例化结构体
        private  structtype structtest =new structtype ();
        private structtype1 structtest1 = new structtype1();

        //定义数组,含有五个元素
        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(“192.168.1.107.1.1“851);
            int i = 0;
        }
        //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 er

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

    ..A..H.     57856  2021-01-06 15:20  c#程序\writeread\.vs\writeread\v14\.suo

    ..A..H.     57856  2020-12-30 17:19  c#程序\writeread\.vs\writeread\v15\.suo

     文件          0  2020-12-30 17:19  c#程序\writeread\.vs\writeread\v15\Server\sqlite3\db.lock

     文件       4096  2020-12-30 17:19  c#程序\writeread\.vs\writeread\v15\Server\sqlite3\storage.ide

     文件      32768  2020-12-30 17:19  c#程序\writeread\.vs\writeread\v15\Server\sqlite3\storage.ide-shm

     文件     593312  2020-12-30 17:19  c#程序\writeread\.vs\writeread\v15\Server\sqlite3\storage.ide-wal

     文件     401408  2017-07-26 08:31  c#程序\writeread\writeread\bin\Debug\TwinCAT.Ads.dll

     文件    1226008  2017-07-26 08:31  c#程序\writeread\writeread\bin\Debug\TwinCAT.Ads.xml

     文件      27136  2019-12-02 11:00  c#程序\writeread\writeread\bin\Debug\writeread.exe

     文件      36352  2019-12-02 11:00  c#程序\writeread\writeread\bin\Debug\writeread.pdb

     文件      21680  2021-01-06 15:18  c#程序\writeread\writeread\bin\Debug\writeread.vshost.exe

     文件        490  2019-03-19 12:46  c#程序\writeread\writeread\bin\Debug\writeread.vshost.exe.manifest

     文件      15074  2020-07-27 09:09  c#程序\writeread\writeread\Form1.cs

     文件      40119  2018-12-23 13:50  c#程序\writeread\writeread\Form1.Designer.cs

     文件       6181  2018-12-23 13:50  c#程序\writeread\writeread\Form1.resx

     文件       1209  2020-12-17 09:18  c#程序\writeread\writeread\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6222  2021-01-06 15:18  c#程序\writeread\writeread\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

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

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

     文件         42  2020-12-30 17:18  c#程序\writeread\writeread\obj\Debug\writeread.csproj.CoreCompileInputs.cache

     文件      10430  2021-01-06 15:18  c#程序\writeread\writeread\obj\Debug\writeread.csproj.FileListAbsolute.txt

     文件        847  2018-12-23 13:50  c#程序\writeread\writeread\obj\Debug\writeread.csproj.GenerateResource.Cache

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

     文件      21081  2020-12-30 17:18  c#程序\writeread\writeread\obj\Debug\writeread.csprojAssemblyReference.cache

     文件       3771  2019-12-02 11:00  c#程序\writeread\writeread\obj\Debug\writeread.csprojResolveAssemblyReference.cache

     文件      27136  2019-12-02 11:00  c#程序\writeread\writeread\obj\Debug\writeread.exe

     文件        180  2019-12-02 11:00  c#程序\writeread\writeread\obj\Debug\writeread.Form1.resources

     文件      36352  2019-12-02 11:00  c#程序\writeread\writeread\obj\Debug\writeread.pdb

     文件        180  2019-12-02 11:00  c#程序\writeread\writeread\obj\Debug\writeread.Properties.Resources.resources

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

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

评论

共有 条评论