资源简介
基于C#的固定设备物联网小程序,采用OneNet平台进行通信,实测通过,分享出来,大家一起交流。
基于C#的固定设备物联网小程序,采用OneNet平台进行通信,实测通过,分享出来,大家一起交流。
基于C#的固定设备物联网小程序,采用OneNet平台进行通信,实测通过,分享出来,大家一起交流。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;
using System.IO.Ports;
using System.Net.Sockets;
using System.Net;
using System.Reflection;
using System.Collections.Specialized;
namespace Catcher
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timertemp1 = new System.Timers.Timer(2000);
timertemp1.AutoReset = true;
timertemp1.Elapsed += new System.Timers.ElapsedEventHandler(timertemp1_Elapsed);
CheckForIllegalCrossThreadCalls = false;
}
private System.Timers.Timer timertemp1;//面向设备定时器
void timertemp1_Elapsed(object sender System.Timers.ElapsedEventArgs e)
{
Ask();
Post();
}//定时器事件
private void Form1_Load(object sender EventArgs e)
{
}//界面载入
TcpClient tcpclient = new TcpClient();
bool zt = false;
#region 网络监听
public void conn()
{
try
{
int port = Convert.ToInt32(textBox2.Text);
tcpclient.Connect(IPAddress.Parse(textBox1.Text) port);
textBox6.Text = “已成功连接!“;
button1.Text = “断开“;
zt = true;
Thread threadRead = new Thread(Listingsever);
threadRead.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message “错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
}
}//网络连接
int[] received = new int[40];//int32串数组
string Creceived = null;//字符串数组
byte[] buffer = new byte[256];//字节接收缓存区
byte[] buffer1 = new byte[256];//转接字节数组
string[] aArray = new string[256];//显示数组
string state01 = “0“;
byte[] head = new byte[1];//接收信息头字符
public void Listingsever()
{
while (zt)
{
NetworkStream ns = tcpclient.GetStream();
ns = tcpclient.GetStream();
ns.Read(buffer 0 buffer.Length);
Creceived = System.Text.Encoding.ASCII.GetString(buffer) + “ “;//将字节流转为字符串
textBox4.Text = (“接收到的信息:“ + Creceived);//显示接收数据
state01 = Creceived.Substring(22 1);//从第23位开始截取1位 @@当前机柜状态值@@
head = System.Text.Encoding.ASCII.GetBytes(Creceived.Substring(0 1));//截取头字符
if (head[0] == 2)
{
if (state01 == “$“)
{
textBox3.Text = “off“;
}
else if (state01 == “#“)
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-11-23 14:06 远程监控\
目录 0 2018-11-23 14:06 远程监控\Catcher\
目录 0 2018-11-23 14:06 远程监控\Catcher\.git\
文件 2581 2018-11-23 10:40 远程监控\Catcher\.gitattributes
文件 4565 2018-11-23 10:40 远程监控\Catcher\.gitignore
文件 40 2018-11-23 10:40 远程监控\Catcher\.git\COMMIT_EDITMSG
文件 722 2018-11-23 10:40 远程监控\Catcher\.git\config
文件 73 2018-11-23 10:40 远程监控\Catcher\.git\desc
文件 23 2018-11-23 10:40 远程监控\Catcher\.git\HEAD
目录 0 2018-11-23 14:06 远程监控\Catcher\.git\hooks\
文件 478 2018-11-23 10:40 远程监控\Catcher\.git\hooks\applypatch-msg.sample
文件 896 2018-11-23 10:40 远程监控\Catcher\.git\hooks\commit-msg.sample
文件 3327 2018-11-23 10:40 远程监控\Catcher\.git\hooks\fsmonitor-watchman.sample
文件 189 2018-11-23 10:40 远程监控\Catcher\.git\hooks\post-update.sample
文件 424 2018-11-23 10:40 远程监控\Catcher\.git\hooks\pre-applypatch.sample
文件 1642 2018-11-23 10:40 远程监控\Catcher\.git\hooks\pre-commit.sample
文件 1348 2018-11-23 10:40 远程监控\Catcher\.git\hooks\pre-push.sample
文件 4898 2018-11-23 10:40 远程监控\Catcher\.git\hooks\pre-reba
文件 544 2018-11-23 10:40 远程监控\Catcher\.git\hooks\pre-receive.sample
文件 1239 2018-11-23 10:40 远程监控\Catcher\.git\hooks\prepare-commit-msg.sample
文件 3610 2018-11-23 10:40 远程监控\Catcher\.git\hooks\update.sample
文件 1318 2018-11-23 10:40 远程监控\Catcher\.git\index
目录 0 2018-11-23 14:06 远程监控\Catcher\.git\info\
文件 240 2018-11-23 10:40 远程监控\Catcher\.git\info\exclude
目录 0 2018-11-23 14:06 远程监控\Catcher\.git\logs\
文件 193 2018-11-23 10:40 远程监控\Catcher\.git\logs\HEAD
目录 0 2018-11-23 14:06 远程监控\Catcher\.git\logs\refs\
目录 0 2018-11-23 14:06 远程监控\Catcher\.git\logs\refs\heads\
文件 193 2018-11-23 10:40 远程监控\Catcher\.git\logs\refs\heads\master
目录 0 2018-11-23 14:06 远程监控\Catcher\.git\ob
目录 0 2018-11-23 14:06 远程监控\Catcher\.git\ob
............此处省略196个文件信息
相关资源
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
评论
共有 条评论