热度 3
2013-10-22 02:37
3180 次阅读|
1 个评论
所谓的花里挑花,也即一直选型的——上位机软件开发,从VB到VC++,在到C++Builder,在到QT,再到LabView等等,最后选中了CVI(LabWindows/CVI),感觉良好,所以大家都懂得。因为是刚开始,所以好多知识点可能还做的不到位,望各位高手别拍砖,而是多多指教,先谢。 由于自己爱好和出书的缘故,必须的搞定上位机的开发,所以先来个2小时的成果,望能和大家共勉。 说明:界面有点丑,没夜月狼丑,望包涵哈! 先介绍一下,所谓下位机是MGMC-V1.0实验板,核心器件:单片机+LM75A温度传感器,实时采集当前温度,并通过串口打印到PC机上,最后结合自己编写的上位机软件,演示效果如上,说明此时温度也不高(18.125)啊。其实自己也想睡在被窝里,可是既然选择了这条路,没有退路,所以必须得搞起,呵呵。。。 最后来上整个上位机的源码,该源码自己当然能理解,也会写,但是还没真正吃透,因为才学了2个小时嘛,所以望理解,不过相信自己很快就能搞定,之后再给大家详细的注释和说明,若喜欢请等待,若不喜欢,请轻轻的走开,不要带走一点点“孤独”,也不要留下一丝丝“恶意”。 /* =============================================================== */ #include rs232.h #include ansi_c.h #include "sample5.h" static int panelHandle; int ComSelect=0; int status; char info ; // 字符型数组,用于存放发送、接收的字符串 int CVIFUNC DimObject(int stat) //设置页面控件状态,stat=0表示串口关闭,1串口打开 { SetCtrlAttribute(panelHandle,PANEL_COMSELECT,ATTR_DIMMED ,stat); SetCtrlAttribute(panelHandle,PANEL_BTLSELECT,ATTR_DIMMED ,stat); SetCtrlAttribute(panelHandle,PANEL_JYSELECT,ATTR_DIMMED ,stat); SetCtrlAttribute(panelHandle,PANEL_LONGSELECT,ATTR_DIMMED ,stat); SetCtrlAttribute(panelHandle,PANEL_STOPSELECT,ATTR_DIMMED ,stat); SetCtrlAttribute(panelHandle,PANEL_OPEN_COM,ATTR_DIMMED ,stat); SetCtrlAttribute(panelHandle,PANEL_CLOSE_COM,ATTR_DIMMED ,!stat); SetCtrlAttribute(panelHandle,PANEL_SEND,ATTR_DIMMED ,!stat); SetCtrlAttribute(panelHandle,PANEL_CLEARSEND,ATTR_DIMMED ,!stat); SetCtrlAttribute(panelHandle,PANEL_RECIEVE,ATTR_DIMMED ,!stat); SetCtrlAttribute(panelHandle,PANEL_CLEARRECIVE,ATTR_DIMMED ,!stat); return 0; } int main (int argc, char *argv ='\0'; SetCtrlVal(PANEL,PANEL_RECIVETEXT,info); //SetActiveCtrl(PANEL,PANEL_RECIVETEXT); // 考虑中! break; } return 0; } int CVICALLBACK Quit (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: if(ComSelect) { CloseCom(ComSelect); ComSelect=0; DimObject(0); } QuitUserInterface (0); break; } return 0; } int CVICALLBACK ComOpen (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int comValue,btlValue,jhValue,longValue,stopValue; switch (event) { case EVENT_COMMIT: GetCtrlVal(PANEL,PANEL_COMSELECT,comValue); //选择串口 GetCtrlVal(PANEL,PANEL_BTLSELECT,btlValue); //选择波特率 GetCtrlVal(PANEL,PANEL_JYSELECT,jhValue); //选择奇偶校验 GetCtrlVal(PANEL,PANEL_LONGSELECT,longValue); //选择数据位 GetCtrlVal(PANEL,PANEL_STOPSELECT,stopValue); //选择停止位 //设置和打开串口 status=OpenComConfig(comValue,"",btlValue,jhValue, longValue,stopValue,512,512); if(status!=0) { MessagePopup("Error","config failed!"); return 0; } SetCTSMode(comValue,LWRS_HWHANDSHAKE_OFF); FlushInQ(comValue); //清空输入和输出缓冲区 FlushOutQ(comValue); ComSelect=comValue; DimObject(1); break; } return 0; } int CVICALLBACK ComClose (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: CloseCom(ComSelect); ComSelect=0; DimObject(0); break; } return 0; } int CVICALLBACK ClearTextBox (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: if(control==PANEL_CLEARRECIVE) ResetTextBox(PANEL,PANEL_RECIVETEXT,"\0");//清空接收文本框 else ResetTextBox(PANEL,PANEL_SENDTEXT,"\0");//清空发送文本框 break; } return 0; } 演示完毕,一点“滚蛋”和一把实验板电源开关,上位机软件、实验板、自己统统睡觉,因为时间不早了啊(午夜2:40),大家都累了,晚安、好梦。。。