<< 点击显示目录 >> 主页 PVI通信 > PVI帮助信息 > PVI base system > PVICOM interface > PVICOM functions > PviLinkRequest, PviXLinkRequest functions |
int PviLinkRequest (LPCSTR pObjectName, LPVOID hEventMsg, DWORD EventMsgNo, LPARAM EventParam, LPCSTR pLinkDescriptor, LPVOID hResMsg, DWORD ResMsgNo, LPARAM ResParam)
int PviXLinkRequest (DWORD hPvi, LPCSTR pObjectName, LPVOID hEventMsg, DWORD EventMsgNo, LPARAM EventParam, LPCSTR pLinkDescriptor, LPVOID hResMsg, DWORD ResMsgNo, LPARAM ResParam)
PviLinkRequest (ByVal pObjectName As String, ByVal hEventMsg As Long, ByVal EventMsgNo As Long, ByVal EventParam As Long, ByVal pLinkDescriptor As String, ByVal hResMsg As Long, ByVal ResMsgNo As Long, ByVal ResParam As Long) As Long
PviXLinkRequest (ByVal hPvi As Long, ByVal pObjectName As String, ByVal hEventMsg As Long, ByVal EventMsgNo As Long, ByVal EventParam As Long, ByVal pLinkDescriptor As String, ByVal hResMsg As Long, ByVal ResMsgNo As Long, ByVal ResParam As Long) As Long
Argument |
I/O |
Description |
hPvi |
In |
来自 PviXInitialize 函数的实例句柄 |
pObjectName |
In |
|
hEventMsg |
In |
|
EventMsgNo |
In |
用户信息的信息编号 = 0(空)。在这种情况下,可以为hEventMsg指定除0以外的任何值(例如PVI_HMSG_NIL)。 |
EventParam |
In |
用户信息的消息参数 在32位PVI版本(PviCom.dll)中,消息参数(用户参数)的大小为4字节,在64位PVI版本(PviCom64.dll)中为8字节。 |
pLinkDescriptor |
In |
指向 链接对象描述的指针。以空结尾的字符串形式给出。 |
hResMsg |
In |
= 0(空)。PVI管理器不发送响应 |
ResMsgNo |
In |
用户信息的信息编号 = 0 (Null):与hResMsg=0含义相同。 |
ResParam |
In |
用户信息的消息参数 在32位PVI版本(PviCom.dll)中,消息参数(用户参数)的大小为4字节,在64位PVI版本(PviCom64.dll)中为8字节。 |
如果数值不是0,则表明有错误。错误代码被作为一个值返回。原则上,这个函数只报告Windows资源错误(如没有足够的可用内存)或用户错误(如非法的函数参数,不正确的函数使用,等等)。在这种情况下,不会向PVI管理器发送请求,也不会执行定义的响应信息。如果在数据传输过程中或在处理请求时发生错误,那么它将只与响应数据一起报告。
这个函数向PVI管理器发送一个请求,以建立一个链接对象。响应数据必须用 PviLinkResponse 或PviXLinkResponse函数 读取 ,除非使用 PVICALLBACK_DATA 类型的回调函数 。
用pLinkDescriptor定义的对象参数在设置链接对象时被使用。应用程序会收到一个带有响应数据的链接ID,用于识别设置的链接对象。
Example for Visual C++
#include <PviCom.h>
class CPviDlg : public CDialog
{
...
int m_LinkRequestCnt;
DWORD m_LinkID[256];
long m_ErrCode[256];
void LinkPviObjects ();
LRESULT OnPviLinkResp (WPARAM, LPARAM);
LRESULT OnPviObjEvent (WPARAM, LPARAM);
...
DECLARE_MESSAGE_MAP ()
};
BEGIN_MESSAGE_MAP (CPviDlg, CDialog)
...
ON_MESSAGE (WM_USER+3, OnPviObjEvent)
ON_MESSAGE (WM_USER+4, OnPviLinkResp)
END_MESSAGE_MAP()
LRESULT CPviDlg::OnPviObjEvent (WPARAM wParam, LPARAM lParam)
{
...
return (0);
}
LRESULT CPviDlg::OnPviCreateResp (WPARAM wParam, LPARAM lParam)
{
int ErrCode;
DWORD LinkID;
ErrCode = PviCreateResponse (wParam, &LinkID);
if (ErrCode != 0)
m_ErrCode[lParam] = ErrCode;
else
m_LinkID[lParam] = LinkID;
if (--m_CreateRequestCnt <= 0)
{
// last create response was received:
...
}
return (0);
}
void CPviDlg::LinkPviObjects()
{
int ErrCode;
// Initialize members:
m_LinkRequestCnt = 0;
memset (m_LinkID, 0, sizeof (m_LinkID));
memset (m_ErrCode, 0, sizeof (m_ErrCode));
// Link to variable object PVar1 (process value):
ErrCode = PviLinkRequest ("@Pvi/LNINA2/COM2/CPU/PVar1",
CWnd::m_hWnd, WM_USER+3, 0, "VT=i32 LT=prc",
CWnd::m_hWnd, WM_USER+4, 0);
if (ErrCode != 0)
m_ErrCode[0] = ErrCode;
else
m_LinkRequestCnt++;
// First link to variable object PVar2 (raw value):
ErrCode = PviLinkRequest ("@Pvi/LNINA2/COM2/CPU/PVar2",
CWnd::m_hWnd, WM_USER+3, 1, "VT=i32 LT=raw",
CWnd::m_hWnd, WM_USER+4, 1);
if (ErrCode != 0)
m_ErrCode[1] = ErrCode;
else
m_LinkRequestCnt++;
// Second link to variable object PVar2 (process value):
ErrCode = PviLinkRequest ("@Pvi/LNINA2/COM2/CPU/PVar2",
CWnd::m_hWnd, WM_USER+3, 101, "VT=i32 LT=prc",
CWnd::m_hWnd, WM_USER+4, 101);
if (ErrCode != 0)
m_ErrCode[101] = ErrCode;
else
m_LinkRequestCnt++;
...
}