登录
首页 PLC论坛 台达PLC
回帖 发帖
正文

主题:Select Case Command1.Caption 参数不可选

点击:350 回复:0

测试【台达PLC源码FORM VB6.0】提供的部分程序:
Function Chr_lrc(str As String) As String
C = 0
l = Len(str)
For C = C + 1 To l
c_data = Mid$(str, C, 2)
d_lrc = d_lrc + Val("&H" + c_data)
C = C + 1
Next C
If d_lrc > &HFF Then
d_lrc = d_lrc Mod &H100
End If
h_lrc = Hex(&HFF - d_lrc + 1)
If Len(h_lrc) > 2 Then
h_lrc = Mid(h_lrc, Len(h_lrc) - 1, 2)
End If
Chr_lrc = h_lrc
End Function
Private Sub Command1_Click()   'PLC运行停止按钮
If MSComm1.PortOpen = False Then   '如果串口未打开
MSComm1.PortOpen = True   '则打开串口
End If
Select Case Command1.Caption     '选择事件
Case "PLC RUN"
str = "010509AEFF00"   '通讯字符串
LRC = Chr_lrc(str)     '计算lrc校验值
stx = ":"    '起始字符冒号
str_out = stx + str + LRC + Chr$(13) + Chr$(10)   '发送字符串内容
MSComm1.Output = str_out     '通过串口发送
Command1.Caption = "PLC STOP"   '按钮显示PLC STOP 等待下次按压此按钮
Command1.BackColor = &HFF&   '按钮背景颜色为红色
Case "PLC STOP"     '事件PLC STOP
str = "010509AE0000"     '通讯字符串
LRC = Chr_lrc(str)      '计算lrc校验值
stx = ":"    '起始字符冒号
str_out = stx + str + LRC + Chr$(13) + Chr$(10)   '发送的字符串
MSComm1.Output = str_out    '通过串口发送
Command1.Caption = "PLC RUN"   '按钮显示PLC RUN 等待下次按压此按钮
Command1.BackColor = &HFF00&   '按钮背景颜色为绿色
End Select
End Sub
调试时提示 str = 参数不可选,
最后修改:2016/9/6 6:25:20
16-09-06 06:21

工控新闻

更多新闻资讯