版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
項目十基于WSN技術(shù)的智能倉儲環(huán)境監(jiān)測與智能控制系統(tǒng)設(shè)計與實現(xiàn)一、教學(xué)目標(biāo)掌握WSN網(wǎng)關(guān)通信的相關(guān)應(yīng)用。掌握WSN實現(xiàn)了信息的采集、信息傳輸和信息處理模式。掌握WSN實現(xiàn)倉儲環(huán)境監(jiān)控智能化技術(shù)方法。二、教學(xué)內(nèi)容10.1設(shè)備簡介10.1.1WSN網(wǎng)關(guān)圖10-1WSN網(wǎng)關(guān)圖供電電源:DC5V,信號獲取接口:USB,上位機通信接口:以太網(wǎng)口,操作系統(tǒng):Linux。網(wǎng)關(guān)通過USB與協(xié)調(diào)器連接,并通過協(xié)調(diào)器與各Zigbee節(jié)點進行信號通訊。10.1.2協(xié)調(diào)器圖10-2協(xié)調(diào)器圖供電方式:USB供電。該設(shè)備為網(wǎng)關(guān)與各傳感器節(jié)點的中繼,負(fù)責(zé)轉(zhuǎn)發(fā)Zigbee信號。10.1.3溫濕度傳感器模塊圖10-3溫濕度傳感模塊圖供電方式:DC5V,通訊協(xié)議:Zigbee。集成模塊:溫濕度傳感器。該節(jié)點可采集溫濕度數(shù)據(jù),并通過Zigbee協(xié)議傳輸?shù)骄W(wǎng)關(guān),上位機通過訪問網(wǎng)關(guān)獲取溫濕度數(shù)據(jù)。10.1.4電磁繼電器模塊圖10-4電磁繼電器模塊圖供電方式:DC5V,繼電器控制路數(shù):4路,與網(wǎng)關(guān)通信協(xié)議:Zigbee。該繼電器可控制四路電源,在京勝世紀(jì)的實驗臺中,控制了兩路燈光、一路風(fēng)扇和一路電磁門。10.2類的設(shè)計與實現(xiàn)在本部分實訓(xùn)中我們要用到數(shù)據(jù)庫來存儲當(dāng)前各個節(jié)點的信息,以面向?qū)ο蟮乃枷霝槔?我們需要先編寫幾對數(shù)據(jù)庫操作的基礎(chǔ)類和將節(jié)點信息保存的對象類。10.2.1DBConnection.cs類這個類文件是要對數(shù)據(jù)庫進行連接操作,登錄到本地的數(shù)據(jù)庫。引用命名空間。該命名空間是SQLServer.NET數(shù)據(jù)提供者,是SQLServer專用的內(nèi)置.NET提供者,引用該命名空間后就可以獲得最好的性能和對基礎(chǔ)功能的最直接訪問。usingSystem.Data.SqlClient;添加變量 privatestringstr;privateSqlCommandsqlcom;privateSqlConnectionconn;在構(gòu)造函數(shù)中寫入連接數(shù)據(jù)庫方法///<summary>///連接數(shù)據(jù)庫的方法///</summary>publicDBConnection(){//定義了要連接的數(shù)據(jù)庫的位置,數(shù)據(jù)庫的名稱,登錄帳號和密碼this.str="Server=localhost;DataBase=SmartShelfD;uid=sa;pwd=123";this.conn=newSqlConnection(str);this.sqlcom=newSqlCommand();this.sqlcom.Connection=this.conn;this.conn.Open();}上邊定義了兩個全局變量,分變是字符型str,變量量為數(shù)據(jù)庫連接字符串內(nèi)容:Server表示正在訪問的數(shù)據(jù)庫服務(wù)器名稱,其格式是“計算機名\實例名”,如果是本地的數(shù)據(jù)庫服務(wù)器并且使用的是SQLServer的默認(rèn)實例名,則可以使用(Local)或.來表示。DataBase表示數(shù)據(jù)庫名稱,即該項目所要連接的數(shù)據(jù)庫名;Uid表示數(shù)據(jù)庫服務(wù)器的登錄名稱;Pwd表示數(shù)據(jù)庫服務(wù)器的密碼。返回數(shù)據(jù)連接方法///<summary>///返回數(shù)據(jù)連接方法///</summary>///<returns></returns>publicSqlConnectionGetConnection(){returnthis.conn;}10.2.2DBOperate.cs類該類的作用是對程序中的要用到的對數(shù)據(jù)庫的操作進行統(tǒng)一,涉及到對數(shù)據(jù)庫的操作時,如對數(shù)據(jù)庫的增刪改操作,都可以直接調(diào)用該類,相應(yīng)的方法。傳入相應(yīng)的參數(shù)即可。添加引用usingSystem.Data.SqlClient;usingSystem.Data;定義變量SqlCommandsqlcom;SqlConnectionconn;默認(rèn)構(gòu)造方法///<summary>///構(gòu)造函數(shù)///</summary>///<paramname="dbc"></param>publicDBOperate(DBConnectiondbc){sqlcom=newSqlCommand();sqlcom.Connection=dbc.GetConnection();}編寫執(zhí)行方法///<summary>///執(zhí)行sql語句///</summary>///<paramname="sql"></param>publicvoidExecuteSQL(stringsql){this.sqlcom.CommandText=sql;try{this.sqlcom.ExecuteNonQuery();}catch{}}///<summary>///獲取數(shù)據(jù)表格的方法///</summary>///<paramname="sql"></param>///<returns>sql語句</returns>publicDataTableGetDataTable(stringsql){this.sqlcom.CommandText=sql;SqlDataAdaptersda=newSqlDataAdapter(this.sqlcom);DataSetds=newDataSet();DataTabledt=newDataTable();try{sda.Fill(ds);dt=ds.Tables[0];}catch{}returndt;}///<summary>///執(zhí)行SQL語句,獲取string類型數(shù)據(jù)///</summary>///<paramname="sql">SQL語句</param>///<returns>獲取到的string類型數(shù)據(jù)</returns>publicstringGetString(stringsql){stringresultStr="";this.sqlcom.CommandText=sql;try{resultStr=this.sqlcom.ExecuteScalar().ToString();}catch(SqlExceptione){}finally{this.sqlcom.Dispose();}returnresultStr;}publicintGetInt(stringsql){intresultInt=0;this.sqlcom.CommandText=sql;try{resultInt=Convert.ToInt32(this.sqlcom.ExecuteScalar().ToString());}catch(SqlExceptione){System.Windows.Forms.MessageBox.Show(e.Message);}finally{this.sqlcom.Dispose();}returnresultInt;}本資源是基于SQLServer開發(fā)的,所以可以使用using指令可以引用SQLServer專用的.NET數(shù)據(jù)庫提供者:usingSystem.Data.SqlClient;提取數(shù)據(jù)庫中數(shù)據(jù)的4步:連接數(shù)據(jù)源打開連接發(fā)出一個SQL查詢命令執(zhí)行命令語句SqlConnection是一個用于SQL.NET數(shù)據(jù)提供者的連接對象名稱,表示SQLServer數(shù)據(jù)庫的一個打開的連接。SqlConnection對象表示與SQLServer數(shù)據(jù)源的一個唯一的會話。對于客戶端/服務(wù)器數(shù)據(jù)庫系統(tǒng),它等效于到服務(wù)器的網(wǎng)絡(luò)連接。SqlConnection與SqlDataAdapter和SqlCommand一起使用,可以在連接MicrosoftSQLServer數(shù)據(jù)庫時提高性能。"Server=localhost;DataBase=AccessControl;uid=sa;pwd=123"Server=localost,表示正在訪問的SQLServer名稱,其格式是“計算機名\實例名”。計算機名(localhost)是一個非常方便的SQLServer簡短名稱,它表示運行在當(dāng)前機器上的服務(wù)器實例。DataBase=AccessControl,指定數(shù)據(jù)庫的名稱。uid=sa;pwd=123,表示登錄數(shù)據(jù)庫的用戶名和密碼,這是SQLServer和Windows的標(biāo)準(zhǔn)內(nèi)置安全。this.conn.Open();打開數(shù)據(jù)庫的連接。CommandText屬性獲取或設(shè)置要對數(shù)據(jù)源執(zhí)行的SQL語句或存儲過程。ExecuteNonQuery()方法,對連接執(zhí)行SQL語句并返回受影響的行數(shù)。SqlDataAdapter類表示用于填充DataSet和更新SQLServer數(shù)據(jù)庫的一組數(shù)據(jù)命令和一個數(shù)據(jù)庫連接。SqlDataAdapter是DataSet和SQLServer之間的橋接器,用于檢索和保存數(shù)據(jù)。DataSet是ADO.NET結(jié)構(gòu)的主要組件,它是從數(shù)據(jù)源中檢索到的數(shù)據(jù)在內(nèi)存中的緩存。DataSet由一組DataTable對象組成。try-catch語句由一個try塊后跟一個或多個catch子句構(gòu)成,這些子句指定不同的異常處理程序。try塊包含可能導(dǎo)致異常的保護代碼。該塊一直執(zhí)行到引發(fā)異常或成功完成為止。例如,下列強制轉(zhuǎn)換null對象的嘗試引發(fā)NullReferenceException異常:objecto2=null;try{inti2=(int)o2;//錯誤}10.2.3ObjCargoNode.cs類該類是對節(jié)點信息與數(shù)據(jù)庫中的進行操作進行的修改。節(jié)點加入網(wǎng)絡(luò)后,段地址會存儲到數(shù)據(jù)庫中。對當(dāng)前節(jié)點的識別也需要讀取數(shù)據(jù)庫中已輸入的節(jié)點信息。添加命名空間usingSystem.Data;定義變量privateintcargo;privatestringiEEEAddress;privatestringshortAddress;privateintnodeType;構(gòu)造函數(shù) publicObjCargoNode(){}publicObjCargoNode(intcargo){this.cargo=cargo;DataTabledtb=Program.dbo.GetDataTable(string.Format("selectCargo,IEEEAddress,ShortAddress,NodeTypefromCargoNodewhereCargo='{0}'",this.cargo));DataRowrow=dtb.Rows[0];this.cargo=Convert.ToInt32(row["Cargo"].ToString());this.iEEEAddress=row["IEEEAddress"].ToString();this.shortAddress=row["ShortAddress"].ToString();this.nodeType=Convert.ToInt32(row["NodeType"].ToString());}屬性publicintCargo{get{returnthis.cargo;}}publicstringIEEEAddress{get{returnthis.iEEEAddress;}}publicstringShortAddress{get{returnthis.shortAddress;}set{this.shortAddress=value;}}publicintNodeType{get{returnthis.nodeType;}}方法publicvoidInsert(){Program.dbo.ExecuteSQL(string.Format("updateCargoNodesetShortAddress='{0}'whereIEEEAddress='{1}'",this.shortAddress,this.iEEEAddress));}10.3功能設(shè)計與實現(xiàn)該部分實訓(xùn)內(nèi)容主要是通過程序和wsn的網(wǎng)關(guān)進行通信,這里我們需要學(xué)習(xí)關(guān)于wsn網(wǎng)關(guān)通信的相關(guān)應(yīng)用。該模塊程序中的代碼,在后面會分解出來應(yīng)用。向窗體中添加一個TabControl控件,在TabPages屬性添加6個成員。控件Name屬性Text屬性UseVisualStyleBackColor屬性TabPagetpConnect建立連接TrueTabPagetpPingPing指令TrueTabPagetpConfigReadConfig_Read指令TrueTabPagetpConfigWriteConfig_Write指令TrueTabPagetpSensorReadSensor_Read指令TrueTabPagetpSensorWriteSensor_Write指令True10.3.1創(chuàng)建建立連接1、建立連接TabPage窗體屬性,窗體如圖10-5所示。圖10-5Zigbee節(jié)點連接實驗圖向窗體添加1個SplitContainer控件,2個GroudBox控件,8個Label控件,9個TextBox控件,4個Button控件。更改窗體和控件屬性:2、設(shè)置窗體屬性窗體StartPosition屬性MaximizeBox屬性MinimizeBox屬性FormBorderStyle屬性Text屬性frmGoodsOutCenterParentFalseFalseFixedSingleZigbee節(jié)點連接實驗3、設(shè)置Lable控件屬性控件Name屬性Text屬性T1通道SocketLablelblIPAddressT1IP地址LablelblPortT1端口號LablelblAppIDT1AppIDLablelblPasswordT1PasswordT2通道SocketLablelblIPAddressT2IP地址LablelblPortT2端口號LablelblAppIDT2AppIDLablelblPasswordT2Password4、設(shè)置TextBox屬性控件Name屬性Text屬性TextBoxtxtIPAddressT130TextBoxtxtPortT14000TextBoxtxtAppIDT11001TextBoxtxtPasswordT1Kingvc@zigvineTextBoxtxtIPAddressT230TextBoxtxtPortT24000TextBoxtxtAppIDT21001TextBoxtxtPasswordT2Kingvc@zigvine5、設(shè)置顯示信息內(nèi)容的TextBox屬性控件Name屬性Dock屬性Multiline屬性ReadOnle屬性ScorllBars屬性TextBoxtxtMessageConnectFillTrueTrueVertical6、設(shè)置GroupBox控件屬性控件Name屬性Text屬性GroupBoxgbSocket_T1T1通道SocketGroupBoxgbSocket_T2T2通道Socket7、設(shè)置Button按鈕事件控件Name屬性Text屬性UseVisualStyleBackColor屬性ButtonbtnConnectSocketT1SocketT1連接TrueButtonbtnConnectT1T1通道連接TrueButtonbtnConnectSocketT2SocketT2連接TrueButtonbtnConnectT2T2通道連接True8、窗體后臺代碼:定義變量//定義一個函數(shù)結(jié)構(gòu)的委托privatedelegatevoidShowMessageDel(TextBoxtxt,stringmsg);privatedelegatevoidShowMessageDelOfTempLabel(Labellbl,stringvalue);//實例化T1數(shù)據(jù)包消息類privateGRIP_MessagemessageT1=newGRIP_Message();//實例化T2數(shù)據(jù)包消息類privateGRIP_MessagemessageT2=newGRIP_Message();//定義T1Socket通訊接口privateSocketsocketT1;//定義T2Socket通訊接口privateSocketsocketT2;//定義T1通道流水號privateUInt16sequenceIDT1;//定義T2通道流水號privateUInt16sequenceIDT2;privateinttime;//定義一個線程privateThreadthread;//sessionID為連接后網(wǎng)關(guān)隨機分配的一個標(biāo)識IDprivatestringsessionID="";構(gòu)造函數(shù)///<summary>///構(gòu)造函數(shù)///</summary>publicfrmZigBee(){InitializeComponent();}編寫方法Socket發(fā)送消息方法///<summary>///Socket發(fā)送消息方法///</summary>///<paramname="msgSend">要發(fā)送的字節(jié)數(shù)組</param>///<paramname="socket">Socket實例</param>///<paramname="lenSend">已發(fā)送的長度</param>privatevoidSendMsg(byte[]msgSend,Socketsocket,intlenSend){//需對發(fā)送的字節(jié)長度有明確認(rèn)識,發(fā)送一段字節(jié)后需要加上該段字節(jié)的長度while(lenSend<msgSend.Length){lenSend+=socket.Send(msgSend,lenSend,msgSend.Length-lenSend,SocketFlags.None);}}Socket接收信息的方法 ///<summary>///Socket接收消息方法///</summary>///<paramname="msgRecv">要接收的字節(jié)數(shù)組</param>///<paramname="socket">Socket實例</param>///<paramname="lenRecv">已接收的長度</param>privatevoidRecvMsg(byte[]msgRecv,Socketsocket,intlenRecv){while(lenRecv<msgRecv.Length){lenRecv+=socket.Receive(msgRecv,lenRecv,msgRecv.Length-lenRecv,SocketFlags.None);}}在控件中顯示信息的方法//<summary>///在控件中顯示消息的方法///</summary>///<paramname="txt"></param>///<paramname="msg"></param>privatevoidShowMessage(TextBoxtxt,stringmsg){if(txt.InvokeRequired){ShowMessageDelsmd=newShowMessageDel(ShowMessage);txt.Invoke(smd,txt,msg);}else{txt.Text+="\r\n【"+DateTime.Now.ToString("yyyy-MM-ddhh-mm-ss")+"】"+msg;}}在Label控件中顯示消息的方法 ///<summary>///在Label控件中顯示消息的方法///</summary>///<paramname="lbl">控件名稱</param>///<paramname="value">要顯示的值</param>privatevoidShowTempValue(Labellbl,stringvalue){if(lbl.InvokeRequired){ShowMessageDelOfTempLabelsmd=newShowMessageDelOfTempLabel(ShowTempValue);lbl.Invoke(smd,lbl,value);}else{lbl.Text=value;}}線程方法///<summary>///T2通道線程執(zhí)行方法///</summary>privatevoidRun(){try{while(true){#region解析消息頭//定義一個byte類型的6位數(shù)組byte[]msgRecvHeadBytes=newbyte[6];//接收到的消息頭的長度intlenRecv=0;//Socket接收消息的方法RecvMsg(msgRecvHeadBytes,this.socketT2,lenRecv);//實例化一個消息頭類GRIP_MessageHeadmsgHeadRecv=newGRIP_MessageHead();//對接收到的消息頭進行轉(zhuǎn)換msgHeadRecv.GetHeadBytesOfRecive(msgRecvHeadBytes,0,6);#endregion#region心跳包if(msgHeadRecv.MessageCommand==(UInt16)GRIP_Message_CommandID.NWM_HEARTBEAT){try{//消息的長度為16位無符號整數(shù)UInt16messageLength=0;//心跳報消息體?信息為空UInt16messageCommand=(UInt16)GRIP_Message_CommandID.NWM_HEARTBEAT_RESP;//獲取獲取流水號UInt16sequenceID=msgHeadRecv.SequenceID;//實例化一個消息頭類GRIP_MessageHeadmsgHeadSend=newGRIP_MessageHead(messageLength,messageCommand,sequenceID);//按照本地字節(jié)轉(zhuǎn)換發(fā)送的信息byte[]msgSend=msgHeadSend.GetHeadBytesOfSend();//發(fā)送信息方法SendMsg(msgSend,this.socketT2,0);//MessageBox.Show("【T2通道心跳包】發(fā)送成功");}catch(Exceptionex){MessageBox.Show("【T2通道心跳包】錯誤:"+ex.Message);}}#endregion#regionStatus_Report//判斷消息頭返回命令字是否正確if(msgHeadRecv.MessageCommand==(UInt16)GRIP_Message_CommandID.NWM_STATUS_REPORT){try{//定義一個消息頭字節(jié)長度的byte數(shù)組byte[]msgBodyRecvBytes=newbyte[msgHeadRecv.MessageLength];//定義消息體長度變量intlenBodyRecv=0;//Socket接收信息方法接收信息RecvMsg(msgBodyRecvBytes,this.socketT2,lenBodyRecv);//實例化節(jié)點報告命令GRIP_MessageBody_Status_ReportmsgBodyRecv=newGRIP_MessageBody_Status_Report();//按照本地字節(jié)和網(wǎng)絡(luò)字節(jié)的順序轉(zhuǎn)換接收到的消息體msgBodyRecv.ConvertReciveBytes(msgBodyRecvBytes);UInt16status=0;//實例化節(jié)點報告命令響應(yīng)GRIP_MessageBody_Status_Report_RespmsgBodySend=newGRIP_MessageBody_Status_Report_Resp(status);//實例化消息頭類,并將響應(yīng)參數(shù)傳入GRIP_MessageHeadmsgHeadSend=newGRIP_MessageHead(msgBodySend.BodyLength,(UInt16)GRIP_Message_CommandID.NWM_STATUS_REPORT_RESP,msgHeadRecv.SequenceID);//獲取發(fā)送的數(shù)據(jù)包的byte數(shù)組byte[]msgSend=this.messageT2.GetSendMessage(msgHeadSend,msgBodySend);intlenSend=0;//發(fā)送消息SendMsg(msgSend,this.socketT2,lenSend);if(this.sessionID==msgBodyRecv.SessionID){this.ShowMessage(this.txtMessagePing,"\r\n");this.ShowMessage(this.txtMessagePing,"【Status_Report】指令成功");this.ShowMessage(this.txtMessagePing,"【Status_Report】IEEEAddress:"+msgBodyRecv.Node.IEEEAddress);this.ShowMessage(this.txtMessagePing,"【Status_Report】ShortAddress:"+msgBodyRecv.Node.ShortAddress.ToString("X4"));this.ShowMessage(this.txtMessagePing,"【?Status_Report】Cause:"+msgBodyRecv.Cause);this.ShowMessage(this.txtMessagePing,"【Status_Report】SessionID:"+msgBodyRecv.SessionID);this.ShowMessage(this.txtMessagePing,"【Status_Report】DeviceName:"+msgBodyRecv.DeviceName);this.ShowMessage(this.txtMessagePing,"【Status_Report】DeviceType:"+msgBodyRecv.DeviceType);this.ShowMessage(this.txtMessagePing,"【Status_Report】Status:"+msgBodyRecv.Status);this.ShowMessage(this.txtMessagePing,"【Status_Report】PanID:"+msgBodyRecv.PanID+""+msgBodyRecv.PanID.ToString("X4"));this.ShowMessage(this.txtMessagePing,"【Status_Report】ParentIEEEAddress:"+msgBodyRecv.ParentNode.IEEEAddress);this.ShowMessage(this.txtMessagePing,"【Status_Report】ParentShortAddress:"+msgBodyRecv.ParentNode.ShortAddress.ToString("X4"));this.ShowMessage(this.txtMessagePing,"【Status_Report】SensorEnable:"+msgBodyRecv.SensorEnable);this.ShowMessage(this.txtMessagePing,"【Status_Report】SensorClass:"+msgBodyRecv.SensorClass);this.ShowMessage(this.txtMessagePing,"【Status_Report】SensorType:"+msgBodyRecv.SensorType.ToString("X4"));this.ShowMessage(this.txtMessagePing,"\r\n");this.ShowMessage(this.txtMessagePing,"【Status_Report_Resp】指令成功");}}catch(Exceptionex){this.ShowMessage(this.txtMessagePing,"【Status_Report】指令失敗錯誤:"+ex.Message);}}#endregion#regionSensor_Reportif(msgHeadRecv.MessageCommand==(UInt16)GRIP_Message_CommandID.NWM_SENSOR_REPORT){try{//定義一個消息體長度的byte數(shù)組byte[]msgBodyRecvBytes=newbyte[msgHeadRecv.MessageLength];//接收消息體的長度變量intlenBodyRecv=0;//接收消息體RecvMsg(msgBodyRecvBytes,this.socketT2,lenBodyRecv);//實例化節(jié)點報告命令GRIP_MessageBody_Sensor_ReportmsgBodyRecv=newGRIP_MessageBody_Sensor_Report();//將消息體按照本地字節(jié)和網(wǎng)絡(luò)字節(jié)的順序轉(zhuǎn)換msgBodyRecv.ConvertReciveBytes(msgBodyRecvBytes);UInt16status=0;//實例化節(jié)點報告命令的響應(yīng)GRIP_MessageBody_Sensor_Report_RespmsgBodySend=newGRIP_MessageBody_Sensor_Report_Resp(status);//實例化并獲得消息頭GRIP_MessageHeadmsgHeadSend=newGRIP_MessageHead(msgBodySend.BodyLength,(UInt16)GRIP_Message_CommandID.NWM_SENSOR_REPORT_RESP,msgHeadRecv.SequenceID);//獲取發(fā)送的數(shù)據(jù)包的byte數(shù)組byte[]msgSend=this.messageT2.GetSendMessage(msgHeadSend,msgBodySend);intlenSend=0;//發(fā)送消息SendMsg(msgSend,this.socketT2,lenSend);//判斷會話ID是否相同if(this.sessionID==msgBodyRecv.SessionID){this.ShowMessage(this.txtMessagePing,"\r\n");this.ShowMessage(this.txtMessagePing,"【Sensor_Report】指令成功");this.ShowMessage(this.txtMessagePing,"【Sensor_Report】IEEEAddress:"+msgBodyRecv.Node.IEEEAddress);this.ShowMessage(this.txtMessagePing,"【Sensor_Report】ShortAddress:"+msgBodyRecv.Node.ShortAddress.ToString("X4"));this.ShowMessage(this.txtMessagePing,"【Sensor_Report】Cause:"+msgBodyRecv.Cause);this.ShowMessage(this.txtMessagePing,"【Sensor_Report】SessionID:"+msgBodyRecv.SessionID);this.ShowMessage(this.txtMessagePing,"【Sensor_Report】DataType:"+msgBodyRecv.DataType);#regionSensor_Read引°y發(fā)¤?é//判斷節(jié)點數(shù)據(jù)采集是否成功if(msgBodyRecv.DataType==0x01){this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】SensorClass:"+((GRIP_SensorData)msgBodyRecv.Data).SensorClass);this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】SensorType:"+((GRIP_SensorData)msgBodyRecv.Data).SensorType.ToString("X4"));this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】SensorDataLength:"+((GRIP_SensorData)msgBodyRecv.Data).SensorDataLength);#region溫濕度傳感器//判斷溫濕度傳感器節(jié)點的數(shù)據(jù)長度是否正確同時在窗口中顯示溫濕度if(((GRIP_SensorData)msgBodyRecv.Data).SensorDataLength==4){this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】Temp_H:"+((GRIP_SensorData)msgBodyRecv.Data).Temp_H);this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】Temp_L:"+((GRIP_SensorData)msgBodyRecv.Data).Temp_L);this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】當(dāng)前溫度:"+((GRIP_SensorData)msgBodyRecv.Data).Temp_H+"."+((GRIP_SensorData)msgBodyRecv.Data).Temp_L+"℃");this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】Humi_H:"+((GRIP_SensorData)msgBodyRecv.Data).Humi_H);this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】Humi_L:"+((GRIP_SensorData)msgBodyRecv.Data).Humi_L);this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】當(dāng)前濕度:"+((GRIP_SensorData)msgBodyRecv.Data).Humi_H+"."+((GRIP_SensorData)msgBodyRecv.Data).Humi_L+"%");ShowTempValue(this.lblTempValue,((GRIP_SensorData)msgBodyRecv.Data).Temp_H+"."+((GRIP_SensorData)msgBodyRecv.Data).Temp_L+"℃");ShowTempValue(this.lblHumiValue,((GRIP_SensorData)msgBodyRecv.Data).Humi_H+"."+((GRIP_SensorData)msgBodyRecv.Data).Humi_L+"%");}#endregion#region數(shù)碼管節(jié)點//判斷數(shù)碼管節(jié)點數(shù)據(jù)長度是否正確if(((GRIP_SensorData)msgBodyRecv.Data).SensorDataLength==5){this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】Value:"+((GRIP_SensorData)msgBodyRecv.Data).Value);this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】LED:"+((GRIP_SensorData)msgBodyRecv.Data).LED);this.ShowMessage(this.txtMessagePing,"【Sensor_Report(SensorData)】Value:"+((GRIP_SensorData)msgBodyRecv.Data).Time);}#endregion}#endregion#regionConfig_Read引發(fā)//判斷節(jié)點配置數(shù)據(jù)采集是否成功if(msgBodyRecv.DataType==0x02){this.ShowMessage(this.txtMessageConfigRead,"【Sensor_Report(ConfigInfo)】DeviceCountFlag:"+((GRIP_NodeConfigInfo)msgBodyRecv.Data).DeviceConfigFlag);this.ShowMessage(this.txtMessageConfigRead,"【Sensor_Report(ConfigInfo)】DeviceName:"+((GRIP_NodeConfigInfo)msgBodyRecv.Data).DeviceName);this.ShowMessage(this.txtMessageConfigRead,"【Sensor_Report(ConfigInfo)】NetWorkKey:"+((GRIP_NodeConfigInfo)msgBodyRecv.Data).NetWorkKey);this.ShowMessage(this.txtMessageConfigRead,"【Sensor_Report(ConfigInfo)】PanID:"+((GRIP_NodeConfigInfo)msgBodyRecv.Data).PanID+""+((GRIP_NodeConfigInfo)msgBodyRecv.Data).PanID.ToString("X4"));this.ShowMessage(this.txtMessageConfigRead,"【Sensor_Report(ConfigInfo)】SensorEnable:"+((GRIP_NodeConfigInfo)msgBodyRecv.Data).SensorEnable);this.ShowMessage(this.txtMessageConfigRead,"【Sensor_Report(ConfigInfo)】SensorClass:"+((GRIP_NodeConfigInfo)msgBodyRecv.Data).SensorClass);this.ShowMessage(this.txtMessageConfigRead,"【Sensor_Report(ConfigInfo)】SensorType:"+((GRIP_NodeConfigInfo)msgBodyRecv.Data).SensorType.ToString("X4"));this.ShowMessage(this.txtMessageConfigRead,"【Sensor_Report(ConfigInfo)】SensorReportPeriod:"+((GRIP_NodeConfigInfo)msgBodyRecv.Data).SensorReprotPeriod);this.ShowMessage(this.txtMessageConfigRead,"【Sensor_Report(ConfigInfo)】SensorConfigDataLength:"+((GRIP_NodeConfigInfo)msgBodyRecv.Data).SensorConfigDataLength);this.ShowMessage(this.txtMessageConfigRead,"【Sensor_Report(ConfigInfo)】SensorConfigData:"+BitConverter.ToString(((GRIP_NodeConfigInfo)msgBodyRecv.Data).SensorConfigData));}#endregion}else{#regionSensor_Read引發(fā)if(msgBodyRecv.DataType==0x01){this.ShowMessage(this.txtMessageSensorRead,"【Sensor_Report(SensorData)】SensorClass:"+((GRIP_SensorData)msgBodyRecv.Data).SensorClass);this.ShowMessage(this.txtMessageSensorRead,"【Sensor_Report(SensorData)】SensorType:"+((GRIP_SensorData)msgBodyRecv.Data).SensorType.ToString("X4"));this.ShowMessage(this.txtMessageSensorRead,"【Sensor_Report(SensorData)】SensorDataLength:"+((GRIP_SensorData)msgBodyRecv.Data).SensorDataLength);#region溫濕度傳感器if(((GRIP_SensorData)msgBodyRecv.Data).SensorDataLength==4){this.ShowMessage(this.txtMessageSensorRead,"【Sensor_Report(SensorData)】Temp_H:"+((GRIP_SensorData)msgBodyRecv.Data).Temp_H);this.ShowMessage(this.txtMessageSensorRead,"【Sensor_Report(SensorData)】Temp_L:"+((GRIP_SensorData)msgBodyRecv.Data).Temp_L);this.ShowMessage(this.txtMessageSensorRead,"【Sensor_Report(SensorData)】當(dāng)前溫度:"+((GRIP_SensorData)msgBodyRecv.Data).Temp_H+"."+((GRIP_SensorData)msgBodyRecv.Data).Temp_L+"℃");this.ShowMessage(this.txtMessageSensorRead,"【Sensor_Report(SensorD
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 土地使用權(quán)轉(zhuǎn)讓合同
- 2026年醫(yī)療知識培訓(xùn)合同
- 2026年工程整體驗收合同
- 2026年醫(yī)院品牌運營托管服務(wù)合同
- 2025年中國科學(xué)院深??茖W(xué)與工程研究所招聘備考題庫(十三)及答案詳解參考
- 2026年航空治理協(xié)同合同
- 2025年寧夏中科碳基材料產(chǎn)業(yè)技術(shù)研究院招聘備考題庫及參考答案詳解1套
- 2025國考國家稅務(wù)總局勉縣稅務(wù)局面試題庫及答案
- 中國信息通信研究院2026屆校園招聘80人備考題庫含答案詳解
- 中國科學(xué)院空間應(yīng)用工程與技術(shù)中心2026屆校園招聘備考題庫及1套完整答案詳解
- 九江市村級衛(wèi)生室診所醫(yī)療機構(gòu)衛(wèi)生院社區(qū)衛(wèi)生服務(wù)中心地理位置地址信息匯總
- 會計職業(yè)生涯規(guī)劃書
- 液壓傳動課程設(shè)計-臥式半自動組合機床液壓系統(tǒng)
- 品質(zhì)異常通知單
- 鼎捷T100-V1.0-總賬管理用戶手冊-簡體
- GB 31644-2018食品安全國家標(biāo)準(zhǔn)復(fù)合調(diào)味料
- 邏輯學(xué)(北大課件)
- 援疆工作調(diào)研報告
- 加油站班前會記錄表
- 機車-受電弓碳滑板磨耗檢測
- 數(shù)學(xué)建模電子教材
評論
0/150
提交評論