VB中如何调用PI_Mercury_GCS_DLL.dll这个DLL文件,并进行RS232连接。
下面是RS232连接部分的代码:
#ifndef _GENERIC_I_NO_GUI
int MERCURY_FUNC_DECL Mercury_InterfaceSetupDlg(const char* szRegKeyName);
#endif
int MERCURY_FUNC_DECL Mercury_ConnectRS232(int port, int baudrate);
BOOL MERCURY_FUNC_DECL Mercury_IsConnected(int ID);
void MERCURY_FUNC_DECL Mercury_CloseConnection(int ID);
int MERCURY_FUNC_DECL Mercury_GetError(int ID);
BOOL MERCURY_FUNC_DECL Mercury_SetErrorCheck(int ID, BOOL bErrorCheck);
BOOL MERCURY_FUNC_DECL Mercury_TranslateError(int errNr, char* szBuffer, int maxlen);

解决方案 »

  1.   

    Option Explicit
    #If Not GENERIC_I_NO_GUI Then
        'int MERCURY_FUNC_DECL Mercury_InterfaceSetupDlg(const char* szRegKeyName);
        Private Declare Function Mercury_InterfaceSetupDlg Lib "PI_Mercury_GCS_DLL.dll" (ByVal szRegKeyName As String) As Long
    #End If
    'int MERCURY_FUNC_DECL Mercury_ConnectRS232(int port, int baudrate);
    Private Declare Function Mercury_ConnectRS232 Lib "PI_Mercury_GCS_DLL.dll" (ByVal port As Long, ByVal baudrate As Long) As Long
    'BOOL MERCURY_FUNC_DECL Mercury_IsConnected(int ID);
    Private Declare Function Mercury_IsConnected Lib "PI_Mercury_GCS_DLL.dll" (ByVal ID As Long) As Long
    'void MERCURY_FUNC_DECL Mercury_CloseConnection(int ID);
    Private Declare Sub Mercury_CloseConnection Lib "PI_Mercury_GCS_DLL.dll" (ByVal ID As Long)
    'int MERCURY_FUNC_DECL Mercury_GetError(int ID);
    Private Declare Function Mercury_GetError Lib "PI_Mercury_GCS_DLL.dll" (ByVal ID As Long) As Long
    'BOOL MERCURY_FUNC_DECL Mercury_SetErrorCheck(int ID, BOOL bErrorCheck);
    Private Declare Function Mercury_SetErrorCheck Lib "PI_Mercury_GCS_DLL.dll" (ByVal ID As Long, ByVal bErrorCheck As Long) As Long
    'BOOL MERCURY_FUNC_DECL Mercury_TranslateError(int errNr, char* szBuffer, int maxlen);
    Private Declare Function Mercury_TranslateError Lib "PI_Mercury_GCS_DLL.dll" (ByVal errNr As Long, ByVal szBuffer As String, ByVal maxlen As Long) As Long
      

  2.   

    好的 谢谢supergreenbean 我加进去看看
      

  3.   

    再问下,我现在有个局部变量定义如下:
    Private Declare Function Mercury_MVR Lib "PI_Mercury_GCS_DLL.dll" (ByVal ID As Long, ByVal szAxes As String, ByVal pdValarray As Double) As Long我执行控件操作,我试了下,按照这样不行:
    Private Sub Command9_Click()
       Dim ID As Long
       ID = Mercury_ConnectRS232(2, 9600)
       MSComm1.Output = Mercury_MVR(ID, "A", -146) & Chr(13)
       '或者干脆Mercury_MVR(ID, "A", -146) & Chr(13)
    End Sub
    应该怎么改呢。
      

  4.   

    上面的重新改下,是这样的:
    Private Declare Function Mercury_MVR Lib "PI_Mercury_GCS_DLL.dll" (ByVal ID As Long, ByVal szAxes As String, ByVal pdValarray As Double) As Long 
    Private Sub Command9_Click()
       Call Sleep(100)
       Mercury_MVR.A = 146   'A即szAxes ,146即pdValarray
       Dim currentPos As Double
       currentPos = Mercury_MVR.A
    End Sub
    这样也不行!为什么?