| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 516 人关注过本帖
标题:有关于CWSeria串口类的问题l
只看楼主 加入收藏
jewen_he
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-9-9
收藏
 问题点数:0 回复次数:1 
有关于CWSeria串口类的问题l
各位高手帮忙看下这个程序,被闷了好久了,帮忙看看
Public Function IMSSendCommand(ByRef SendString As String, Query As Integer) As String 'MDI马达发送命令  所有运行的程序
Dim RecvString As String
Dim CompString As String
On Error GoTo Done
RecvString = ""
frmFC.CWSerial1.Write SendString & Chr(10)     '通过USB 收到什么样子的数据   是通过串口CWSerial1传递字符数据   发送数据

GetMore:

RecvString = RecvString & frmFC.CWSerial1.Read(1000)   '是写入程序   收到数据字符  一直在这里等待是否我数据字符等待
If InStr(RecvString, ">") < 1 Then GoTo GetMore   '判断有多少个字符输入进去,少于一个时候则重新判断  '>代表在IMS始端检测,InStr比较是否有相同的字母

Done:

If Len(RecvString) > 0 Then '判断是否收到指令
    'MsgBox RecvString
Else
    If InStr(SendString, "YP=") < 1 Then MsgBox "No data available" & vbCrLf & SendString 'Ignore first command - error for some reason
    MsgBox "No data available" & vbCrLf & SendString
    'TimedDelay2 1#
    Exit Function   '跳出窗口过程
End If
If InStr(RecvString, ">") < 1 Then
    MsgBox ("Command Prompt Failed!!!" & vbCrLf & "Command=" & SendString & vbCrLf & "Response=" & RecvString)
    GoTo BadResponse
End If
CompString = SendString
i = InStr(RecvString, CompString) '返回 Variant (Long),指定一字符串在另一字符串中最先出现的位置  判断发送的命令和接收到的命令是否相同
If i < 1 Then
    MsgBox ("Command Echo Failed!!!" & vbCrLf & "Command=" & SendString & vbCrLf & "Response=" & RecvString)
    GoTo BadResponse
End If
If Query = 0 Then Exit Function   '等于0时候就退出
s1 = Right(RecvString, Len(RecvString) - Len(SendString) - 2)
i = InStr(s1, Chr(13))
If i < 1 Then
    MsgBox ("Command Terminate Failed!!!" & vbCrLf & "Command=" & SendString & vbCrLf & "Response=" & RecvString)
    GoTo BadResponse
End If
s4 = Left(s1, i - 1) '。字符串表达式其中最左边的那些字符将被返回  i-1是字符个数   s1是字符串

s3 = ""
For i = 1 To Len(RecvString)
    s1 = Right(RecvString, Len(RecvString) - i + 1)
    s2 = Left(s1, 1)
    s3 = s3 & i & "  " & s2 & "  " & Asc(s2) & vbCrLf
Next i
'MsgBox s3
IMSSendCommand = s4
Exit Function

BadResponse:
s3 = ""
For i = 1 To Len(RecvString)
    s1 = Right(RecvString, Len(RecvString) - i + 1)
    s2 = Left(s1, 1)
    s3 = s3 & i & "  " & s2 & "  " & Asc(s2) & vbCrLf
Next i
MsgBox s3
Open "c:\FC\Temp\IMSErrorMessages.dat" For Append As #2   
Print #2, Date, Time, RecvString
Close #2

End Function


以下这这个是怎么样调用
上面的程序的
Public Function IMSCheckStageMotion(ByVal Axis As Integer) As Integer     'Motion移动
Dim Command As String
Dim IStart As Integer
Dim IStop As Integer
If Axis = 0 Then
    IStart = 1
    IStop = IMSNAxis
Else
    IStart = Axis
    IStop = Axis
End If
IMSCheckStageMotion = 0
For i = IStart To IStop
    If IMSParam(i).Enabled = 1 Then
        Command = IMSParam(i).AxisLabel & "PR MV" '??    VM=360000 PR VM  The MDrivePlus Motion Control will return a value of 360000
        Status = IMSSendCommand(Command, 1) '1. Click in the Terminal Window, and type (followed by ENTER):
        If Status = 1 Then IMSCheckStageMotion = 1' 2. The MDrivePlus Motion Control will return a value of 768000
    End If
Next i
End Function
搜索更多相关主题的帖子: 马达 
2011-09-09 16:29
jewen_he
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-9-9
收藏
得分:0 
自己先顶起,各位高手冒个泡,真是闷了很久了。先谢谢啦
2011-09-09 16:56
快速回复:有关于CWSeria串口类的问题l
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036146 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved