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

📄 com.frm

📁 应朋友之托
💻 FRM
📖 第 1 页 / 共 2 页
字号:
      Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
         Height          =   3375
         Left            =   -74760
         TabIndex        =   21
         Top             =   600
         Width           =   6135
         _ExtentX        =   10821
         _ExtentY        =   5953
         _Version        =   393216
         FixedCols       =   0
         BackColorBkg    =   12632256
         AllowUserResizing=   1
      End
      Begin VB.PictureBox Picture1 
         Appearance      =   0  'Flat
         AutoRedraw      =   -1  'True
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   1485
         Left            =   3840
         ScaleHeight     =   1485
         ScaleWidth      =   2250
         TabIndex        =   23
         Top             =   1560
         Width           =   2250
      End
      Begin VB.Label Label4 
         Caption         =   "数据长度:"
         Height          =   375
         Left            =   -71640
         TabIndex        =   20
         Top             =   3480
         Width           =   1335
      End
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   5040
      Top             =   1080
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      RThreshold      =   1
      SThreshold      =   1
   End
End
Attribute VB_Name = "SetForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim i As Integer
Dim S As String
Dim S1 As String
Dim KaiShi() As String      '开始表示
Dim JianCe As Boolean     '监测状态
Dim iStr() As String
Dim BufA
Dim JShStr As String
Dim FSStr As String
Dim myPath As String


Private Sub Command2_Click()         '退出程序部分
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
Close #1
End
End Sub


Private Sub Command5_Click()
If Command5.Caption = "开始测试" Then
    JianCe = True
    Command5.Caption = "停止测试"
'    myReadCOM
Else
    JianCe = False
    Command5.Caption = "开始测试"
End If

End Sub

Private Sub Form_Load()   '程序开始入口
SetForm.Show
DoEvents
myPath = App.Path             '程序运行路径
If Right(myPath, 1) <> "\" Then myPath = myPath & "\"
Open myPath & "Data.txt" For Output Shared As #1
myPath = myPath & "scomport.ini"
myReState
End Sub

Private Sub MSComm1_OnComm()

BufA = MSComm1.Input
Text2 = Text2 & BufA
If JianCe Then myReadCOM

End Sub

Sub myReadCOM()

On Error Resume Next

Dim l As Integer
Dim f As Integer
Dim iTmp As String    '要加入表格的内容
Dim Biao As Boolean

iTmp = BufA
BufA = ""
'iTmp = "E800F2301A320B560C1200D150E350F100A2530 B35 00C120D800E1600F100"

For f = 1 To Len(iTmp)
    BufA = Mid(iTmp, f, 1)
    For i = 0 To UBound(KaiShi)
        If BufA = KaiShi(i) Then
            If i = 0 Then
                S1 = S1 & Chr(9) & Trim(S) & Chr(9) & Time
                MSFlexGrid1.AddItem S1, MSFlexGrid1.Rows - 1
                MSChart1.RowCount = MSFlexGrid1.Rows - 1
                Write #1, S1
                S1 = ""
                S = ""
            End If
            Biao = True
            Exit For
        Else
            Biao = False
        End If
    Next i
    If Biao Then
        If S1 = "" Then
            S1 = S
       Else
            S1 = S1 & Chr(9) & S
        End If
        If IsNumeric(S) Then
            MSChart1.Column = i
            MSChart1.Row = MSFlexGrid1.Rows - 1
            MSChart1.Data = S
        End If
        S = ""
    Else
        S = S & BufA
    End If
Next f
            
'S1 = ""
'S = ""
    

End Sub

Sub myReState()  '初始模块,在程序开始时,及改变设置时调用

On Error Resume Next

T1(0) = Trim(myReadINI(myPath, "接收端口", "端口号", "1"))
T1(1) = Trim(myReadINI(myPath, "接收端口", "波特率", "9600"))
T1(2) = Trim(myReadINI(myPath, "接收端口", "数据位", "8"))
T1(3) = Trim(myReadINI(myPath, "接收端口", "停止位", "1"))
For i = 0 To 2
    If CInt(myReadINI(myPath, "接收端口", "校验方式", "0")) = i Then Option1(i).Value = True
Next i


Text3 = myReadINI(myPath, "数据格式", "开始标志", " ")

KaiShi = Split(Text3, ",")

For i = 0 To 2
    If Option1(i).Value = True Then
        Select Case i
            Case 0
                JShStr = "N"
            Case 1
                JShStr = "O"
            Case 2
                JShStr = "E"
        End Select
    End If
Next i
JShStr = T1(1) & "," & JShStr & "," & T1(2) & "," & T1(3)


MSFlexGrid1.Clear
MSFlexGrid1.Rows = 2
MSFlexGrid1.Cols = UBound(KaiShi) + 1
S = ""
For i = 0 To MSFlexGrid1.Cols - 1
    S = S & KaiShi(i) & "          " & "|"
Next i
S = S & "时间                   "
MSFlexGrid1.FormatString = S
S = ""

MSComm1.Settings = JShStr
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = T1(0)
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True


With MSChart1
    .chartType = VtChChartType2dLine
    .ColumnCount = UBound(KaiShi) + 1
    .RowCount = MSFlexGrid1.Rows - 1
    For i = 0 To UBound(KaiShi)
        .Column = i + 1
        .ColumnLabel = KaiShi(i)
    Next i
End With

End Sub


Private Sub Text2_Change()
Text5 = Len(Text2)
End Sub

Private Sub Text3_GotFocus()
Text3.SelStart = 0
Text3.SelLength = Len(Text3)
End Sub

Private Sub Command1_Click()               '保存设置到ini文件

Dim x

For i = 0 To 3
    If T1(i) = "" Or Text3 = "" Then
        MsgBox ("数据不完整,请检查后重新输入并保存!")
        myReState
        Exit Sub
    End If
Next i
x = myWriteINI(myPath, "接收端口", "端口号", T1(0))
x = myWriteINI(myPath, "接收端口", "波特率", T1(1))
x = myWriteINI(myPath, "接收端口", "数据位", T1(2))
x = myWriteINI(myPath, "接收端口", "停止位", T1(3))
For i = 0 To 2
    If Option1(i).Value = True Then x = myWriteINI(myPath, "接收端口", "校验方式", CStr(i))
Next i
    
x = myWriteINI(myPath, "数据格式", "开始标志", Text3)

myReState

End Sub

⌨️ 快捷键说明

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