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

📄 form1.frm

📁 VB和西门子s300plc串口通讯程序 能实现读写功能
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3090
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3090
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text1 
      Height          =   495
      Left            =   2280
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   1080
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   495
      Left            =   1200
      TabIndex        =   0
      Top             =   480
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'通过点击“请点击”键可以读到PLC的DB块的实数数据,显示在窗体的文本框中
'注意:在PLC中,定义了DB10,DB10中定义了至少1个real型元素,PLC的站地址是2,槽号是2,机架号是0;本机PC的地址是0
'应用在s7-300/400的PLC中

Private Sub Command1_Click()
Dim dbno As Long, dwno As Long, amount As Long
Dim buffer(50) As Long
Dim var_read As Single

plcadr(0).adr = 2
plcadr(0).SEGMENTID = 0
plcadr(0).SLOTNO = 2
plcadr(0).RACKNO = 0
'
'plcadr(1).adr = 0
'plcadr(1).SEGMENTID = 0
'plcadr(1).SLOTNO = 2
'plcadr(1).RACKNO = 0

dbno = 10
dwno = 0
amount = 2

res = load_tool(1, "S7ONLINE", plcadr(0))

res = db_read(dbno, dwno, amount, buffer(0))

Call gp_to_float(buffer(0), var_read)

Text1.Text = CStr(var_read)

res = unload_tool()

End Sub

⌨️ 快捷键说明

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