函数的原型是:
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文件。
请指点。
1. LabVIEW 是不支持 pointer to pointer 的。
2. CAN.h 中的定义是:TUOKONGCAN_API bool CANPortOpen(DWORD MemPhy);
是 DWORD, 不是 PBYTE。
To:George Zou。
非常感谢你,并阅读了.h文件和dll。
.h中确实是dword类型,不过对方给的硬件原型说明是pbyte,请看下面。
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
}
你好!
我尝试用 数值型,unsigned 32 ,传递用 数值或者指针都失败了。
传递的这个地址是DA00,DB00,DC00等。
我尝试转化为char* ,即用csting来,也失败了。
尝试用 byte array, array pointer 也失败了。
dll调用时,函数名称是乱码。
这个dll的所有函数名称都存在这个问题。
会不会是,.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; }