資源簡介
基于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-29?16:34??遠程監控\
?????目錄???????????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
............此處省略198個文件信息
評論
共有 條評論