您现在所在的是:

电脑编程

回帖:10个,阅读:3396 [上一页] [1] [2] [下一页]
* 帖子主题:

请教VB通讯?

1184
空心菜
文章数:116
年度积分:50
历史总积分:1184
注册时间:2004/10/9
发站内信
发表于:2006/3/11 19:29:00
#0楼
在串口通讯中,是不是可以用SEND发送指令,而不必用MSCOMM指令?有不有这方面的例子
2826
流客
文章数:794
年度积分:50
历史总积分:2826
注册时间:2005/8/28
发站内信
发表于:2006/3/11 21:09:00
#1楼
不是吧,不能这么发送吧.
40345
tigermu 版主
文章数:14903
年度积分:1303
历史总积分:40345
注册时间:2004/8/12
发站内信
2018论坛优秀版主
2018春节活动(二)
2017论坛优秀版主
2017国庆活动(一)
2016论坛优秀版主
2016国庆活动(一)
2015论坛优秀版主
西门子logo体验(三)
英威腾PLC体验(三)
2015春节活动
2014论坛优秀版主
2013论坛优秀版主
2012论坛优秀版主
2010年度论坛贡献奖
发表于:2006/3/11 21:16:00
#2楼
你用api还是串口组件?
清泉石上,明月松间。
1005
gray.dai
文章数:38
年度积分:50
历史总积分:1005
注册时间:2006/3/12
发站内信
发表于:2006/3/12 0:45:00
#3楼
mscomm是microsoft推出一个针对串口操作的一个组件,也就是一个类,使用的时候生成这个类的实例,然后使用类中的方法发送或者接受数据.
1184
空心菜
文章数:116
年度积分:50
历史总积分:1184
注册时间:2004/10/9
发站内信
发表于:2006/3/13 11:19:00
#4楼
下面的代码可能是用来串口通讯的,是一个模块,看了很久,不知道具体是什么意思,用了哪些函数,每个函数是什么意思。不好意思,是刚接触,希望大家不吝指教一二,在此不胜感激
Public m_devtype As Long
Public m_connect As Byte
Public m_devind As Long
Public m_cannum As Long
Public m_idx As String
Public m_passcode As String
Public UserName As String
Public strpass(6) As String
Public m_modeselc As String
Public m_NODEID As String
Public m_btnNODE As Boolean
Public m_Timing0 As String
Public m_Timing1 As String


Declare Function VCI_OpenDevice Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal Reserved As Long) As Long

Declare Function VCI_CloseDevice Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long) As Long

Declare Function VCI_InitCAN Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByRef InitConfig As VCI_INIT_CONFIG) As Long

Declare Function VCI_ReadBoardInfo Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByRef info As VCI_BOARD_INFO) As Long

Declare Function VCI_ReadErrInfo Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByRef ErrInfo As VCI_ERR_INFO) As Long

Declare Function VCI_ReadCANStatus Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByRef CANStatus As VCI_CAN_STATUS) As Long

Declare Function VCI_GetReference Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByVal RefType As Long, ByRef data As Any) As Long

Declare Function VCI_SetReference Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByVal RefType As Long, ByRef data As Any) As Long

Declare Function VCI_GetReceiveNum Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long) As Long
Declare Function VCI_ClearBuffer Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long) As Long

Declare Function VCI_StartCAN Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long) As Long

Declare Function VCI_ResetCAN Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long) As Long

Declare Function VCI_Transmit Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByRef Send As VCI_CAN_OBJ, ByVal length As Long) As Long

Declare Function VCI_Receive Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByRef Receive As VCI_CAN_OBJ, ByVal length As Long, ByVal WaitTime As Long) As Long



'定义需要用到的数据结构
Public Type VCI_BOARD_INFO
   hw_Version As Integer
   fw_Version As Integer
   dr_Version As Integer
   in_Version As Integer
   irq_num As Integer
   can_num As Byte
   str_Serial_Num(19) As Byte
   str_hw_Type(39) As Byte
   Reserved(3) As Integer
End Type

Public Type VCI_CAN_OBJ
   ID As Long
   TimeStamp As Long
   TimeFlag As Byte
   SendType As Byte
   RemoteFlag As Byte
   ExternFlag As Byte
   DataLen As Byte
   data(7) As Byte
   Reserved(2) As Byte
End Type

Public Type VCI_CAN_STATUS
   ErrInterrupt As Byte
   regMode As Byte
   regStatus As Byte
   regALCapture As Byte
   regECCapture As Byte
   regEWLimit As Byte
   regRECounter As Byte
   regTECounter As Byte
   Reserved As Long
End Type

Public Type VCI_ERR_INFO
   ErrCode As Long
   Passive_ErrData(2) As Byte
   ArLost_ErrData As Byte
End Type

Public Type VCI_INIT_CONFIG
   AccCode As Long
   AccMask As Long
   Reserved As Long
   Filter As Byte
   Timing0 As Byte
   Timing1 As Byte
   Mode As Byte
End Type


Public Function ConnectString() As String
  Dim strAppPath As String
  strAppPath = App.Path
  If Right(strAppPath, 1) <> "\" Then
      strAppPath = strAppPath & "\"
  End If
   
  strAppPath = strAppPath & "Data\object.mdb"
  ConnectString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & strAppPath & ";PWD=phase.com.cn" '& strAppPath &
End Function
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
  Dim cnn As ADODB.Connection
  Dim rst As ADODB.Recordset
  Dim sTokens() As String
 
  On Error GoTo ExecuteSQL_Error
 
  sTokens = Split(SQL)
  Set cnn = New ADODB.Connection
  cnn.Open ConnectString
  If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then
     cnn.Execute SQL
     MsgString = sTokens(0) & " query successful"
  Else
     Set rst = New ADODB.Recordset
     rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
     Set ExecuteSQL = rst
     MsgString = "查询到" & rst.RecordCount & " 条记录 "
  End If
ExecuteSQL_Exit:
  Set rst = Nothing
  Set cnn = Nothing
  Exit Function
ExecuteSQL_Error:
  MsgString = "查询错误: " & Err.Description
  Resume ExecuteSQL_Exit
End Function
1184
空心菜
文章数:116
年度积分:50
历史总积分:1184
注册时间:2004/10/9
发站内信
发表于:2006/3/13 16:42:00
#5楼
请问一下,frameinfo是不是VB的一个命令?
1184
空心菜
文章数:116
年度积分:50
历史总积分:1184
注册时间:2004/10/9
发站内信
发表于:2006/3/14 8:54:00
#6楼
用API函数是不是可以进行串口通讯,请问一下API函数的用法?
978
woxujun
文章数:22
年度积分:50
历史总积分:978
注册时间:2005/9/6
发站内信
发表于:2006/3/14 10:51:00
#7楼
这是一个安装在计算内的接口卡吧(我猜是CAN总线接口卡)? 人家提供了驱动程序给你了,参照它的例程做就好了!把动态库的接口函数研究研究吧!
1184
空心菜
文章数:116
年度积分:50
历史总积分:1184
注册时间:2004/10/9
发站内信
发表于:2006/3/14 13:25:00
#8楼
xiexie,没有接口卡,但用的是CANOPEN通讯,是用232接口转485通讯,同时控制3台伺服电机,是自已编了一个API函数,做为公用模块。NND,看了半天,没看到这个动态库“ControlCAN.dll”,因为编的人已走了,只留下源代码,也没人说过这个动态库的用法,要怎么去把这个动态库提出来,并反编出来。郁闷中
1184
空心菜
文章数:116
年度积分:50
历史总积分:1184
注册时间:2004/10/9
发站内信
发表于:2006/3/14 13:41:00
#9楼
另外,因我这个源代码是从其他电脑拷出来的,在程序中没有这个动态库文件,不知还能不能进行串口通讯了?

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

78.0005