<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[C#与WinCC]]></title><description><![CDATA[C#与WinCC]]></description><link>https://bbs.novotific.com/category/8</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 21:24:29 GMT</lastBuildDate><atom:link href="https://bbs.novotific.com/category/8.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Jun 2021 14:52:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[C#实现Wincc声音报警]]></title><description><![CDATA[

本程序实现Wincc语音报警，自动读取WINCC组态的报警内容，然后实现语音报警。
附件：C#报警控件.rar]]></description><link>https://bbs.novotific.com/topic/59/c-实现wincc声音报警</link><guid isPermaLink="true">https://bbs.novotific.com/topic/59/c-实现wincc声音报警</guid><dc:creator><![CDATA[zhengqiqi]]></dc:creator><pubDate>Tue, 15 Jun 2021 14:52:23 GMT</pubDate></item><item><title><![CDATA[WinCE6.0与S7200SMART/S71200/S71500通讯DOME]]></title><description><![CDATA[

本成程序基于VS2008编写，目前已经打通S7通讯协议，可以成功PLC读取数据，属于半成品，主要面对自已开发OEM机器与设备。

本程序为DOME代码，集成S7通讯协议，在WinCE成功与S71200通讯，有兴趣的朋友可以一起研究。class MsgSocket
    {
        private Socket TCPSocket;
        private int _ReadTimeout = 2000;
        private int _WriteTimeout = 2000;
        private int _ConnectTimeout = 1000;
        public int LastError = 0;

        public MsgSocket()
        {
        }

        ~MsgSocket()
        {
            Close();
        }

        public void Close()
        {
            if (TCPSocket != null)
            {
                //TCPSocket.Dispose();
                TCPSocket = null;
            }
        }

        private void CreateSocket()
        {
            TCPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //TCPSocket.NoDelay = true;
        }

        private void TCPPing(string Host, int Port)
        {
            // To Ping the PLC an Asynchronous socket is used rather then an ICMP packet.
            // This allows the use also across Internet and Firewalls (obviously the port must be opened)           
            LastError = 0;
            Socket PingSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                //
                IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(Host), Port);
                //
                IAsyncResult result = PingSocket.BeginConnect(ipe, null, null);
                //bool success = result.AsyncWaitHandle.WaitOne(_ConnectTimeout, true);
                //if (!success)
                //{
                //    LastError = S7Consts.errTCPConnectionFailed;
                //}
            }
            catch
            {
                LastError = S7Consts.errTCPConnectionFailed;
            };
            PingSocket.Close();
        }

        public int Connect(string Host, int Port)
        {
            LastError = 0;
            if (!Connected)
            { 
                TCPPing(Host, Port);
                if (LastError == 0)
                try
                {
                        CreateSocket();
                    //
                        IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(Host), Port);
                    //

                        TCPSocket.Connect(ipe);
                }
                catch
                {
                        LastError = S7Consts.errTCPConnectionFailed;
                }
            }
            return LastError;
        }

        private int WaitForData(int Size, int Timeout)
        {
            bool Expired = false;
            int SizeAvail;
            int Elapsed = Environment.TickCount;
            LastError = 0;
            try
            {
                SizeAvail = TCPSocket.Available;
                while ((SizeAvail &lt; Size) &amp;&amp; (!Expired))
                {
                    Thread.Sleep(2);
                    SizeAvail = TCPSocket.Available;
                    Expired = Environment.TickCount - Elapsed &gt; Timeout;
                    // If timeout we clean the buffer
                    if (Expired &amp;&amp; (SizeAvail &gt; 0))
                    try
                    {
                        byte[] Flush = new byte;
                        TCPSocket.Receive(Flush, 0, SizeAvail, SocketFlags.None);
                    }
                    catch { }
                }
            }
            catch
            {
                LastError = S7Consts.errTCPDataReceive;
            }
            if (Expired)
            {
                LastError = S7Consts.errTCPDataReceive;
            }
            return LastError;
        }

        public int Receive(byte[] Buffer, int Start, int Size)
        {

            int BytesRead = 0;
            LastError = WaitForData(Size, _ReadTimeout);
            if (LastError == 0)
            {
                try
                {
                    BytesRead = TCPSocket.Receive(Buffer, Start, Size, SocketFlags.None);
                }
                catch
                {
                    LastError = S7Consts.errTCPDataReceive;
                }
                if (BytesRead == 0) // Connection Reset by the peer
                {
                    LastError = S7Consts.errTCPDataReceive;
                    Close();
                }
            }
            return LastError;
        }

        public int Send(byte[] Buffer, int Size)
        {
            LastError = 0;
            try
            {
                int BytesSent = TCPSocket.Send(Buffer, Size, SocketFlags.None);
            }
            catch
            {
                LastError = S7Consts.errTCPDataSend;
                Close();
            }
            return LastError;
        }

        public bool Connected
        {
            get
            {
                return (TCPSocket != null) &amp;&amp; (TCPSocket.Connected); 
            }
        }

        public int ReadTimeout
        {
            get
            {
                return _ReadTimeout;
            }
            set
            {
                _ReadTimeout = value;
            }
        }

        public int WriteTimeout
        {
            get
            {
                return _WriteTimeout;
            }
            set
            {
                _WriteTimeout = value;
            }

        }
        public int ConnectTimeout
        {
            get
            {
                return _ConnectTimeout;
            }
            set
            {
                _ConnectTimeout = value;
            }
        }
    }   
#endif附件：WindowsFormsApplication1.rar]]></description><link>https://bbs.novotific.com/topic/58/wince6.0与s7200smart-s71200-s71500通讯dome</link><guid isPermaLink="true">https://bbs.novotific.com/topic/58/wince6.0与s7200smart-s71200-s71500通讯dome</guid><dc:creator><![CDATA[zhengqiqi]]></dc:creator><pubDate>Tue, 15 Jun 2021 14:44:03 GMT</pubDate></item></channel></rss>