1、第第5章章万能通信之只收不发万能通信之只收不发转速测量转速测量 Preparation of Hardware and Software 软硬件准备软硬件准备 5.1 Variable Definition and Control Associated 变量定义与构件关联变量定义与构件关联 5.2 Configuration of Strategy 策略组态策略组态 5.3 Program Running 程序运行程序运行软硬件准备工作软硬件准备工作 Preparation of Hardware and Software 软硬件准备软硬件准备 Preparation of Hardware
2、and Software 软硬件准备软硬件准备 TTL 3.3V电平!电平!RS232为为12V电平!电平!Preparation of Hardware and Software 软硬件准备软硬件准备 (1)GNDGND(2)TxDRxD(3)RxDTxD本例特殊本例特殊(2)TxDTxD(3)RxDRxD Preparation of Hardware and Software 软硬件准备软硬件准备 Preparation of Hardware and Software 软硬件准备软硬件准备 Preparation of Hardware and Software 软硬件准备软硬件准备
3、软件调试软件调试 Preparation of Hardware and Software 软硬件准备软硬件准备 4800,N,8,1波波特特率率数数据据位位停停止止位位奇奇偶偶校校验验 Preparation of Hardware and Software 软硬件准备软硬件准备 Preparation of Hardware and Software 软硬件准备软硬件准备 Variable Definition and Control Associated 变量定义与构件关联变量定义与构件关联 变量定义变量定义Variable Definition and Control Associat
4、ed 变量定义与构件关联变量定义与构件关联 变量名变量名数据类型数据类型注释注释BaudRate数值型波特率CommError1数值型波特率错误指示CommError2数值型数据位错误指示CommError3数值型停止位错误指示CommError4数值型校验位错误指示CommNo数值型串口号Count数值型每条数据记录的编号DataBit数值型数据位FileName字符型数据文件的名字ParityBit数值型奇偶校验位ReceiveStr字符型从串口接收到的数据SaveData开关型用于控制“开始保存”与“停止保存”按钮的显隐StopBit数值型停止位转速值数值型测得的霍尔元件的计数值Conf
5、iguration of Strategy 策略组态策略组态策略定义策略定义Configuration of Strategy 策略组态策略组态Configuration of Strategy 策略组态策略组态设置串口参数策略设置串口参数策略Configuration of Strategy 策略组态策略组态Configuration of Strategy 策略组态策略组态保存串口参数CommNo.SaveDataInitValue()BaudRate.SaveDataInitValue()DataBit.SaveDataInitValue()StopBit.SaveDataInitVal
6、ue()ParityBit.SaveDataInitValue()刷新到磁盘上!FlushDataInitValueToDisk()Configuration of Strategy 策略组态策略组态设定波特率CommError1=!SetSerialBaud(CommNo,BaudRate)IF CommError10 THEN EXITENDIF 设定数据位CommError2=!SetSerialDataBit(CommNo,DataBit)IF CommError20 THEN EXITENDIFConfiguration of Strategy 策略组态策略组态设定停止位CommEr
7、ror3=!SetSerialStopBit(CommNo,StopBit)IF CommError30 THEN EXITENDIF 设定校验位CommError4=!SetSerialParityBit(CommNo,ParityBit)IF CommError40 THEN EXITENDIFConfiguration of Strategy 策略组态策略组态定时接收数据策略定时接收数据策略Configuration of Strategy 策略组态策略组态Configuration of Strategy 策略组态策略组态串口未正确打开则退出IF CommError10 OR Comm
8、Error20 OR CommError30 OR CommError40 THEN EXITENDIF串口中无可读数据则退出IF!GetSerialReadBufferSize(CommNo)=0 THEN EXITENDIF从串口读数据ReceiveStr=!ReadSerialStr(CommNo)ReceiveStr=!Right(ReceiveStr,!Len(ReceiveStr)-1)转速值=!val(ReceiveStr)EXITConfiguration of Strategy 策略组态策略组态Configuration of Strategy 策略组态策略组态Configu
9、ration of Strategy 策略组态策略组态保存数据保存数据Configuration of Strategy 策略组态策略组态Configuration of Strategy 策略组态策略组态Count=0程序下载到触摸屏时用此代码FileName=usb harddiskData_+!str($Year)+年+!str($Month)+月+!str($Day)+日_+!str($Hour)+时+!str($Minute)+分+!str($Second)+秒+.txt程序在台式机上运行时采用此代码FileName=d:Data_+!str($Year)+年+!str($Month
10、)+月+!str($Day)+日_+!str($Hour)+时+!str($Minute)+分+!str($Second)+秒+.txt!FileWriteStr(FileName,1,序号时间转速值(r/min),1)Configuration of Strategy 策略组态策略组态Configuration of Strategy 策略组态策略组态停止保存停止保存开始保存开始保存SaveData1开始保存开始保存不可见不可见可见可见SaveData初始化为初始化为0Configuration of Strategy 策略组态策略组态Configuration of Strategy 策略
11、组态策略组态Configuration of Strategy 策略组态策略组态停止保存停止保存SaveData0开始保存开始保存可见可见不可见不可见停止保存停止保存Configuration of Strategy 策略组态策略组态Configuration of Strategy 策略组态策略组态Configuration of Strategy 策略组态策略组态串口参数界面设计串口参数界面设计Configuration of Strategy 策略组态策略组态Configuration of Strategy 策略组态策略组态曲线显示界面设计曲线显示界面设计Configuration of Strategy 策略组态策略组态Configuration of Strategy 策略组态策略组态程序运行程序运行Program Running 程序运行程序运行Program Running 程序运行程序运行Program Running 程序运行程序运行Program Running 程序运行程序运行Program Running 程序运行程序运行第第5章章万能通信之只收不发万能通信之只收不发转速测量转速测量谢谢!谢谢!