NI LabVIEW,CVI,数据采集等产品讨论区

取消
显示结果 
搜索替代 
您的意思是: 

LabVIEW dll函数调用中PBYTE如何设置对应参数

函数的原型是:

bool CANPortOpen(PBYTE pMemPhy):

参数说明:

Parameter: PBYTE pMemPhy Æ it a pointer to point physical memory. The

value of pMemPhy may be 0xda000 or 0xdb000 or 0xdc000 or 0xcc000. 

 

在 LabVIEW调用dll中,如何设置PBYTE  对应的数据类型? 百度后 PBYTE 类似 char*

参数的输入是3个字节,是否用byte array来对应Pbyte呢?

 

附件是 dll和.h文件。

请指点。

0 项奖励
1 条消息(共 12 条)
7,336 次查看

1. LabVIEW 是不支持 pointer to pointer 的。

2. CAN.h 中的定义是:TUOKONGCAN_API bool CANPortOpen(DWORD MemPhy);

    是 DWORD, 不是 PBYTE。

 

 

 

George Zou
2 条消息(共 12 条)
7,321 次查看

To:George Zou。

 

非常感谢你,并阅读了.h文件和dll。

 

.h中确实是dword类型,不过对方给的硬件原型说明是pbyte,请看下面。

 

 

 

bool CANPortOpen(PBYTE pMemPhy):

This function will map memory physical address to linear address, if mapping

success will return true, otherwise, will return false.   This function must be

called before any register setting or  message frame transmitting. And it

should be called only one time, except fail mapping.

In other word, if call this func tion and mapping success, you should not

call it again before a CANPortClose being called.

Parameter: PBYTE pMemPhy Æ it a pointer to point physical memory. The

value of pMemPhy may be 0xda000 or 0xdb000 or 0xdc000 or 0xcc000.

Ex: bool result;

result =CANPortOpen((PBYTE)0xda000);  

if(!result){

 //error handler

0 项奖励
3 条消息(共 12 条)
7,310 次查看

你好!

 

我尝试用 数值型,unsigned 32 ,传递用 数值或者指针都失败了。

 

传递的这个地址是DA00,DB00,DC00等。

 

我尝试转化为char* ,即用csting来,也失败了。

 

尝试用 byte array, array pointer 也失败了。

0 项奖励
4 条消息(共 12 条)
7,301 次查看

> 传递的这个地址是DA00,DB00,DC00等。

 

少了一个零?

建议用 U32,传递用 数值:0x000DB000,或 0xB000000D,或 0x00B00D00。

 

 

George Zou
0 项奖励
5 条消息(共 12 条)
7,298 次查看

dll调用时,函数名称是乱码。

 

这个dll的所有函数名称都存在这个问题。

0 项奖励
6 条消息(共 12 条)
7,290 次查看

会不会是,.net的函数〉

 

这里有 函数的操作,vc下or.net的。

看起来是int32 型。但是我尝试操作端口,总是没有返回值。

 

void CCanbusDlg::OnBnClickedButton1()
{
	// TODO: 北兜矪瞶盽Α祘Α絏
	INT_PTR ret;
	CconDialog myConDlg;
	unsigned int p0Code,p0Mask,p1Code,p1Mask;
	
	ret=myConDlg.DoModal();
	if(ret == -1)
	{
		AfxMessageBox(_T("Can't open Configuration Dialog"),MB_OK | MB_ICONSTOP);
	}

	if(ret==IDOK)
	{
		configData newConfig;
		newConfig.p0Add=myConDlg.m_ddx_strcb15;
		newConfig.p0IRQ=myConDlg.m_ddx_strcb13;
		newConfig.p0Baud=myConDlg.m_ddx_strcb11;
		newConfig.p0Mode=myConDlg.m_ddx_strcb16;
		newConfig.p0AcpCode=myConDlg.m_ddx_stred23;
		newConfig.p0AcpMask=myConDlg.m_ddx_stred24;
		newConfig.p1Add=myConDlg.m_ddx_stred21;
		newConfig.p1IRQ=myConDlg.m_ddx_strcb14;
		newConfig.p1Baud=myConDlg.m_ddx_strcb12;
		newConfig.p1Mode=myConDlg.m_ddx_strcb17;
		newConfig.p1AcpCode=myConDlg.m_ddx_stred25;
		newConfig.p1AcpMask=myConDlg.m_ddx_stred26;
		if(newConfig.p0Mode==CString("Basic")){
			if(!CheckIntString(newConfig.p0AcpCode,255,0,&p0Code)){
				AfxMessageBox(_T("Port 0 Acceptance Code is invalid!!"),MB_OK | MB_ICONSTOP);
				return;
			}
			if(!CheckIntString(newConfig.p0AcpMask,255,0,&p0Mask)){
				AfxMessageBox(_T("Port 0 Acceptance Mask is invalid!!"),MB_OK | MB_ICONSTOP);
				return;
			}
		}else{
			if(!CheckIntString(newConfig.p0AcpCode,0xffffffff,0,&p0Code)){
				AfxMessageBox(_T("Port 0 Acceptance Code is invalid!!"),MB_OK | MB_ICONSTOP);
				return;
			}
			if(!CheckIntString(newConfig.p0AcpMask,0xffffffff,0,&p0Mask)){
				AfxMessageBox(_T("Port 0 Acceptance Mask is invalid!!"),MB_OK | MB_ICONSTOP);
				return;
			}
		}
		if(newConfig.p1Mode==CString("Basic")){
			if(!CheckIntString(newConfig.p1AcpCode,255,0,&p1Code)){
				AfxMessageBox(_T("Port 1 Acceptance Code is invalid!!"),MB_OK | MB_ICONSTOP);
				return;
			}
			if(!CheckIntString(newConfig.p1AcpMask,255,0,&p1Mask)){
				AfxMessageBox(_T("Port 1 Acceptance Mask is invalid!!"),MB_OK | MB_ICONSTOP);
				return;
			}
		}else{
			if(!CheckIntString(newConfig.p1AcpCode,0xffffffff,0,&p1Code)){
				AfxMessageBox(_T("Port 1 Acceptance Code is invalid!!"),MB_OK | MB_ICONSTOP);
				return;
			}
			if(!CheckIntString(newConfig.p1AcpMask,0xffffffff,0,&p1Mask)){
				AfxMessageBox(_T("Port 1 Acceptance Mask is invalid!!"),MB_OK | MB_ICONSTOP);
				return;
			}
		}
		ShowPortMessage(newConfig);
		OnBnClickedButton5();
		if(IsConfiged){
			CANPortClose();
			IsConfiged=false;
		}
		int addr=0xda000;
		if(newConfig.p0Add==CString("DA00H"))
			addr=0xda000;
		else if(newConfig.p0Add==CString("DB00H"))
			addr=0xdb000;
		else if(newConfig.p0Add==CString("DC00H"))
			addr=0xdc000;
		else if(newConfig.p0Add==CString("CC00H"))
			addr=0xcc000;

		CANPortOpen(addr);
		IsConfiged=true;
		//TODO:HW_DETECT
		bool p0Stus,p1Stus;
		p0Stus=CANHWDetect(false);
		p1Stus=CANHWDetect(true);
		myPaint(p0Stus,p1Stus);

		m_combo1.SetCurSel(0);
		m_combo2.SetCurSel(0);
		m_edit1.SetWindowTextW(_T(""));
		if(!p0Stus)
			AfxMessageBox(_T("Can't connect to Port 0"),MB_OK | MB_ICONSTOP);
		if(!p1Stus)
			AfxMessageBox(_T("Can't connect to Port 1"),MB_OK | MB_ICONSTOP);
		//m_btn6.EnableWindow(0);
		if(p0Stus||p1Stus)
		{
			m_combo1.EnableWindow(1);
			m_combo2.EnableWindow(1);
			EnableTransmit(0);
						
		}else{
			m_combo1.EnableWindow(0);
			m_combo2.EnableWindow(0);
			EnableTransmit(0);
			CANPortClose();
			IsConfiged=false;
			return;
		}
		//port 0 configuration
		if(newConfig.p0Mode==CString("Basic")){
			CANSetMode(0,0);
			m_p0Mode=false;
		}else{
			CANSetMode(0,1);
			m_p0Mode=true;
		}
		if(newConfig.p0Baud==CString("100K"))
			CANSetBaud(0,4,0x1c);
		else if(newConfig.p0Baud==CString("125K"))
			CANSetBaud(0,3,0x1c);
		else if(newConfig.p0Baud==CString("250K"))
			CANSetBaud(0,1,0x1c);
		else if(newConfig.p0Baud==CString("500K"))
			CANSetBaud(0,0,0x1c);
		else if(newConfig.p0Baud==CString("1000K"))
			CANSetBaud(0,0,0x14);
		else{
			AfxMessageBox(_T("No vaild Baud Rate setting"),MB_OK | MB_ICONSTOP);
			return;
		}
		CANSetOutCtrl(0,0xda);
		CANSetAccpt(0,(DWORD)p0Code,(DWORD)p0Mask);
		//port 1 configuration
		if(newConfig.p1Mode==CString("Basic")){
			CANSetMode(1,0);
			m_p1Mode=false;
		}else{
			CANSetMode(1,1);
			m_p1Mode=true;
		}
		if(newConfig.p1Baud==CString("100K"))
			CANSetBaud(1,4,0x1c);
		else if(newConfig.p1Baud==CString("125K"))
			CANSetBaud(1,3,0x1c);
		else if(newConfig.p1Baud==CString("250K"))
			CANSetBaud(1,1,0x1c);
		else if(newConfig.p1Baud==CString("500K"))
			CANSetBaud(1,0,0x1c);
		else if(newConfig.p1Baud==CString("1000K"))
			CANSetBaud(1,0,0x14);
		else{
			AfxMessageBox(_T("No vaild Baud Rate setting"),MB_OK | MB_ICONSTOP);
			return;
		}
		CANSetOutCtrl(1,0xda);
		CANSetAccpt(1,(DWORD)p1Code,(DWORD)p1Mask);

	}

	return;

}

 

0 项奖励
7 条消息(共 12 条)
7,288 次查看

这多数是个C++的DLL。不能直接调用。

在ANSI C中试试看。

 

 

George Zou
0 项奖励
8 条消息(共 12 条)
7,285 次查看

 

非常感谢!!

 

在ANSI C中试试,请问是什么意思? 是调用dll 选择C 还是 需要编译dll 选择ANSI C?

 

是这个原因造成 dll 函数调用时 函数名都是乱码的吗?

0 项奖励
9 条消息(共 12 条)
7,279 次查看

> 编译dll 选择ANSI C

上选

 

〉是调用dll 选择C

次之

 

〉乱码

应该是C++

 

 

George Zou
0 项奖励
10 条消息(共 12 条)
7,276 次查看