资源简介

采用C#开发的,跟松下PLC通讯的标准模块,可置位寄存器,读取寄存器,和写入数据到寄存器

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO.Ports;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    class PLC
    {
        /// 
        /// 速美达自动化 郑茂强
        /// zhenggong@126.com
        /// 

        //触点 X、Y、R
        //数据寄存器 D
        /*-----读取单触点状态[RCS] (XYR)------
         * 例:读取Y1
         * 发送:%01#RCSY0001**[CR]
         * 返回:%01$RC1**[CR]
         * 0=“off“1=“on“
         * ----------------------*/
        /*-----写入单触点状态[WCS] (XYR)------
         * 例:写入Y1=“on“
         * 发送:%01#WCSY00011**[CR]
         * 返回:%01$WC**[CR]
         * ----------------------*/
        /*-----读取多触点状态[RCP] (XYR)------
         * 例:读取Y1-Y3
         * 发送:%01#RCP3Y0001R0001Y0003T0099**[CR]
         * 返回:%01$RC1011**[CR]
         * 0=“off“1=“on“
         * ----------------------*/
        /*-----读取Word型触点状态[RCC] (XYR)------
         * 例:读取Y1-Y3
         * 发送:%01#RCCY00010003**[CR]
         * 返回:%01$RC34127856BC9A**[CR]
         * ----------------------*/
        /*-----写入多触点状态[WCP] (XYR)------
         * 例:写入Y1-Y3为on
         * 发送:%01#WCP3Y00011R00021Y00031**[CR]
         * 返回:%01$WC**[CR]
         * 0=“off“1=“on“
         * ----------------------*/
        /*-----读取DT数据[RD]---------------
         *例:读取D1105-D1107的内容
         *发送:%01#RDD011050110757[CR]
         *返回:%01$RD630044330A0062[CR]
         *值:D1105=0063HD1106=3344HD1107=000AH
         *----------------------*/
        /*-----写入DT数据[WD]----------------
         * 例:写入数据到D1-D13 D1=0005HD2=1507HD=0900H
         * 发送:%01%WDD00001000030500071500095D[CR]
         * 返回:%01$WD13[CR]
         *----------------------*/
        public static TextBox txtCommLog = new TextBox();
        public static SerialPort COMM = new SerialPort();
        public static double[] DTValue = null;
        public static System.Collections.BitArray [] arrXYMValue = null;
        public static int iDelay = 60;
        public static bool Open(string strPort)
        {
            try
            {
                if (COMM.IsOpen)
                {
                    COMM.Close();
                }
                COMM.PortName = strPort;
                COMM.BaudRate = 19200;
                COMM.Parity = Parity.Even;
                COMM.DataBits = 7;
                COMM.StopBits = StopBits.One;
                COMM.NewLine = “\r\n“; 
                COMM.DataReceived += new SerialDataReceivedEventHandler(OnDataReceived);
                COMM.Open();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }

        }
        public static void Close()
        {
            if (COMM.IsOpen)
            {
                COMM.Close();
            }
        }
        private delegate void SetTextCallback(string text);
        private static vo

评论

共有 条评论