![基于單片機的測量軸轉(zhuǎn)速扭矩系統(tǒng)的軟件實現(xiàn)畢業(yè)設計_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/9/12030d17-9e53-4ac9-ae41-e9be6ee3ca11/12030d17-9e53-4ac9-ae41-e9be6ee3ca111.gif)
![基于單片機的測量軸轉(zhuǎn)速扭矩系統(tǒng)的軟件實現(xiàn)畢業(yè)設計_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/9/12030d17-9e53-4ac9-ae41-e9be6ee3ca11/12030d17-9e53-4ac9-ae41-e9be6ee3ca112.gif)
![基于單片機的測量軸轉(zhuǎn)速扭矩系統(tǒng)的軟件實現(xiàn)畢業(yè)設計_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/9/12030d17-9e53-4ac9-ae41-e9be6ee3ca11/12030d17-9e53-4ac9-ae41-e9be6ee3ca113.gif)
![基于單片機的測量軸轉(zhuǎn)速扭矩系統(tǒng)的軟件實現(xiàn)畢業(yè)設計_第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/9/12030d17-9e53-4ac9-ae41-e9be6ee3ca11/12030d17-9e53-4ac9-ae41-e9be6ee3ca114.gif)
![基于單片機的測量軸轉(zhuǎn)速扭矩系統(tǒng)的軟件實現(xiàn)畢業(yè)設計_第5頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/9/12030d17-9e53-4ac9-ae41-e9be6ee3ca11/12030d17-9e53-4ac9-ae41-e9be6ee3ca115.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、 畢業(yè)設計論文測量軸轉(zhuǎn)速扭矩系統(tǒng)的軟件實現(xiàn) xx大學xx學院畢業(yè)設計(論文) 題 目 測量軸轉(zhuǎn)速扭矩系統(tǒng)的軟件實現(xiàn) 所 屬 系 過程裝備與控制工程系年級專業(yè) 學 號 姓 名 指導教師 日 期 測量軸轉(zhuǎn)速扭矩系統(tǒng)的軟件實現(xiàn)摘要:在深入研究軸轉(zhuǎn)矩轉(zhuǎn)速測量儀工作原理基礎上,采用面向?qū)ο蟪绦蛟O計語言vc+6.0,建立一個對軸轉(zhuǎn)速,扭矩值動態(tài)測量采集的系統(tǒng),繼而完成對數(shù)據(jù)的存貯。關(guān)鍵詞: 面向?qū)ο蟮某绦蛟O計 開放數(shù)據(jù)庫連接 sql查詢 數(shù)據(jù)庫the design of a measurement system for shaft speed and torque abstract: based on d
2、eeply researching into the operation principle of shaft speed and torque measurement instrument, we adopt object oriented program ,vc+6.0,create a dynamical measurement system for shaft speed and torque, completing the record of data. key words:object oriented program(oop) the query of sql databaseo
3、dbc(open database connection)目 錄the design of a measurement system for shaft speed and torque1目 錄2前 言3第一部分 系統(tǒng)設計概述41.1數(shù)據(jù)采集系統(tǒng)的組成及其硬件結(jié)構(gòu)41.1.1典型的數(shù)據(jù)自動采集系統(tǒng)41.1.2轉(zhuǎn)矩轉(zhuǎn)速測量儀硬件結(jié)構(gòu)51.2系統(tǒng)的工作原理61.2.1轉(zhuǎn)矩測量原理圖61.2.2轉(zhuǎn)速測量原理61.3 扭矩轉(zhuǎn)速數(shù)據(jù)采集系統(tǒng)的軟件功能及結(jié)構(gòu)7第二部分 軟件工程模塊的建立82.1用戶界面設計82.1.1消息及成員函數(shù)之間的響應關(guān)系92.1.2設計步驟92.2數(shù)據(jù)庫設計252.2.1數(shù)據(jù)庫整
4、體框架設計252.2.2完整實現(xiàn)代碼272.3 rs-232c通信建立392.3.1 windows下串行通信392.3.2 rs232c的類封裝46第三部分 畢業(yè)設計的收獲和反思51參考文獻:52前 言自1981年8月12日ibm公司的pc問世以來,pc的處理能力經(jīng)歷了一個驚人的發(fā)展過程?,F(xiàn)在pc正在大舉進入數(shù)據(jù)采集領域。事實上,作為數(shù)據(jù)采集的主要部件,pc表現(xiàn)出了巨大的潛力。pc采用數(shù)字編碼格式,使得大規(guī)模瞬態(tài)采集和存儲數(shù)據(jù)成為可能。為基于大量數(shù)據(jù)的工業(yè)用分析設計軟件如ansys5.7提供了數(shù)據(jù)源,為工業(yè)過程控制領域自動控制的實施提供決策依據(jù)。 一些大型控制系統(tǒng)經(jīng)常采用vb作平臺,vc作為
5、面向?qū)ο蟪绦?,并輔之以匯編語言作為i/o接口處理本次畢業(yè)設計實驗的儀器為一臺普通的轉(zhuǎn)速轉(zhuǎn)矩測量儀,通過轉(zhuǎn)矩傳感器實現(xiàn)轉(zhuǎn)矩、轉(zhuǎn)速及軸功率的多參數(shù)輸出,并顯示在led液晶控制面板上。但因為生產(chǎn)該儀器廠家,只提供與計算機通信相連的rs232接口,而未提供相關(guān)通信連接的軟件。故無法實現(xiàn)數(shù)據(jù)采集的智能化和計算機化。因此本次畢業(yè)設計選題的目的在于,基于該轉(zhuǎn)速轉(zhuǎn)矩測量儀的rs232接口的串口通信機制,利用microsoft 提供的visual c+編程開發(fā)工具,完成計算機與該儀器的智能通信,實現(xiàn)該儀器數(shù)據(jù)的動態(tài)采集,記錄,存入數(shù)據(jù)庫備查。第一部分 系統(tǒng)設計概述1.1數(shù)據(jù)采集系統(tǒng)的組成及其硬件結(jié)構(gòu)1.1.1典
6、型的數(shù)據(jù)自動采集系統(tǒng)隨著人類社會的發(fā)展,利用計算機設備實現(xiàn)生產(chǎn)過程的自動化成為了提高生產(chǎn)力,減輕勞動強度的有效方法。由于大量設備的使用,必需隨時知道實際的情況,這就是監(jiān)視,通過計算機輔助數(shù)據(jù)采集過程可以實現(xiàn)對數(shù)據(jù)的自動處理。圖11描述了一個簡單的計算機輔助數(shù)據(jù)采集系統(tǒng)的方框圖。計算機界與硬件接口通過合適的通信鏈路相連,硬件接口依次與相應的傳感器相連,而傳感器對視眼中環(huán)境的變化作出相應。傳感器將各種不同的現(xiàn)象轉(zhuǎn)換成電壓或者電流信號接口硬件將傳感器的輸出信號轉(zhuǎn)換成計算機可以識別的形式輸入計算機。生產(chǎn)過程傳感器接口硬件計算機傳感器 圖11典型的數(shù)據(jù)自動采集系統(tǒng)相應的我們對數(shù)據(jù)采集系統(tǒng)作出一點改動,便
7、可以作出工業(yè)上應用廣泛的分布式監(jiān)控系統(tǒng)(distributed control system)如圖12所示。生產(chǎn)過程傳感器接口硬件計算機執(zhí)行機構(gòu) 圖12計算機控制系統(tǒng)方框圖1.1.2轉(zhuǎn)矩轉(zhuǎn)速測量儀硬件結(jié)構(gòu)本次畢業(yè)設計所采用的轉(zhuǎn)矩轉(zhuǎn)速測量儀是由湖南湘儀動力有限公司生產(chǎn)的基于jn388數(shù)字式轉(zhuǎn)矩轉(zhuǎn)速傳感器和at89c52單片機教學科研用轉(zhuǎn)矩轉(zhuǎn)速測量儀,圖13給出了與單片機接口構(gòu)成的智能轉(zhuǎn)矩轉(zhuǎn)速測量儀的硬件電路結(jié)構(gòu)框圖。圖中,jn338型轉(zhuǎn)矩傳感器輸出的轉(zhuǎn)矩及轉(zhuǎn)速信號經(jīng)光耦隔離后送入單片機的t0、t1計數(shù)器,然后由t0和t1完成測頻計數(shù)功能,秒脈沖閘門由t2提供。這其中光耦的作用,一是電平轉(zhuǎn)換,把轉(zhuǎn)
8、矩轉(zhuǎn)速信號電平轉(zhuǎn)換成ttl電平,二是提高單片機的抗干擾能力并保護單片機。圖13 智能轉(zhuǎn)矩轉(zhuǎn)速測量儀硬件電路結(jié)構(gòu)框圖由單片機完成相應的轉(zhuǎn)矩、轉(zhuǎn)速值的運算后,即可將轉(zhuǎn)矩、轉(zhuǎn)速及軸功率等參數(shù)保存并顯示輸出。本系統(tǒng)以at89c52單片機為核心由imp8132構(gòu)成電源監(jiān)控及看門狗電路以提高系統(tǒng)工作的可靠性,系統(tǒng)中擴展了一片i2c總線串行鐵電存儲器fm24256,它的主要作用是存儲參數(shù)設定值及采集的轉(zhuǎn)矩轉(zhuǎn)速值。內(nèi)含gb2312中文漢字庫的圖形點陣液晶顯示模塊ocmjx8c可用于構(gòu)成中文人機顯示界面,icl232的作用是將單片機的ttl電平轉(zhuǎn)換為rs-232電平,以便于和上位計算機進行通信。1.2系統(tǒng)的工作
9、原理1.2.1轉(zhuǎn)矩測量原理圖 14應變傳感器測量原理圖 jn338數(shù)字式轉(zhuǎn)矩轉(zhuǎn)速傳感器采用兩組特殊環(huán)形旋轉(zhuǎn)變壓器來實現(xiàn)能源的輸入及轉(zhuǎn)矩信號的輸出,從而解決了旋轉(zhuǎn)動力傳遞系統(tǒng)中能源及信號可靠地在旋轉(zhuǎn)部分與靜止部分之間的傳遞問題。該傳感器還可同時實現(xiàn)旋轉(zhuǎn)軸轉(zhuǎn)速的測量,從而可方便地計算出軸輸出功率,因此利用該傳感器可實現(xiàn)轉(zhuǎn)矩、轉(zhuǎn)速及軸功率的多參數(shù)輸出。在一段特制的彈性軸上粘貼專用的測扭應變片并組成電橋,以形成基礎扭矩傳感器,然后在軸上再固定能源環(huán)形旋轉(zhuǎn)變壓器的次級線圈、軸上印刷電路板和信號環(huán)旋轉(zhuǎn)變壓器的初級線圈。電路板上包含整流穩(wěn)壓電源、儀表放大電路及v/f變換電路。在傳感器的外殼上固定著激磁電路、
10、能源環(huán)形旋轉(zhuǎn)變壓器的初級線圈、信號環(huán)形變壓器的次級線圈及信號處理電路。1.2.2轉(zhuǎn)速測量原理轉(zhuǎn)矩傳感器在旋轉(zhuǎn)軸上安裝著60條齒縫的測速輪,在傳感器外殼上安裝的一只由發(fā)光二極管及光敏三極管組成的槽型光電開關(guān)架,測速輪的每一個齒將發(fā)光二極管的光線遮擋住時,光敏三極管就輸出一個高電平,當光線通過齒縫射到光敏管的窗口時,光敏管就輸出一個低電平,旋轉(zhuǎn)軸每轉(zhuǎn)一圈就可得到60個脈沖,因此,每秒鐘檢測到的脈沖數(shù)恰好等于每分鐘的轉(zhuǎn)速值。 1.3 扭矩轉(zhuǎn)速數(shù)據(jù)采集系統(tǒng)的軟件功能及結(jié)構(gòu)用 戶人/機交互界面 數(shù)據(jù)采集的命令消息 記錄數(shù)據(jù)的命令消息rs-232c數(shù)據(jù)庫管理系統(tǒng) 數(shù)據(jù)的實時記錄數(shù)據(jù)庫扭矩轉(zhuǎn)速測量儀開始連接
11、數(shù)據(jù)庫讀串口數(shù)據(jù) 設置定時器是否創(chuàng)建新表 n獲得串口數(shù)據(jù) y新表名稱顯示數(shù)據(jù)設置采樣個數(shù)記錄采樣數(shù)據(jù)停止讀串口數(shù)據(jù)連接數(shù)據(jù)庫寫入數(shù)據(jù)庫圖15 程序結(jié)構(gòu)及流程示意圖該軟件工程完成的功能主要有:對轉(zhuǎn)矩轉(zhuǎn)速測量儀經(jīng)由rs232c串口送出的轉(zhuǎn)矩轉(zhuǎn)速數(shù)據(jù)進行動態(tài)采集,使用者可以自行規(guī)定采樣個數(shù),一旦完成了對數(shù)據(jù)的采集,使用者可以創(chuàng)建一個新表,并連接到數(shù)據(jù)庫,完成對數(shù)據(jù)的存貯。第二部分 軟件工程模塊的建立2.1用戶界面設計該界面所要完成得功能有:當用戶點擊連接數(shù)據(jù)庫按鈕時,會彈出數(shù)據(jù)源選擇對話框,配置完成候,彈出“connect is ok”隨后,用戶可以創(chuàng)建新表。當用戶點擊讀串口數(shù)據(jù)按鈕時,如果計算機與
12、rs232c串口連接成功則在扭矩轉(zhuǎn)速文本框中動態(tài)顯示測量儀的扭矩及轉(zhuǎn)速,當用戶輸入采樣個數(shù)值以后,系統(tǒng)便開始在當前采樣矩形列表框中顯示采樣所獲數(shù)據(jù),當記錄完成后彈出寫入數(shù)據(jù)庫按鈕,隨后,即可將采樣數(shù)據(jù)記錄入庫。 圖21 程序功能界面圖2.1.1消息及成員函數(shù)之間的響應關(guān)系窗口發(fā)出讀串口數(shù)據(jù)信息時,將調(diào)用時間設置函數(shù)settimer(),時間響應函數(shù)ontimer(),串口通信類rs232c成員函數(shù),獲得端口數(shù)據(jù)getcomdata(),連接函數(shù)connectok(),記錄函數(shù)onrecord(),停止讀串口數(shù)據(jù)函數(shù)onstop().窗口發(fā)出連接數(shù)據(jù)庫信息時,調(diào)用斷開數(shù)據(jù)庫函數(shù)onclose()
13、,寫入數(shù)據(jù)庫函數(shù)onwrite(),創(chuàng)建新表函數(shù)onnewtable().具體響應關(guān)系如圖22所示。 圖22 系統(tǒng)消息與響應函數(shù)系圖2.1.2設計步驟步驟一 :創(chuàng)建工程。使用vc+的appwizard中的mfc appwizard(exe)選項建立一個名為pi100_rs232_vc60的single documents 工程。步驟二 :添加菜單資源。打開resourceview標簽,打開dialog,添加標題為“扭矩轉(zhuǎn)速試驗采樣記錄系統(tǒng)”的對話框,id號為“idd_example_form”。添加該菜單命令的目的是為了彈出系統(tǒng)的功能界面如圖23所示。步驟三 :該對話框所用到的控件的詳細說明如
14、表21所示:圖23 初始界面設計圖 控件種類id號標 題靜態(tài)文字(cstatic text)idc_static扭矩轉(zhuǎn)速采樣記錄系統(tǒng)靜態(tài)文字(cstatic text)idc_static當前表名靜態(tài)文字(cstatic text)idc_static扭矩靜態(tài)文字(cstatic text)idc_static轉(zhuǎn)速靜態(tài)文字(cstatic text)idc_static采樣個數(shù)靜態(tài)文字(cstatic text)idc_static新表名稱靜態(tài)文字(cstatic text)idc_static當前采樣編輯文字 (cedit text)idc_edittorque扭矩編輯文字 (cedit t
15、ext)idc_editrpm轉(zhuǎn)速編輯文字 (cedit text)idc_edit_recnum采樣個數(shù)編輯文字 (cedit text)idc_edit_name新表名稱列表框 (clist box)idc_listm當前采樣按鈕 (cbutton)idc_buttonconnect連接數(shù)據(jù)庫按鈕 (cbutton)idc_buttonread讀串口數(shù)據(jù)按鈕 (cbutton)idc_buttonrecord記錄數(shù)據(jù)按鈕 (cbutton)idc_buttonclose斷開數(shù)據(jù)庫按鈕 (cbutton)idc_buttonstop停止讀串口數(shù)據(jù)按鈕 (cbutton)idc_buttonc
16、reate創(chuàng)建新表 表2-1 對話框的控件 在設計狀態(tài)下,保證選中該對話框的前提下,使用系統(tǒng)采單viewclasswizard命令或使用快捷鍵ctrl+w,按照提示便可以完成生成新類的工作,將新生的類命名為exampleview,基類為cformview。步驟四 :使用classwizard添加菜單響應函數(shù)以及為對話框的控件添加事件處理函數(shù)。使用classwizard命令,調(diào)用“mfc classwizard”對話框。先將 “class name :”組合框選為“cexampleview”;在“object id:”列表框中,選中“idd_example_form”;在message:”列表框
17、中,選中“command”;最后用鼠標左鍵單擊“add fuction”按鈕,以便添加該菜單命令消息函數(shù)。將“class name :”組合框選為“cexampleview”項,在“object id:”列表框中,分別用鼠標選中表12中所列出的控件id(每次只能選擇一個);在“message :”列表框中,選中“bnclicked”消息,然后再用鼠標左鍵單擊“add fuction”按鈕。此時屏幕上會彈出 add member fuction對話框,如此重復多次就可以添加所需的消息控制函數(shù)。步驟五 : 為對話框類添加成員函數(shù)和成員變量,打開class view標簽,用鼠標右
18、鍵單擊類cexampleview,使用快捷菜單命令“add member viariable”添加成員變量。使用classwizard菜單中“add member fuction”命令添加如下主要成員函數(shù): getcomportdata( ) / 獲得串口數(shù)據(jù) getcomportdatafor_jw1a( ) /在列表中顯示數(shù)據(jù) onconnect( ) /連接數(shù)據(jù)庫 onrecord( ) /記錄新數(shù)據(jù) onclose( ) /斷開數(shù)據(jù)庫 onnewtable ( ) /創(chuàng)建新表 onwrite( ) /寫入數(shù)據(jù)庫 onread( ) /讀串口數(shù)據(jù)編輯exampleview.h文件如下:/
19、 exampleview.h : interface of the cexampleview class/#if !defined(afx_exampleview_h_43802042_b656_11d4_8741_82cf81df7355_included_)#define afx_exampleview_h_43802042_b656_11d4_8741_82cf81df7355_included_#if _msc_ver > 1000#pragma once#endif / _msc_ver > 1000#include "modalodbc.h"stru
20、ct s_data /為將轉(zhuǎn)速扭矩測量數(shù)據(jù)放入數(shù)據(jù)庫定義的一種數(shù)據(jù)結(jié)構(gòu)double m_data;double n_data;class cexampleview : public cformviewprotected: / create from serialization onlycexampleview();declare_dyncreate(cexampleview)public:/afx_data(cexampleview)enum idd = idd_example_form ;ceditm_torque; /定義的扭矩變量ceditm_rpm; /定義的轉(zhuǎn)速變量/afx_data
21、mydbclass db;/ attributespublic:cexampledoc* getdocument();/ operationspublic:class crs232 *rs232; /定義的串口通信類void getcomportdata(); /獲得串口數(shù)據(jù)顯示采集所獲的數(shù)據(jù)/ overrides/ classwizard generated virtual function overrides/afx_virtual(cexampleview)public:virtual bool precreatewindow(createstruct& cs);protecte
22、d:virtual void dodataexchange(cdataexchange* pdx); / ddx/ddv supportvirtual void oninitialupdate(); / called first time after construct/afx_virtual/ implementationpublic:char tbname50;int currentnum;int recnum;bool beginrecord;bool connected;s_data * samp_data;bool connectok();virtual cexampleview()
23、;#ifdef _debugvirtual void assertvalid() const;virtual void dump(cdumpcontext& dc) const;#endifprotected:/ generated message map functionsprotected:/afx_msg(cexampleview)afx_msg void onread (); /讀串口數(shù)據(jù)afx_msg void ontimer(uint nidevent); /對定時器的響應afx_msg void onconnect(); /連接數(shù)據(jù)庫afx_msg void onreco
24、rd(); /記錄新數(shù)據(jù)afx_msg void onshowwindow(bool bshow, uint nstatus); /按鈕的顯示與隱藏afx_msg void onclose(); /斷開數(shù)據(jù)庫afx_msg void onreadstop(); /停止讀串口數(shù)據(jù)afx_msg void onnewtable(); /創(chuàng)建新表afx_msg void onwrite(); /寫入數(shù)據(jù)庫/afx_msg void onchangeedittorque(); / afx_msg void onchangeeditrpm();/afx_msgdeclare_message_map();
25、#ifndef _debug / debug version in exampleview.cppinline cexampledoc* cexampleview:getdocument() return (cexampledoc*)m_pdocument; #endif/afx_insert_location/ microsoft visual c+ will insert additional declarations immediately before the previous line.#endif / !defined(afx_exampleview_h_43802042_b656
26、_11d4_8741_82cf81df7355_included_)步驟六 :為各個成員函數(shù)添加代碼。添加完成所有成員函數(shù)和成員變量之后,實現(xiàn)這些成員函數(shù),該類的完整實現(xiàn)代碼如下:/ exampleview.cpp : implementation of the cexampleview class/#include <stdafx.h>#include <math.h>#include "stdafx.h"#include "example.h"#include "rs232.h"#include "
27、;exampledoc.h"#include "exampleview.h"#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif/ cexampleviewimplement_dyncreate(cexampleview, cformview)begin_message_map(cexampleview, cformview)/afx_msg_map(cexampleview)on_bn_clicked(idc_test, ontest)on_
28、wm_timer()on_bn_clicked(idc_button1, onconnect)on_bn_clicked(idc_button3, onrecord)on_wm_showwindow()on_bn_clicked(idc_button4, onclose)on_bn_clicked(idc_test_stop, onreadstop)on_bn_clicked(idc_button_newtable, onnewtable)on_bn_clicked(idc_button_write, onwrite)/ on_en_change(idc_edittorque, onchang
29、eedittorque)/ on_en_change(idc_editrpm, onchangeeditrpm)/afx_msg_mapend_message_map()/ cexampleview construction/destructioncexampleview:cexampleview(): cformview(cexampleview:idd)/afx_data_init(cexampleview)/ note: the classwizard will add member initialization here/afx_data_init/ todo: add constru
30、ction code herers232 = new crs232; / rs232通信類的引入this->beginrecord=false;recnum=0;this->connected=false;strcpy(tbname,"null");cexampleview:cexampleview() delete rs232;cwnd:killtimer(1); db.disconn();void cexampleview:dodataexchange(cdataexchange* pdx)cformview:dodataexchange(pdx);/afx
31、_data_map(cexampleview)ddx_control(pdx, idc_edittorque, m_torque);ddx_control(pdx, idc_editrpm, m_rpm);/afx_data_mapbool cexampleview:precreatewindow(createstruct& cs)/ todo: modify the window class or styles here by modifying/ the createstruct csreturn cformview:precreatewindow(cs);void cexampl
32、eview:oninitialupdate()cformview:oninitialupdate();getparentframe()->recalclayout();resizeparenttofit();/ cexampleview diagnostics#ifdef _debugvoid cexampleview:assertvalid() constcformview:assertvalid();void cexampleview:dump(cdumpcontext& dc) constcformview:dump(dc);cexampledoc* cexamplevie
33、w:getdocument() / non-debug version is inlineassert(m_pdocument->iskindof(runtime_class(cexampledoc);return (cexampledoc*)m_pdocument;#endif /_debug/ cexampleview message handlersvoid cexampleview:onread() / todo: add your control notification handler code herecwnd:settimer(1,1000,null);/設置發(fā)送響應時間
34、,每一秒發(fā)送一次。cbutton *p=(cbutton*)getdlgitem(idc_test);p->showwindow(sw_hide);p=(cbutton*)getdlgitem(idc_test_stop);p->showwindow(sw_show);p=(cbutton*)getdlgitem(idc_button3);p->showwindow(sw_show);void cexampleview:getcomportdata() /獲得串口的數(shù)據(jù)cwnd:killtimer(1); /中斷對定時器的響應if(!connectok() /如果連接失敗af
35、xmessagebox("應答失敗!");return; dword nnumberofbytestoread; /要讀取的字節(jié)數(shù) dword nbytesread; /已經(jīng)讀取的字節(jié)數(shù) char buffer1128, buffer2128; /定義存放串口數(shù)據(jù)的緩沖區(qū) char mychar; int i, j; bool nowgetn = false; /兩個數(shù)據(jù)之間的轉(zhuǎn)換標識char listchar256; for(i=0; i<128; i+)buffer1i = buffer2i = '0' rs232->setupcomport
36、(); /clear i/o buffer. nnumberofbytestoread = 1; /指定要從串口讀取的字節(jié)數(shù)。 i = j = 0; do rs232->readcomport(nnumberofbytestoread, nbytesread); mychar = rs232->combuffer0; if( nowgetn ) buffer2j = mychar; if( mychar = ',' ) nowgetn = false; buffer2j = '0' j+; else buffer1i = mychar; if( my
37、char = '' ) nowgetn = true; buffer1i = '0' i+; /strcpy(buffer, rs232->combuffer); while( mychar != ',' ); /顯示采集所獲的數(shù)據(jù)于編輯對話框中 / if( lstrlen(buffer1) >= 6 && lstrlen(buffer2) >= 6 ) m_torque.setwindowtext( buffer1 ); m_rpm.setwindowtext( buffer2 ); if(beginrecor
38、d) /開始記錄數(shù)據(jù)if(currentnum<recnum) /如果當前記錄的數(shù)據(jù)個數(shù)小于要記錄的個數(shù) /將數(shù)據(jù)轉(zhuǎn)換為浮點數(shù)據(jù)記錄于列表框中char a10;samp_datacurrentnum.m_data=0.0001*atof(buffer1);samp_datacurrentnum.n_data=atof(buffer2);clistbox * pp=(clistbox*)getdlgitem(idc_listm);strcpy(listchar,"m:");sprintf(a,"%10.4f",samp_datacurrentnum.
39、m_data);strcat(listchar,a);strcat(listchar," n:");strcat(listchar,buffer2);pp->addstring( listchar);currentnum+;cstatic *ps=(cstatic*)getdlgitem(idc_static_num);itoa(currentnum,a,10);ps->setwindowtext(a);cbutton * p2=(cbutton*)getdlgitem(idc_button_write);if(recnum>0)&&(cu
40、rrentnum=recnum)&&(connected)&&(strcmp(tbname,"null")!=0)p2->showwindow(sw_show);elsep2->showwindow(sw_hide);/此時出現(xiàn)可以記錄入數(shù)據(jù)庫的按鈕提示用戶可以將數(shù)據(jù)存入數(shù)據(jù)庫了cwnd:settimer(1,1000,null); /恢復對定時器的響應/-/*void cexampleview:getcomportdata_forjw1a()cwnd:killtimer(1); dword nnumberofbytestorea
41、d; dword nbytesread; char buffer1128, buffer2128;char mychar; int i; for(i=0; i<128; i+)buffer1i = buffer2i = '0' rs232->setupcomport();/clear i/o buffer. nnumberofbytestoread = 1; i = 0; do rs232->readcomport(nnumberofbytestoread, nbytesread); mychar = rs232->combuffer0; buffer1
42、i = mychar; i+; while( i < 19 );double m, n, temp;/mtemp = buffer11 - '0'm = temp * pow(10.0, 4.0);temp = buffer12 - '0'm += temp * pow(10.0, 3.0);temp = buffer13 - '0'm += temp * pow(10.0, 2.0);temp = buffer14 - '0'm += temp * 10.0;temp = buffer15 - '0'm +
43、= temp; temp = buffer10;if( temp = '-' )m *= -1; temp = buffer116-'0' m *= pow(10.0, -temp);/ntemp = buffer16 - '0'n = temp * pow(10.0, 4.0);temp = buffer17 - '0'n += temp * pow(10.0, 3.0);temp = buffer18 - '0'n += temp * pow(10.0, 2.0);temp = buffer19 - '
44、0'n += temp * 10.0;temp = buffer110 - '0'n += temp; temp = buffer117-'0' n *= pow(10.0, -temp);sprintf(buffer1, "%.2f", m);sprintf(buffer2, "%.2f", n);m_torque.setwindowtext( buffer1 );m_rpm.setwindowtext( buffer2 ); cwnd:settimer(1,1000,null);/-*/void cexampl
45、eview:ontimer(uint nidevent) /對定時器的響應/ todo: add your message handler code here and/or call default /for pi-100getcomportdata();/for jw-1a/getcomportdata_forjw1a(); cformview:ontimer(nidevent);bool cexampleview:connectok()dword nnumberofbytestowrite;dword nbyteswritten,nnumberofbytestoread,nbytesrea
46、d;nnumberofbytestowrite=4;rs232->setupcomport(); /初始化串口,準備傳輸數(shù)據(jù)。strcpy(rs232->combuffer,"rts;"); this->rs232->writecomport(nnumberofbytestowrite,nbyteswritten);nnumberofbytestoread=3;rs232->readcomport(nnumberofbytestoread, nbytesread);rs232->combuffer2='0'if(!strc
47、mp(rs232->combuffer,"ok")return false;return true;void cexampleview:onconnect () / todo: add your control notification handler code hereif(db.step1(false,m_hwnd)=sql_success)afxmessagebox("connect is ok!");cbutton * p=(cbutton *)getdlgitem(idc_button1); p->showwindow(sw_hid
48、e);p=(cbutton *)getdlgitem(idc_button4); p->showwindow(sw_show);connected=true;p=(cbutton*)getdlgitem(idc_button_newtable);p->showwindow(sw_show); void cexampleview:onrecord () / todo: add your control notification handler code herethis->beginrecord=true;cstring str;cedit *p=(cedit *)getdlgitem(idc_edit1_recnum);p->getwindowtext(str);recnum=atoi(str); /將字符型數(shù)據(jù)轉(zhuǎn)換為整型數(shù)據(jù)free(samp_data);samp_data=(struct s_data *) malloc (sizeof (s_data)*recnum);currentnum=0;clistbox *p1=(clistbox *)getdlgitem(idc_listm);p1->resetcontent( );cbutton * p2=(cbutton*)getdlgitem(idc_button_write
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年交接器項目可行性研究報告
- 2025至2030年中國盤式電機數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國氣動防爆氣扇數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國冰箱專用冰磚數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國丁胺黑藥數(shù)據(jù)監(jiān)測研究報告
- 2025年中國電腦彩繪指甲機市場調(diào)查研究報告
- 2025-2030年復古風格皮質(zhì)沙發(fā)套企業(yè)制定與實施新質(zhì)生產(chǎn)力戰(zhàn)略研究報告
- 2025-2030年房車露營地加盟合作行業(yè)跨境出海戰(zhàn)略研究報告
- 2025-2030年揉捏式按摩器行業(yè)跨境出海戰(zhàn)略研究報告
- 2025-2030年手工采摘黃桃罐頭行業(yè)深度調(diào)研及發(fā)展戰(zhàn)略咨詢報告
- 2025年度院感管理工作計劃(后附表格版)
- 勵志課件-如何做好本職工作
- 化肥銷售工作計劃
- 2024浙江華數(shù)廣電網(wǎng)絡股份限公司招聘精英18人易考易錯模擬試題(共500題)試卷后附參考答案
- 2024年山東省濟南市中考英語試題卷(含答案解析)
- 2024年社區(qū)警務規(guī)范考試題庫
- 2025中考英語作文預測:19個熱點話題及范文
- 第10講 牛頓運動定律的綜合應用(一)(講義)(解析版)-2025年高考物理一輪復習講練測(新教材新高考)
- 2024春節(jié)后復工消防安全專題培訓
- 班組建設與班組長管理培訓
- 三級老年病醫(yī)院評審標準實施細則(2020年版)
評論
0/150
提交評論