| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 734 人关注过本帖
标题:[开源]最近做的一个FPGA配套软件
只看楼主 加入收藏
旋风王子
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-7-21
收藏
 问题点数:0 回复次数:1 
[开源]最近做的一个FPGA配套软件

图片附件: 游客没有浏览图片的权限,请 登录注册

源码:

'定义窗体级变量
'在显示、绘图、报警等过程中使用
Dim datatemp(1000) As Single '用于存储温度采样值
Dim num As Integer '用于存储采样值个数
Dim filedata(1000) As String '数据的字符串形式
Private Sub Form_load()
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
Call tabinit
End Sub
Private Sub Combo1_Click()
OpenCom
End Sub

Private Sub Combo1_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Private Sub Combo2_Click()
OpenCom
End Sub

Private Sub Combo2_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub


'串口初始化
'在窗体的Load事件中加入下列代码对串口进行初始化:
Sub OpenCom()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = Val(Mid(Combo1.Text, 4, Len(Combo1.Text) - 3))
MSComm1.InputMode = 0
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.Settings = Form1.Combo2.Text + "," + "n,8,1"
MSComm1.PortOpen = True
Timer1.Interval = Form1.Combo3.Text
Call tabinit '调用表格初始化子程序
End Sub
'开始采集
Private Sub Cmdstart_Click()
Timer1.Enabled = True
MSComm1.Output = Chr(&H10)
End Sub
'停止采集
Private Sub Cmdstop_Click()
Timer1.Enabled = False
MSComm1.Output = Chr(&H0)
End Sub
'选择通道0
Private Sub Cmdch0_Click()
MSComm1.Output = Chr(&H10)
End Sub
'选择通道1
Private Sub Cmdch1_Click()
MSComm1.Output = Chr(&H11)
End Sub

Private Sub Combo3_Click()
OpenCom
End Sub

Private Sub Combo3_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub

'每发送一次指令,触发下面事件,返回数据串
Private Sub MSComm1_OnComm()
Dim Inbyte() As Byte
Dim buffer As String
Dim datatemp2a, datatemp2b As String
Dim datatemp2 As String
Dim cut() As String
If num > 199 Then Call renew
'读取仪表返回数据串
Select Case MSComm1.CommEvent
Case comEvReceive
Inbyte = MSComm1.Input
For i = LBound(Inbyte) To UBound(Inbyte)
buffer = buffer + Hex(Inbyte(i)) + Chr(32)
Next i
Case comEvSend
End Select
'获取十进制测量数据
If Timer1.Enabled = True Then
datatemp(num) = Val(Mid(buffer, 1, 2))
End If
'显示测量温度值
If datatemp(num) <> 0 Then
Grid.Col = 1: Grid.Row = num + 1
Grid.Text = Format$(datatemp(num), "0.0")
TempText = Format$(datatemp(num), "0.0") '10进制显示,保留一位小数
num = num + 1
Call cal '调用计算极值、平均值子程序
Call draw '调用绘曲线过程
End If
End Sub
'计算极值、平均值
Sub cal()
On Error GoTo hh
Sum = 0
Max = datatemp(0): Min = Max
For i = 0 To num - 1
If datatemp(i) >= Max Then Max = datatemp(i)
If datatemp(i) <= Min Then Min = datatemp(i)
Sum = Sum + datatemp(i)
Next i
aver = Sum / num
MaxText.Text = Format$(Max, "0.0")
MinText.Text = Format$(Min, "0.0")
AverText.Text = Format$(aver, "0.0")
hh: Exit Sub
End Sub
'绘制温度实时变化曲线
Private Sub draw()
Picture1.Cls
Picture1.DrawWidth = 1
Picture1.BackColor = QBColor(15)
Picture1.Scale (0, 100)-(400, 0)
For i = 1 To num - 1
X1 = (i - 1): Y1 = datatemp(i - 1)
X2 = i: Y2 = datatemp(i)
Picture1.Line (X1, Y1)-(X2, Y2), QBColor(0)
Next i
End Sub
'刷新
Private Sub renew()
If num = 0 Then Exit Sub
TempText.Text = "": AverText.Text = ""
MinText.Text = "": MaxText.Text = ""
Grid.Clear
Picture1.Cls
For i = 0 To num - 1
datatemp(i) = 0
Next i
num = 0
Call tabinit
End Sub
'数据表格初始化
Public Sub tabinit()

Grid.Cols = 2
Grid.Rows = 200 + 1
Grid.ColWidth(0) = 700
Grid.ColWidth(1) = 950
Grid.Col = 0
For i = 1 To 200
Grid.Row = i
Grid.Text = " " + Str$(i)
Next i
Grid.Row = 0
Grid.Col = 0: Grid.Text = " 序号"
Grid.Col = 1: Grid.Text = " 温度值"
Grid.TopRow = 1 '置在第一页
Grid.LeftCol = 1

End Sub
'当退出程序时,关闭串行口
Private Sub Cmdquit_Click()
Unload Me
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
MSComm1.PortOpen = False '关闭串口
End Sub

'存储数据到文本文件
Private Sub Cmdsave_Click()
On Error GoTo hh
If num = 0 Then Exit Sub
Timer1.Enabled = False
CDsave.Filter = "*.txt|*.txt|"
F3 = FreeFile
CDsave.ShowSave
fname = CDsave.FileName
Open fname For Output As #F3
For j = 0 To num - 1
filedata(j) = datatemp(j)
Print #F3, filedata(j)
Next j
Close #F3
hh: Exit Sub
End Sub
'打开数据文件
Private Sub Cmdopen_Click()
Dim l As Long
Dim a As String, b As String, X As String
On Error GoTo errhandler
Timer1.Enabled = False
CDopen.Filter = "*.txt|*.txt|"
CDopen.FilterIndex = 1
CDopen.Action = 1
fname = CDopen.FileName
Call renew
F% = FreeFile
Open fname For Input As #F%
Do
Input #F%, filedata(num)
datatemp(num) = Val(filedata(num))
Grid.Col = 1: Grid.Row = num + 1
Grid.Text = filedata(num)
num = num + 1
Loop Until EOF(F%)
Close #F%
Call cal
Call draw
Exit Sub
errhandler:
Exit Sub
End Sub


搜索更多相关主题的帖子: FPGA 软件 开源 
2007-07-21 15:30
hai99
Rank: 1
等 级:新手上路
帖 子:146
专家分:0
注 册:2007-7-2
收藏
得分:0 
谢谢!注释再多点就更好了!我们初学的看起来会容易些!
2007-07-21 18:25
快速回复:[开源]最近做的一个FPGA配套软件
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039336 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved