⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 项目是为日本瑞萨工作所做的BAKE炉温控系统 整个文件夹包括设计文档
💻 VB
📖 第 1 页 / 共 5 页
字号:
    ''''''        ShowFlag3 = True
    ''''''        Button3.Text = "不显示3#"
    ''''''    End If
    ''''''End Sub
    ''''''REM "显示4#"按钮
    ''''''Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    ''''''    If Button4.Text = "不显示4#" Then
    ''''''        ShowFlag4 = False
    ''''''        Button4.Text = "显示4#"
    ''''''    Else
    ''''''        ShowFlag4 = True
    ''''''        Button4.Text = "不显示4#"
    ''''''    End If
    ''''''End Sub
    REM 单击"查询"按钮
    Private Sub SearchBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBut.Click
        Dim str0 As String, str1 As String, str2 As String, strInfo As String
        Dim Sdate As String, Edate As String

        REM 显示DataGrid
        DataGrid1.Visible = True
        DataGrid1.Focus()

        REM 查询日期
        Sdate = DateTimePicker1.Text
        Edate = DateTimePicker2.Text

        REM SQL语句初始化
        str0 = "NO" & Val(ComboBox4.Text)
        str1 = "记录日期,当前温度,设定温度,当前时间,设定时间,是否异常"
        str2 = "记录日期 >= # " & Sdate & "# and 记录日期 <= #" & Edate & "# order by 记录日期 "

        REM searchTB(查询的字段,查询的表,查询的条件,显示的DataGrid控件,用于添加的TableStyle)
        strInfo = searchTB(str1, str0, str2, DataGrid1, objts)

SearchBut_exit:
        objts.Dispose()

    End Sub

    REM 单击"导出"按钮
    Private Sub OutBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OutBut.Click
        Dim i As Integer, j As Integer
        Dim rowcount As Integer, colcount As Integer
        Dim Selectstr, Wherestr, FromTB As String


        REM 计算表的行数和列数
        rowcount = objTB.Rows.Count : colcount = objTB.Columns.Count '记录的行、列值
        If rowcount <= 0 Then MsgBox("记录为空,不能导出!") : GoTo OutBut_exit

        REM 将记录集objTB中的内容导出致.CVS文件
        Dim strName As String
        filename = "1# Bake炉 "
        strName = DataSetToCSV(rowcount, colcount, filename, objTB)
        If strName <> "" Then MsgBox("该记录文件的存储路径为:" & strName)
OutBut_exit:

    End Sub

    '==========================================内部函数===============================================================================
    '**************************************************************************
    '功能:根据条件查询数据库并返回符合条件的记录个数,将查询到的信息显示在Grid中
    '入口:查询的字段串str1,表名串strTB,条件字段str2,控件Grid
    '出口:符合条件的记录个数
    '**************************************************************************
    Public Function searchTB(ByVal str1 As String, ByVal strTB As String, ByVal str2 As String, ByVal Grid As System.Windows.Forms.DataGrid, ByVal ts2 As DataGridTableStyle) As String
        Dim Selectstr, Wherestr, FromTB As String
        Dim rowcount As Integer
        Dim ReturnNum As Integer = 0, strExit As String

        REM SQL语句初始化
        Selectstr = str1
        FromTB = strTB
        Wherestr = str2

        REM connection 和 command 的初始化
        Dim objConn As OleDbConnection = GetConn()
        If objConn.State = ConnectionState.Closed Then
            objConn.Open()
        End If
        objCmd.Connection = objConn
        objCmd.CommandText = "select " & Selectstr & " from " & FromTB & " where " & Wherestr        'select语句

        REM table 绑定
        objDA = New OleDbDataAdapter(objCmd)
        Dim objDS As New DataSet
        objDS.Clear()
        objDA.Fill(objDS, "tmpTB")   'tmpTB只是一个中转,用来暂存表,不需定义
        objTB = objDS.Tables("tmpTB")

        REM 计算表的行数和列数
        rowcount = objTB.Rows.Count
        If rowcount <= 0 Then MsgBox("记录为空,不能导出!") : GoTo searchTB_exit

        REM 返回值
        strExit = ReturnNum

        REM Grid部分
        Grid.SetDataBinding(objDS, "tmpTB") '数据源
        ts2.MappingName = "tmpTB"
        ts2.AlternatingBackColor = Color.LightBlue

        REM GridShed中的列变量
        Dim cOrderDate1 As New DataGridTextBoxColumn, cOrderDate2 As New DataGridTextBoxColumn
        Dim cOrderDate3 As New DataGridTextBoxColumn, cOrderDate4 As New DataGridTextBoxColumn
        Dim cOrderDate5 As New DataGridTextBoxColumn, cOrderDate6 As New DataGridTextBoxColumn
        ts2.GridColumnStyles.Clear()  '清空以前的各列

        '添加各列
        cOrderDate1.MappingName = "记录日期" : cOrderDate1.HeaderText = "记录日期" : cOrderDate1.Width = 180 : ts2.GridColumnStyles.Add(cOrderDate1)
        cOrderDate2.MappingName = "当前温度" : cOrderDate2.HeaderText = "当前温度" : cOrderDate2.Width = 100 : ts2.GridColumnStyles.Add(cOrderDate2)
        cOrderDate3.MappingName = "设定温度" : cOrderDate3.HeaderText = "设定温度" : cOrderDate3.Width = 100 : ts2.GridColumnStyles.Add(cOrderDate3)
        cOrderDate4.MappingName = "当前时间" : cOrderDate4.HeaderText = "当前时间" : cOrderDate4.Width = 100 : ts2.GridColumnStyles.Add(cOrderDate4)
        cOrderDate5.MappingName = "设定时间" : cOrderDate5.HeaderText = "设定时间" : cOrderDate5.Width = 100 : ts2.GridColumnStyles.Add(cOrderDate5)
        cOrderDate6.MappingName = "是否异常" : cOrderDate6.HeaderText = "是否异常" : cOrderDate6.Width = 100 : ts2.GridColumnStyles.Add(cOrderDate6)

searchTB_exit:
        Grid.TableStyles.Add(ts2)
        objConn.Close()
        Return strExit
    End Function

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub


    REM 选定校准MCU号
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub ComboBox5_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox5.SelectionChangeCommitted

        Timer3.Enabled = True
        '初始化选路控件
        InitComBox2(ComboBox6, ComboBox5.SelectedValue)
        Dim g As Graphics
        Dim i As Integer, j As Integer
        Dim x0 As Single, y0 As Single
        Dim x1 As Point, y1 As Point, x2 As Point, y2 As Point
        g = PictureBox5.CreateGraphics()
        '清空画的图
        g.Clear(Color.Coral)
        '画XY轴
        g.DrawLine(Pens.Blue, New Point(20, 20), New Point(20, 250))
        g.DrawLine(Pens.Blue, New Point(20, 250), New Point(350, 250))
        '画XY的刻度及单位
        x0 = 20 : y0 = 250
        '查找channel的信息
        SearchAD(ComboBox5.SelectedValue)
        DrawXY2(PictureBox5, x0, y0, ComboBox5.SelectedValue)
        '画各个连接线
        DrawnCurve2(PictureBox5, x0, y0)
        g.Dispose()

    End Sub




    '*****************************************0907加**********************************************
    REM "删除所选"下拉框
    Private Sub ComboBox6_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox6.SelectedIndexChanged
        Dim no As Byte
        Dim str, substr1, substr2 As String
        Dim no1, no2 As Integer
        Dim x, y As Integer

        REM 获取2个下拉框中选中内容
        no = ComboBox5.SelectedIndex
        str = ComboBox6.Text

        REM 提取删除所选中的x,y值
        no1 = InStr(str, "x")
        no2 = InStr(str, "y")
        substr1 = Mid(str, no1 + 2, (no2 - 1) - (no1 + 2))
        x = Val(substr1)
        substr2 = Mid(str, no2 + 2, 3)
        y = Val(substr2)

        REM 确定+取消删除窗口
        If MsgBox("确定要删除:" & Chr(13) & Chr(10) & Chr(10) & "   AD值=" & x & Chr(13) & Chr(10) & "   物理量=" & y, MsgBoxStyle.OKCancel, "删除所选") = MsgBoxResult.Cancel Then
            Exit Sub
        End If

        REM 从库中删除校准值
        DelReviseVal(no, x)

        REM 删除成功
        MsgBox("删除成功!")

        REM 重新加载此下拉框,并画图
        ComboBox5_SelectionChangeCommitted(Nothing, Nothing)

    End Sub
    '===============================================0907加=======================================================================





    Private Sub Timer3_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        StateTxt.Text = ""
        Timer3.Enabled = False
        Dim no As Byte = ComboBox5.SelectedValue
        ReDim G_SendData(4)
        G_SendData(0) = 130 + no
        G_SendData(1) = CByte(Asc("R"))
        G_SendData(2) = 0
        G_SendData(3) = 0
        G_SendData(4) = 69                         '帧尾'E'=69
        SCISendN(MSComm1, G_SendData)

        Dim tmp As Byte = G_RecvNum - 1
        ReDim G_RecvData(tmp)
        SCIRecvN(MSComm1, G_RecvNum, 3)
        If G_RecvData(0) <> 83 And G_RecvData(tmp) <> 69 Then
            Form1.frmMain.StateTxt.Text = G_RecvData(0) & G_RecvData(tmp)
            Exit Sub
        End If
        '当前选中通道的AD值
        G_CurrentAD = G_RecvData(tmp - 2) * 256 + G_RecvData(tmp - 1)  '当前温度的AD位于帧尾前的2字节
        lbAD.Text = G_CurrentAD
        lbPhy.Text = ADToPhy(G_CurrentAD, no)

        btnRevise.Enabled = True
        Timer3.Enabled = True
    End Sub
    REM 单击"校准"按钮
    Private Sub btnRevise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRevise.Click

        Dim myValue As String                           '定义临时串变量
        Dim j As Integer
        Dim x1 As Integer, x2 As Integer, y1 As Single, y2 As Single, y0 As Single
        Dim message, title, defaultValue As String
        Dim g As Graphics
        ''''''''''''''''Dim flag1 As Boolean = False
        g = PictureBox5.CreateGraphics()
        Dim no As Byte = ComboBox5.SelectedValue

        Timer3.Enabled = False   '0904加,校准时停止收数据

        If G_RecordNum >= G_MaxRecordNum Then     '*********************************************************************************0907加
            MsgBox("校准点已经超过" & G_MaxRecordNum & "条!" & Chr(13) & Chr(10) & "请先删除再校准!")
            Exit Sub
        End If

        ''''''''''''''''''''''''''''''''''''''''''''''''
        ' G_CurrentAD = 718   '调试用
        '''''''''''''''''''''''''''''''''''''''''''''
        REM x0为本路当前的A/D值,已知,下面找出X1、X2两点,X1<X0<X2
        For j = LBound(G_X) + 1 To UBound(G_X)           '对数组x循环
            If G_X(j) > G_CurrentAD Then
                x1 = G_X(j - 1) : x2 = G_X(j) '找到了两点
                y1 = G_Y(j - 1) : y2 = G_Y(j)
                '''''''''''If (G_CurrentAD - x1) < 1 Or (x2 - G_CurrentAD) < 1 Then
                '''''''''''    MsgBox("选择点距离太近,放弃本次选择。", 16, "选择点错误")
                '''''''''''    Exit For
                '''''''''''End If
                '''''''''''flag1 = True
                Exit For
            End If
        Next j
        '''''''''''If flag1 = False Then Exit Sub '如果没有合适的两点,退出

        REM input X0 得 y0
        title = "模拟量校正—物理量标准值输入"
        message = "当前值" & G_CurrentPhy & ",请输入标准值(" & G_MinPhy & "-" & G_MaxPhy & ")"
        myValue = InputBox(message, title, )
        y0 = Val(myValue)
        If y0 < G_MinPhy Or y0 > G_MaxPhy Then   '??????????myValue是string型,可以比较大小嘛?
            MsgBox("输入的数值超出范围!")
            Exit Sub
        End If

        REM 校准即写入数据库
        WriteDB(no, G_CurrentAD, y0, x1, y1, x2, y2)

        '************************************************************************************************0907加,校准后重画
        ComboBox5_SelectionChangeCommitted(Nothing, Nothing)

        REM 校准后要写Flash
        ''''''''''''''       WriteFlash()

        Timer3.Enabled = True  '0904加

    End Sub

    REM 单击"写入"按钮
    Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
        Timer3.Enabled = False   '0904加,校准时停止收数

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -