• 大小: 41KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-18
  • 语言: C#
  • 标签: Panasonic  PLC  C#通信  

资源简介

上位机采用c# 语言与下位机松下PLC进行串口通信的动态库文件,包括多字,单字或者位的读取和写入,基本可以直接使用

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Windows.Forms;
using System.Threading;

namespace PanasonicPlc
{
    public class ComPort
    {
        private SerialPort Port= null;
        private int CmdIndex = 0;
        private bool bWriteOK = false bReadOK = false;
        public string bitStauts = ““ wordBitStauts = ““ WordValue = ““ tWordBitStauts = ““ formulaWordValue = ““;
        public int dataLength = 0;
        public string labNameStr = ““;
        public ComPort()
        { 
        }
        ~ComPort()
        {
            try
            {
                if (Port.IsOpen)
                {
                    Port.DataReceived -= new SerialDataReceivedEventHandler(OnDataRecv);
                    ClearBuffer();
                    Port.Close();
                    Port.Dispose();

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
            finally
            {

            }
        }
        public bool ComIsOpen()
        {
            if (Port != null)
            {
                return Port.IsOpen;
            }
            return false;
        }       
        public bool InitPort(string Nameint BaudRateParity Parityint DataBStopBits StopB)
        {
            try
            {
                Port = new SerialPort(Name BaudRate Parity DataB StopB);
                Port.WriteBufferSize = 2048;
                Port.ReadBufferSize = 2048;
                Port.RtsEnable = true;
                Port.NewLine = “\r“;
                Port.DataReceived += new SerialDataReceivedEventHandler(OnDataRecv);
                if (!Port.IsOpen)
                {
                    Port.Open();
                    ClearBuffer();
                    return true;
                }
                else
                    return false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
            finally
            {
            }
        }
        private void ClearBuffer()
        {
            Port.DiscardOutBuffer();
            Port.DiscardInBuffer();
        }
        private string XorSum(string str)
        {
            string strOrg = str.Trim();
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(strOrg);
            int Result = 0;
            int Temp = 0;
            for (int i = 0; i < strOrg.Length; i++)
            {
                Temp = bytes[i];
                Result = Result ^ Temp;
            }
            return Result.ToString(“X“);
        }
        private bool ReadOutTime(int Time)
        {
            int i = 0;
            while 

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

     文件       9216  2016-11-22 16:11  PanasonicPlc\bin\Debug\PanasonicPlc.dll

     文件      22016  2016-11-22 16:11  PanasonicPlc\bin\Debug\PanasonicPlc.pdb

     文件       9728  2013-01-29 16:21  PanasonicPlc\bin\x86\Debug\PanasonicPlc.dll

     文件      22016  2013-01-29 16:21  PanasonicPlc\bin\x86\Debug\PanasonicPlc.pdb

     文件      12866  2016-12-01 16:37  PanasonicPlc\ComPort.cs

     文件       6503  2013-05-30 14:39  PanasonicPlc\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件      29520  2017-12-23 22:29  PanasonicPlc\obj\Debug\PanasonicPlc.csproj.FileListAbsolute.txt

     文件       9728  2017-12-23 22:29  PanasonicPlc\obj\Debug\PanasonicPlc.dll

     文件      22016  2017-12-23 22:29  PanasonicPlc\obj\Debug\PanasonicPlc.pdb

     文件       6701  2018-02-03 11:40  PanasonicPlc\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件      10896  2018-03-15 13:10  PanasonicPlc\obj\x86\Debug\PanasonicPlc.csproj.FileListAbsolute.txt

     文件       1910  2018-03-15 13:10  PanasonicPlc\obj\x86\Debug\PanasonicPlc.csprojResolveAssemblyReference.cache

     文件       9728  2018-03-15 13:10  PanasonicPlc\obj\x86\Debug\PanasonicPlc.dll

     文件      24064  2018-03-15 13:10  PanasonicPlc\obj\x86\Debug\PanasonicPlc.pdb

     文件       4285  2013-01-29 16:30  PanasonicPlc\PanasonicPlc.csproj

     文件        143  2016-11-07 17:34  PanasonicPlc\PanasonicPlc.csproj.user

     文件       1356  2016-11-07 15:22  PanasonicPlc\Properties\AssemblyInfo.cs

     目录          0  2017-12-23 22:34  PanasonicPlc\obj\x86\Debug\TempPE

     目录          0  2018-02-03 11:36  PanasonicPlc\bin\x86\Debug

     目录          0  2016-11-07 17:34  PanasonicPlc\obj\Debug\TempPE

     目录          0  2018-03-15 13:10  PanasonicPlc\obj\x86\Debug

     目录          0  2018-02-03 11:36  PanasonicPlc\bin\Debug

     目录          0  2016-11-07 17:34  PanasonicPlc\bin\Release

     目录          0  2017-12-23 22:34  PanasonicPlc\bin\x64

     目录          0  2018-02-03 11:36  PanasonicPlc\bin\x86

     目录          0  2018-02-03 11:36  PanasonicPlc\obj\Debug

     目录          0  2016-11-07 17:34  PanasonicPlc\obj\Release

     目录          0  2018-02-03 11:36  PanasonicPlc\obj\x86

     目录          0  2018-02-03 11:36  PanasonicPlc\bin

     目录          0  2018-02-03 11:36  PanasonicPlc\obj

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

评论

共有 条评论