注册 登录
编程论坛 VB6论坛

网上找的代码粘贴到VB6里面出错 请版主看一下哪儿出错

事业男儿 发布于 6 天前 15:56, 268 次点击

VERSION 5.00
Begin VB.Form frmMain
   Caption         =   "宇电519仪表通讯"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin cmdRead
      Caption         =   "读取数据"
      Height          =   495
      Left            =   1680
      TabIndex        =   2
      Top             =   2160
      Width           =   1215
   End
   Begin VB.TextBox txtSetpoint
      Height          =   375
      Left            =   1680
      Locked          =   -1  'True
      TabIndex        =   1
      Top             =   1200
      Width           =   1215
   End
   Begin VB.TextBox txtDisplay
      Height          =   375
      Left            =   1680
      Locked          =   -1  'True
      TabIndex        =   0
      Top             =   600
      Width           =   1215
   End
   Begin VB.Label Label2
      Caption         =   "设定值:"
      Height          =   255
      Left            =   840
      TabIndex        =   4
      Top             =   1320
      Width           =   735
   End
   Begin VB.Label Label1
      Caption         =   "显示值:"
      Height          =   255
      Left            =   840
      TabIndex        =   3
      Top             =   720
      Width           =   735
   End
   Begin MSCommLib.MSComm MSComm1
      Left            =   3600
      Top             =   240
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      CommPort        =   1
      DTREnable       =   -1  'True
      RThreshold      =   1
      RTSEnable       =   -1  'True
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub cmdRead_Click()
    ' 初始化串口
    With MSComm1
        .Settings = "9600,n,8,1"  ' 宇电519默认通讯参数
        .PortOpen = True
    End With
   
    ' 读取显示值
    txtDisplay.Text = Format(ReadDisplayValue(MSComm1), "0.00")
   
    ' 读取设定值
    txtSetpoint.Text = Format(ReadSetpoint(MSComm1), "0.00")
   
    ' 关闭串口
    MSComm1.PortOpen = False
End Sub
3 回复
#2
事业男儿前天 10:19
真心求助
#3
Dirtyppp2前天 18:18
缺少关键函数实现:代码调用了 ReadDisplayValue 和 ReadSetpoint 函数,但未提供实现
串口操作不完整:缺少数据发送/接收逻辑和协议解析
未处理校验和:宇电仪表通讯需要校验和计算
缺少错误处理:串口操作可能失败但没有错误处理
字节顺序问题:宇电协议使用特殊的浮点数传输格式
#4
cwa99585 小时前
缺少读取串口数据的函数(ReadDisplayValue( )和 ReadSetpoint()

1