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

📄 signalsource.frm

📁 一个用VB编写的串口通信程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form SignalSource 
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "SignalSource"
   ClientHeight    =   2805
   ClientLeft      =   7110
   ClientTop       =   3750
   ClientWidth     =   3390
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2805
   ScaleWidth      =   3390
   ShowInTaskbar   =   0   'False
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   5
      Left            =   2580
      Top             =   480
   End
   Begin VB.Frame Frame2 
      Caption         =   "参数设置"
      Height          =   1455
      Left            =   0
      TabIndex        =   4
      Top             =   1320
      Width           =   3375
      Begin VB.TextBox phase 
         Alignment       =   1  'Right Justify
         Height          =   315
         Left            =   840
         TabIndex        =   10
         Text            =   "0"
         Top             =   1020
         Width           =   2295
      End
      Begin VB.TextBox frequency 
         Alignment       =   1  'Right Justify
         Height          =   315
         Left            =   840
         TabIndex        =   9
         Text            =   "50"
         Top             =   660
         Width           =   2295
      End
      Begin VB.TextBox am 
         Alignment       =   1  'Right Justify
         Height          =   315
         Left            =   840
         TabIndex        =   8
         Text            =   "2048"
         Top             =   300
         Width           =   2295
      End
      Begin VB.Label Label3 
         Caption         =   "相位"
         Height          =   255
         Left            =   240
         TabIndex        =   7
         Top             =   1080
         Width           =   555
      End
      Begin VB.Label Label2 
         Caption         =   "频率"
         Height          =   255
         Left            =   240
         TabIndex        =   6
         Top             =   720
         Width           =   555
      End
      Begin VB.Label Label1 
         Caption         =   "幅值"
         Height          =   255
         Left            =   240
         TabIndex        =   5
         Top             =   360
         Width           =   555
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "波形选择"
      Height          =   675
      Left            =   0
      TabIndex        =   0
      Top             =   600
      Width           =   3375
      Begin VB.OptionButton Option3 
         Caption         =   "方波"
         Height          =   255
         Left            =   2340
         TabIndex        =   3
         Top             =   300
         Width           =   975
      End
      Begin VB.OptionButton Option2 
         Caption         =   "三角波"
         Height          =   255
         Left            =   1260
         TabIndex        =   2
         Top             =   300
         Width           =   975
      End
      Begin VB.OptionButton Option1 
         Caption         =   "正弦波"
         Height          =   255
         Left            =   180
         TabIndex        =   1
         Top             =   300
         Value           =   -1  'True
         Width           =   975
      End
   End
   Begin VB.Image wave 
      Height          =   540
      Index           =   2
      Left            =   60
      Picture         =   "SignalSource.frx":0000
      Stretch         =   -1  'True
      Top             =   60
      Visible         =   0   'False
      Width           =   3255
   End
   Begin VB.Image wave 
      Height          =   540
      Index           =   1
      Left            =   60
      Picture         =   "SignalSource.frx":31C2
      Stretch         =   -1  'True
      Top             =   60
      Visible         =   0   'False
      Width           =   3255
   End
   Begin VB.Image wave 
      Height          =   540
      Index           =   0
      Left            =   60
      Picture         =   "SignalSource.frx":6384
      Stretch         =   -1  'True
      Top             =   60
      Width           =   3255
   End
End
Attribute VB_Name = "SignalSource"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Sub Image1_Click()

End Sub

Private Sub am_Change()
If CInt(am.Text) <= 2048 Then
sigam = CInt(am.Text)
End If
End Sub

Private Sub Form_Load()
retvalue = SetWindowPos(Me.hwnd, -1, Me.CurrentX, Me.CurrentY, 150, 110, &H40)
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2

Me.Height = 3165
Me.Width = 3480

sigam = 2047
sigfrequency = 314
sighalfperiod = 10
sigphase = 0

End Sub


Private Sub Form_Unload(Cancel As Integer)
If controllor.state = False Then
    Cancel = 0
Else
    Me.Visible = False
    Cancel = 1
End If
End Sub

Private Sub frequency_Change()
If CInt(frequency.Text) > 0 Then
 sigfrequency = 6.28 * CInt(frequency.Text)
 sighalfperiod = 500 / sigfrequency
End If

End Sub

Private Sub Option1_Click()
signaltype = 0
wave(0).Visible = True
wave(1).Visible = False
wave(2).Visible = False
End Sub

Private Sub Option2_Click()
signaltype = 1
wave(0).Visible = False
wave(1).Visible = True
wave(2).Visible = False
End Sub

Private Sub Option3_Click()
signaltype = 2
wave(0).Visible = False
wave(1).Visible = False
wave(2).Visible = True
End Sub

Private Sub Timer1_Timer()
realtime = Fix((Timer - starttime) * 1000)
i = (realtime - pretime) ' / 10)
For j = 1 To i
    Call sig(j + pretime)
Next j
pretime = realtime
Call Viewer.drawdata
End Sub

Sub sig(time As Integer)
Dim temp(1) As Byte
Dim tempi As Integer
Select Case signaltype
       Case 0
            tempi = sigam * Sin(sigfrequency * 0.001 * time + sigphase) + 2048
       Case 1
            temptime = time Mod 2 * sighalfperiod
            
            If temptime <= sighalfperiod Then
             tempi = temptime * 2 * sigam / sighalfperiod - sigam + 2048
            Else
             tempi = (2 * sighalfperiod - temptime) * 2 * sigam / sighalfperiod - sigam + 2048
            End If
        Case 2
            temptime = time Mod 2 * sighalfperiod
            
            If temptime <= sighalfperiod Then
             tempi = sigam + 2048
            Else
             tempi = 2048 - sigam
            End If
End Select

temp(0) = Fix(tempi / 256)
temp(1) = tempi Mod 256
sericomm.MSComm1.Output = temp
temp(0) = sericomm.MSComm1.OutBufferCount
datapointer_out = datapointer_out + 1
outdata(datapointer_out, 1) = time
outdata(datapointer_out, 2) = tempi

End Sub


⌨️ 快捷键说明

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