• 大小: 78KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: C#
  • 标签: PLC  TCP/IP  C#  

资源简介

C#写的与PLC通过TCP/IP协议通信的实例,代码供参考

资源截图

代码片段和文件信息

using OPC;
using OPCDA;
using OPCDA.NET;

using System;
using System.Collections.Generic;
using System.Text;
using Interface;
using System.IO.Ports;
using System.Threading;
using System.Windows.Forms;
using CommonLibrary;
using System.IO;
using General;
using System.Net.Sockets;
using System.Net;
delegate void AddMessage(string sNewMessage);

namespace HostMainApp
{
    public class PLCControl : ILog IWafterControl
    {
        private Socket plc_sender = null;
       // private event AddMessage m_AddMessage;  
        private PLCCommu plcCommu = PLCCommu.Instance;
        //private System.IO.Ports.SerialPort plcSerialPort;
        private readonly object SendLockObj = new object();
        private readonly object waferIDObj = new object();

        private DefectType plsNotReadyType = DefectType.Hole2;
        private bool unloadTimeout = false;
        private bool isCheckWaferEnd = true;
        private bool isCheckUIRunEnd = true;
        private bool isClickStop = false;       //N0.39

        private int typeA1Count = 0;
        private int typeB1Count = 0;
        private int typeC1Count = 0;
        private int typeA2Count = 0;
        private int typeB2Count = 0;
        private int typeC2Count = 0;
        private int curIdleTime = 20;//N0.36
        //N0.00 private int typeDCount = 0;
        private int waferID = 1;
        private int curWaferCount = -300;
        private string reginfo = ““;

        private System.Timers.Timer timerWafer = new System.Timers.Timer();
        private System.Timers.Timer timerUIRun = new System.Timers.Timer();

        private float curExposureTime = 0.7F;

        private static PLCControl instance = null;
        private static readonly object plcLock = new object();
        public static PLCControl Instance
        {
            get
            {
                lock (plcLock)
                {
                    if (instance == null)
                    {
                        instance = new PLCControl();
                    }
                    return instance;
                }
            }
        }

        private PLCControl()
        {
         
            if (plcConnect())
             {             
                SystemLogger.Write(LogType.Debug “PLC连接成功!“ “Stage.InitThread“);
              }
            else
             {
                 SystemLogger.Write(LogType.Debug “PLC连接失败!“ “Stage.InitThread“);
             }
        }
        private bool plcConnect()
        {
            bool connectResult = true;
            try
            {
                if (plc_sender != null && plc_sender.Connected)
                {
                    plc_sender.Shutdown(SocketShutdown.Both);
                    System.Threading.Thread.Sleep(100);
                    plc_sender.Close();
                }
                plc_sender = new Socket(AddressFamily.InterNetwork SocketType.Stream Protoco

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2010-12-02 17:18  PlcConn_Tcp\
     目录           0  2010-12-17 16:44  PlcConn_Tcp\PlcConn_Tcp\
     文件         923  2010-11-29 08:10  PlcConn_Tcp\PlcConn_Tcp.sln
     文件       20992  2010-12-17 16:45  PlcConn_Tcp\PlcConn_Tcp.suo
     目录           0  2010-12-02 17:18  PlcConn_Tcp\PlcConn_Tcp\bin\
     目录           0  2010-12-02 17:18  PlcConn_Tcp\PlcConn_Tcp\bin\Debug\
     文件       32256  2010-12-03 10:05  PlcConn_Tcp\PlcConn_Tcp\bin\Debug\PlcConn_Tcp.exe
     文件       36352  2010-12-03 10:05  PlcConn_Tcp\PlcConn_Tcp\bin\Debug\PlcConn_Tcp.pdb
     文件       14328  2010-12-17 16:41  PlcConn_Tcp\PlcConn_Tcp\bin\Debug\PlcConn_Tcp.vshost.exe
     文件         490  2007-07-21 01:33  PlcConn_Tcp\PlcConn_Tcp\bin\Debug\PlcConn_Tcp.vshost.exe.manifest
     目录           0  2010-12-02 17:18  PlcConn_Tcp\PlcConn_Tcp\obj\
     目录           0  2010-12-03 09:56  PlcConn_Tcp\PlcConn_Tcp\obj\Debug\
     文件         688  2010-12-17 16:41  PlcConn_Tcp\PlcConn_Tcp\obj\Debug\PlcConn_Tcp.csproj.FileListAbsolute.txt
     文件         913  2010-12-01 13:53  PlcConn_Tcp\PlcConn_Tcp\obj\Debug\PlcConn_Tcp.csproj.GenerateResource.Cache
     文件       32256  2010-12-03 10:05  PlcConn_Tcp\PlcConn_Tcp\obj\Debug\PlcConn_Tcp.exe
     文件       36352  2010-12-03 10:05  PlcConn_Tcp\PlcConn_Tcp\obj\Debug\PlcConn_Tcp.pdb
     文件         180  2010-11-30 13:18  PlcConn_Tcp\PlcConn_Tcp\obj\Debug\PlcConn_Tcp.Properties.Resources.resources
     文件         180  2010-12-01 13:53  PlcConn_Tcp\PlcConn_Tcp\obj\Debug\PlcConn_Tcp.Test_PLC_Conn.resources
     目录           0  2010-12-02 17:18  PlcConn_Tcp\PlcConn_Tcp\obj\Debug\Refactor\
     目录           0  2010-12-02 17:18  PlcConn_Tcp\PlcConn_Tcp\obj\Debug\TempPE\
     文件       36729  2010-12-01 16:59  PlcConn_Tcp\PlcConn_Tcp\PLCCommu.cs
     文件        3847  2010-11-30 13:18  PlcConn_Tcp\PlcConn_Tcp\PlcConn_Tcp.csproj
     文件         511  2010-11-29 13:09  PlcConn_Tcp\PlcConn_Tcp\Program.cs
     目录           0  2010-12-02 17:18  PlcConn_Tcp\PlcConn_Tcp\Properties\
     文件        1442  2010-11-29 08:10  PlcConn_Tcp\PlcConn_Tcp\Properties\AssemblyInfo.cs
     文件        2851  2010-11-29 08:10  PlcConn_Tcp\PlcConn_Tcp\Properties\Resources.Designer.cs
     文件        5612  2010-11-29 08:10  PlcConn_Tcp\PlcConn_Tcp\Properties\Resources.resx
     文件        1096  2010-11-29 08:10  PlcConn_Tcp\PlcConn_Tcp\Properties\Settings.Designer.cs
     文件         249  2010-11-29 08:10  PlcConn_Tcp\PlcConn_Tcp\Properties\Settings.settings
     文件        9643  2010-12-17 16:44  PlcConn_Tcp\PlcConn_Tcp\Test_PLC_Conn.cs
     文件        7449  2010-12-01 13:53  PlcConn_Tcp\PlcConn_Tcp\Test_PLC_Conn.Designer.cs
............此处省略2个文件信息

评论

共有 条评论