-
大小: 333KB文件類型: .zip金幣: 2下載: 1 次發(fā)布日期: 2022-06-11
- 語(yǔ)言: C#
- 標(biāo)簽: c#??onenet??物聯(lián)網(wǎng)??數(shù)據(jù)存儲(chǔ)??
資源簡(jiǎn)介
基于C#的固定設(shè)備物聯(lián)網(wǎng)小程序,采用OneNet平臺(tái)進(jìn)行通信,實(shí)測(cè)通過(guò),分享出來(lái),大家一起交流。
基于C#的固定設(shè)備物聯(lián)網(wǎng)小程序,采用OneNet平臺(tái)進(jìn)行通信,實(shí)測(cè)通過(guò),分享出來(lái),大家一起交流。
基于C#的固定設(shè)備物聯(lián)網(wǎng)小程序,采用OneNet平臺(tái)進(jìn)行通信,實(shí)測(cè)通過(guò),分享出來(lái),大家一起交流。

代碼片段和文件信息
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;//面向設(shè)備定時(shí)器
????????void?timertemp1_Elapsed(object?sender?System.Timers.ElapsedEventArgs?e)
????????{
????????????Ask();
????????????Post();
????????????
????????}//定時(shí)器事件
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????}//界面載入
????????TcpClient?tcpclient?=?new?TcpClient();
????????bool?zt?=?false;
????????#region?網(wǎng)絡(luò)監(jiān)聽(tīng)
????????public?void?conn()
????????{
????????????try
????????????{
????????????????int?port?=?Convert.ToInt32(textBox2.Text);
????????????????tcpclient.Connect(IPAddress.Parse(textBox1.Text)?port);
????????????????textBox6.Text?=?“已成功連接!“;
????????????????button1.Text?=?“斷開(kāi)“;
????????????????zt?=?true;
????????????????Thread?threadRead?=?new?Thread(Listingsever);
????????????????threadRead.Start();
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????MessageBox.Show(ex.Message?“錯(cuò)誤“?MessageBoxButtons.OK?MessageBoxIcon.Error);
????????????}
????????}//網(wǎng)絡(luò)連接
????????int[]?received?=?new?int[40];//int32串?dāng)?shù)組
????????string?Creceived?=?null;//字符串?dāng)?shù)組
????????byte[]?buffer?=?new?byte[256];//字節(jié)接收緩存區(qū)
????????byte[]?buffer1?=?new?byte[256];//轉(zhuǎn)接字節(jié)數(shù)組
????????string[]?aArray?=?new?string[256];//顯示數(shù)組
????????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)?+?“?“;//將字節(jié)流轉(zhuǎn)為字符串
????????????????textBox4.Text?=?(“接收到的信息:“?+?Creceived);//顯示接收數(shù)據(jù)
????????????????state01?=?Creceived.Substring(22?1);//從第23位開(kāi)始截取1位??@@當(dāng)前機(jī)柜狀態(tài)值@@
????????????????head?=?System.Text.Encoding.ASCII.GetBytes(Creceived.Substring(0?1));//截取頭字符
????????????????if?(head[0]?==?2)
????????????????{
????????????????????if?(state01?==?“$“)
????????????????????{
????????????????????????textBox3.Text?=?“off“;
????????????????????}
????????????????????else?if?(state01?==?“#“)
????????????????????{
???????????????????
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-11-23?14:06??遠(yuǎn)程監(jiān)控\
?????目錄???????????0??2018-11-23?14:06??遠(yuǎn)程監(jiān)控\Catcher\
?????目錄???????????0??2018-11-23?14:06??遠(yuǎn)程監(jiān)控\Catcher\.git\
?????文件????????2581??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.gitattributes
?????文件????????4565??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.gitignore
?????文件??????????40??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\COMMIT_EDITMSG
?????文件?????????722??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\config
?????文件??????????73??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\desc
?????文件??????????23??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\HEAD
?????目錄???????????0??2018-11-23?14:06??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\
?????文件?????????478??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\applypatch-msg.sample
?????文件?????????896??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\commit-msg.sample
?????文件????????3327??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\fsmonitor-watchman.sample
?????文件?????????189??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\post-update.sample
?????文件?????????424??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\pre-applypatch.sample
?????文件????????1642??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\pre-commit.sample
?????文件????????1348??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\pre-push.sample
?????文件????????4898??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\pre-reba
?????文件?????????544??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\pre-receive.sample
?????文件????????1239??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\prepare-commit-msg.sample
?????文件????????3610??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\hooks\update.sample
?????文件????????1318??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\index
?????目錄???????????0??2018-11-23?14:06??遠(yuǎn)程監(jiān)控\Catcher\.git\info\
?????文件?????????240??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\info\exclude
?????目錄???????????0??2018-11-23?14:06??遠(yuǎn)程監(jiān)控\Catcher\.git\logs\
?????文件?????????193??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\logs\HEAD
?????目錄???????????0??2018-11-23?14:06??遠(yuǎn)程監(jiān)控\Catcher\.git\logs\refs\
?????目錄???????????0??2018-11-23?14:06??遠(yuǎn)程監(jiān)控\Catcher\.git\logs\refs\heads\
?????文件?????????193??2018-11-23?10:40??遠(yuǎn)程監(jiān)控\Catcher\.git\logs\refs\heads\master
?????目錄???????????0??2018-11-23?14:06??遠(yuǎn)程監(jiān)控\Catcher\.git\ob
?????目錄???????????0??2018-11-23?14:06??遠(yuǎn)程監(jiān)控\Catcher\.git\ob
............此處省略196個(gè)文件信息
評(píng)論
共有 條評(píng)論