资源简介
这是一个物联网设备通讯协议实现客户端,将包括主流PLC通信读取、ModBus协议、Bacnet协议等常用工业通讯协议。
代码片段和文件信息
using IoTClient.Models;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Text;
using System.Threading;
namespace IoTClient
{
///
/// SerialPort基类
///
public abstract class SerialPortbase
{
///
/// 串行端口对象
///
protected SerialPort serialPort;
///
/// 是否自动打开关闭
///
protected bool isAutoOpen = true;
///
/// 获取设备上的COM端口集合
///
///
public static string[] GetPortNames()
{
return SerialPort.GetPortNames();
}
///
/// 连接
///
///
protected Result Connect()
{
var result = new Result();
serialPort?.Close();
try
{
serialPort.Open();
}
catch (Exception ex)
{
result.IsSucceed = false;
result.Err = ex.Message;
}
return result;
}
///
/// 打开连接
///
///
public Result Open()
{
isAutoOpen = false;
return Connect();
}
///
/// 关闭连接
///
///
protected Result Dispose()
{
var result = new Result();
try
{
serialPort.Close();
}
catch (Exception ex)
{
result.IsSucceed = false;
result.Err = ex.Message;
}
return result;
}
///
/// 关闭连接
///
///
public Result Close()
{
isAutoOpen = true;
return Dispose();
}
///
/// 读取
///
///
///
protected byte[] SerialPortRead(SerialPort serialPort)
{
//延时处理
if (serialPort.BytesToRead == 0) Thread.Sleep(20);
if (serialPort.BytesToRead == 0) Thread.Sleep(40);
if (serialPort.BytesToRead == 0) Thread.Sleep(80);
byte[] buffer = new byte[serialPort.BytesToRead];
var length = serialPort.Read(buffer 0 buffer.Length);
return buffer;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-09-11 07:41 IoTClient-master\
文件 4593 2020-09-11 07:41 IoTClient-master\.gitignore
目录 0 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\
目录 0 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\Helper\
文件 5203 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\Helper\CRCTests.cs
文件 1453 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\Helper\ConfigurationManager.cs
文件 1422 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\IoTClient.Tests.csproj
目录 0 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\ModBus\
文件 3000 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\ModBus\ModBusRtuClient_tests.cs
文件 3716 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\ModBus\ModBusTcpClient_tests.cs
目录 0 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\PLCTests\
文件 7693 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\PLCTests\SiemensClient_Tests.cs
目录 0 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\Server_tests\
文件 775 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\Server_tests\ModBusTcpServer_test.cs
文件 6198 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\SocketTempTests.cs
目录 0 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\TempTest\
文件 1887 2020-09-11 07:41 IoTClient-master\IoTClient.Tests\TempTest\temp.cs
目录 0 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\
文件 788 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\App.config
目录 0 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Common\
目录 0 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Common\Helper\
文件 1878 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Common\Helper\StringExtension.cs
目录 0 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Controls\
文件 9470 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Controls\BACnetControl.Designer.cs
文件 16123 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Controls\BACnetControl.cs
文件 5698 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Controls\BACnetControl.resx
文件 14191 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Controls\MQTTControl.Designer.cs
文件 7233 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Controls\MQTTControl.cs
文件 5698 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Controls\MQTTControl.resx
文件 20351 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Controls\MitsubishiMCControl.Designer.cs
文件 10483 2020-09-11 07:41 IoTClient-master\IoTClient.Tool\Controls\MitsubishiMCControl.cs
............此处省略112个文件信息
相关资源
- HMI-with-WPF-part-3-Communication-with-multipl
- C# 使用 TcpClient,Socket 聊天
- dotNetFx40LP_Client_x86_x64zh-Hans
-
C# Rest方式访问Hba
se Microsoft.Hba se - KeyBoardMaster 源码
- WpfVLC-master.rar
- jena_climate_2009_2016耶拿天气数据集
- C#通信TCP/IP server client 简单
- 一个简单完整的Socket通讯包括Server、
- C# WebSocket Client
- C#使用HttpClient
- asp.net mvc linq to sql 增删改查 基本操作
- C# TCP客户端和服务端编程
- C#网络五子棋server&client
- c#实现HttpClient拼接multipart/form-data形式
- C# Socket通讯框架,封装了Client和Serv
- Winform DataGridView中利用WebClient异步加载
- C# udp服务器收发、点对点收发
- C#版的FtpClient客户端Socket实现(可以登
- MSTSCLib.dll和MsTscAxWrapper.dll
- asp.net 模板包含master页
- c#文件发送一个服务器多个客户端
- c# MJPEG STREAM SERVER AND CLIENT
- 如何在WPF应用程序中通过HttpClient调用
- C#客服端与服务器通讯TcpClient和TcpLi
- C#编写Modbus TCP客户端程序
- SwitchClick.cs
- c#tcpClient发送和接收
- migomiddle-xms-master
- TCP_ServerAndClient.rar
评论
共有 条评论