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

📄 form1.frm

📁 周立功USBCANII设备
💻 FRM
📖 第 1 页 / 共 3 页
字号:
         End
         Begin VB.Label Label12 
            Caption         =   "滤波方式:"
            Height          =   255
            Left            =   240
            TabIndex        =   31
            Top             =   1080
            Width           =   975
         End
         Begin VB.Label Label11 
            Caption         =   "定时器1:0x"
            Height          =   255
            Left            =   4560
            TabIndex        =   29
            Top             =   1080
            Width           =   1095
         End
         Begin VB.Label Label8 
            Caption         =   "定时器0:0x"
            Height          =   255
            Left            =   4560
            TabIndex        =   27
            Top             =   720
            Width           =   1095
         End
         Begin VB.Label Label2 
            Caption         =   "屏蔽码:0x"
            Height          =   255
            Left            =   240
            TabIndex        =   25
            Top             =   720
            Width           =   975
         End
         Begin VB.Label Label1 
            Caption         =   "验收码:0x"
            Height          =   255
            Left            =   240
            TabIndex        =   23
            Top             =   360
            Width           =   975
         End
      End
      Begin VB.Label Label10 
         Caption         =   "第几路CAN:"
         Height          =   255
         Left            =   2520
         TabIndex        =   10
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label9 
         Caption         =   "设备索引号:"
         Height          =   255
         Left            =   240
         TabIndex        =   9
         Top             =   360
         Width           =   1095
      End
   End
   Begin VB.Frame Frame6 
      Caption         =   "信息"
      Height          =   2775
      Left            =   120
      TabIndex        =   18
      Top             =   4800
      Width           =   8655
      Begin VB.CommandButton Command4 
         Caption         =   "清除信息"
         Height          =   375
         Left            =   7320
         TabIndex        =   38
         Top             =   240
         Width           =   975
      End
      Begin VB.ListBox List1 
         BeginProperty Font 
            Name            =   "新宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   1860
         ItemData        =   "Form1.frx":01A4
         Left            =   120
         List            =   "Form1.frx":01A6
         TabIndex        =   19
         Top             =   720
         Width           =   8415
      End
      Begin VB.Line Line7 
         X1              =   3840
         X2              =   3840
         Y1              =   360
         Y2              =   600
      End
      Begin VB.Line Line6 
         X1              =   2880
         X2              =   2880
         Y1              =   360
         Y2              =   600
      End
      Begin VB.Label Label21 
         Caption         =   "帧格式"
         Height          =   255
         Left            =   3120
         TabIndex        =   45
         Top             =   360
         Width           =   615
      End
      Begin VB.Line Line5 
         X1              =   5520
         X2              =   5520
         Y1              =   360
         Y2              =   600
      End
      Begin VB.Line Line4 
         X1              =   4680
         X2              =   4680
         Y1              =   360
         Y2              =   600
      End
      Begin VB.Line Line2 
         X1              =   1680
         X2              =   1680
         Y1              =   360
         Y2              =   600
      End
      Begin VB.Label Label20 
         Caption         =   "数据"
         Height          =   255
         Left            =   5760
         TabIndex        =   44
         Top             =   360
         Width           =   495
      End
      Begin VB.Label Label19 
         Caption         =   "帧长度"
         Height          =   255
         Left            =   4800
         TabIndex        =   43
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label18 
         Caption         =   "帧类型"
         Height          =   255
         Left            =   3960
         TabIndex        =   42
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label17 
         Caption         =   "帧ID"
         Height          =   255
         Left            =   2040
         TabIndex        =   41
         Top             =   360
         Width           =   495
      End
      Begin VB.Label Label16 
         Caption         =   "时间标识"
         Height          =   255
         Left            =   840
         TabIndex        =   40
         Top             =   360
         Width           =   855
      End
      Begin VB.Line Line1 
         X1              =   720
         X2              =   720
         Y1              =   360
         Y2              =   600
      End
      Begin VB.Label Label15 
         Caption         =   "收/发"
         Height          =   255
         Left            =   240
         TabIndex        =   39
         Top             =   360
         Width           =   615
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim m_devtype As Long
Dim m_connect As Byte
Dim m_devind As Long
Dim m_cannum As Long
Dim CAN_BTR0(0 To 9) As String
Dim CAN_BTR1(0 To 9) As String
Dim CAN_BTR_Set As Byte
Dim user_str As String
Dim user_str_length As Long
Dim frame_delay_flag As Byte
Dim frame_serial_num As Byte





Private Sub Check1_Click()
    CAN_BTR_Set = Check1.Value
    If CAN_BTR_Set = 1 Then
        Text5.Enabled = True
        Text6.Enabled = True
        Combo8.Enabled = False
    Else
        Text5.Enabled = False
        Text6.Enabled = False
        Combo8.Enabled = True
    End If
    
End Sub

Private Sub Check2_Click()
    frame_delay_flag = Check2.Value
    If frame_delay_flag = 1 Then
        Text9.Enabled = True
    Else
        Text9.Enabled = False
    End If
End Sub

Private Sub Combo8_Click()
    Text5.Text = CAN_BTR0(Combo8.ListIndex)
    Text6.Text = CAN_BTR1(Combo8.ListIndex)
End Sub



Private Sub Combo9_Click()
    Select Case Combo9.ListIndex
        Case 0
            Check2.Enabled = False
            Check3.Enabled = False
            Check4.Enabled = False
            Text1.Enabled = True
            Text7.Enabled = False
            Text8.Enabled = False
            Text9.Enabled = False
            Text10.Enabled = False
            Combo3.Enabled = True
            Combo4.Enabled = True
            Combo5.Enabled = True
        Case 1
            Check2.Enabled = True
            Check3.Enabled = True
            Check4.Enabled = True
            Text1.Enabled = False
            Text7.Enabled = True
            Text8.Enabled = True
            Text9.Enabled = True
            Text10.Enabled = True
            Combo3.ListIndex = 0
            Combo4.ListIndex = 1
            Combo5.ListIndex = 0
            Combo3.Enabled = False
            Combo4.Enabled = False
            Combo5.Enabled = False
            Combo8.ListIndex = 3
            user_str = Text11.Text + Text4.Text + Text10.Text
        Case 2
            Check2.Enabled = True
            Check3.Enabled = True
            Text1.Enabled = False
            Text7.Enabled = True
            Text8.Enabled = True
            Text9.Enabled = True
            Text10.Enabled = True
            Combo3.ListIndex = 0
            Combo4.ListIndex = 1
            Combo5.ListIndex = 0
            Combo3.Enabled = False
            Combo4.Enabled = False
            Combo5.Enabled = False
            Combo8.ListIndex = 7
    End Select
End Sub

Private Sub Command1_Click()
    If (Len(Text4.Text) Mod 2) = 1 Then
        MsgBox ("用户数据 位数须是偶数")
    Else
        CAN_Send
    End If
End Sub

Private Sub Command2_Click()
    If m_connect = 0 Then
        MsgBox ("请先打开端口")
        Exit Sub
    End If
    If VCI_StartCAN(m_devtype, m_devind, m_cannum) <> 1 Then
        MsgBox ("启动CAN错误")
    Else
        'List1.AddItem "启动CAN成功", List1.ListCount
        Command2.Caption = "已启动"
        Command3.Caption = "复位CAN"
    End If
End Sub

Private Sub Command3_Click()
    If m_connect = 0 Then
        MsgBox ("请先打开端口")
        Exit Sub
    End If
    If VCI_ResetCAN(m_devtype, m_devind, m_cannum) <> 1 Then
        MsgBox ("复位CAN错误")
   Else
        'List1.AddItem "复位CAN成功", List1.ListCount
        Command3.Caption = "已复位"
        Command2.Caption = "启动CAN"
    End If

End Sub

Private Sub Command4_Click()
    List1.Clear
End Sub

Private Sub Command5_Click(Index As Integer)
    If m_connect = 0 Then
        MsgBox ("请先打开端口")
        Exit Sub
    End If
    
    Dim i As Long
    i = Combo2.ListIndex
    If i <> -1 Then
        i = i + 1
        If VCI_SetReference(m_devtype, m_devind, 0, 3, i) <> 1 Then
            MsgBox ("更改232波特率错误")
        Else
            List1.AddItem "更改232波特率成功", List1.ListCount
        End If
    End If

End Sub

Private Sub Connect_Click()
    Dim Index As Long
    Dim cannum As Long
    Dim code, mask As Long
    Dim Timing0, Timing1, filtertype, Mode As Byte
    Dim InitConfig As VCI_INIT_CONFIG
    
    If m_connect = 1 Then
        m_connect = 0
        Connect.Caption = "连接"
        VCI_CloseDevice m_devtype, m_devind
        Command2.Caption = "启动CAN"
        Command3.Caption = "复位CAN"
        Exit Sub
    End If
        
    If Combo1.ListIndex <> -1 And Combo2.ListIndex <> -1 Then
        Index = Combo1.ListIndex
        cannum = Combo2.ListIndex
        filtertype = Combo6.ListIndex
        Mode = Combo7.ListIndex
        code = Val("&H" + Text2.Text)
        mask = Val("&H" + Text3.Text)
        Timing0 = Val("&H" + Text5.Text)
        Timing1 = Val("&H" + Text6.Text)
        InitConfig.AccCode = code
        InitConfig.AccMask = mask
        InitConfig.Filter = filtertype
        InitConfig.Mode = Mode
        InitConfig.Timing0 = Timing0
        InitConfig.Timing1 = Timing1
        
        If VCI_OpenDevice(m_devtype, Index, 0) <> 1 Then
            MsgBox ("打开设备错误")
        Else
            If VCI_InitCAN(m_devtype, Index, cannum, InitConfig) = 1 Then
                m_connect = 1
                m_devind = Index
                m_cannum = cannum
                Connect.Caption = "断开"
            Else
                MsgBox ("初始化CAN错误")
            End If
        End If
    End If
    
End Sub

Private Sub Form_Load()
    m_devtype = 4 'USBCAN2类型号
    m_connect = 0
    m_cannum = 0
    Combo1.ListIndex = 0
    Combo2.ListIndex = 0
    Combo3.ListIndex = 0
    Combo4.ListIndex = 1
    Combo5.ListIndex = 0
    Combo6.ListIndex = 0
    Combo7.ListIndex = 0

⌨️ 快捷键说明

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