技術(shù)文章
VB環(huán)境下PMAC卡的初始化
閱讀:132 發(fā)布時(shí)間:2020-8-11設(shè)計(jì)開(kāi)發(fā)上位機(jī)軟件的目的是方便用戶(hù)管理、操作和觀(guān)察界面,實(shí)現(xiàn)對(duì)數(shù)控加工中心 機(jī)床的管理與安全操作[3()]。上位機(jī)系統(tǒng)軟件基于Windows操作系統(tǒng)平臺(tái),采用Microsoft Visual Basic 6.0開(kāi)發(fā)15。機(jī)床動(dòng)作命令必須通過(guò)調(diào)用動(dòng)態(tài)鏈接庫(kù)中的庫(kù)函數(shù)來(lái)實(shí)現(xiàn)對(duì)PMAC 卡的控制,此功能主要由PCOMM32.DLL完成,它是標(biāo)準(zhǔn)的Windows動(dòng)態(tài)鏈接庫(kù)[29]。 PCOMM32PRO在VB6.0中的加載步驟如下:
1.創(chuàng)建一個(gè)通用模塊。
2.聲明導(dǎo)入函數(shù):
Declare Function OpenPmacDevice Lib “Pcomm32.dll”(ByVal pmac As Long) As Long。
函數(shù)原型:
BOOL OpenPmacDevice(DWORD dwDevice) 〇
調(diào)用方式:
Dim Tmp_Val As Long
Tmp_Val=OpenPmacDevice (0)
通過(guò)如下代碼可以實(shí)現(xiàn)運(yùn)動(dòng)鏈接庫(kù)的定義:
Type PmacMsg
newline As Boolean Msg As String End Type
’PMAC.DLL Functions
Declare Function PmacSelect Lib nPcomm32.dlln (ByVal hwnd As Long) As Long
Declare Function OpenPmacDevice Lib nPcomm32.dir (ByVal pmac As Long) As Long
Declare Function PmacConfisure Lib nPcomm32.dlln (BvVal hwnd As Lons. BvVal pmac As Long) As Long
Declare Function PmacGetResponseA Lib nPcomm32.dlln (ByVal pmac As Long, ByVal responses, ByVal dummy As Integer, ByVal com_string$) As Long
Declare Function PmacFlush Lib "Pcomm32.dHn (ByVal pmac As Long) As Integer
Declare Function PmacGetPmacType Lib nPcomm32.dlln (ByVal pmac As Long) As Integer
Declare Function ClosePmacDevice Lib nPcomm32.dir (ByVal pmac As Long) As Long
Declare Function PmacDownloadA Lib nPcomm32.dlln (ByVal pmac As Long, ByVal dummy As Long, ByVal dummy As Long, ByVal dummy As Long, ByVal fname$, ByVal macro%, ByVal map%, ByVal log%, ByVal do_pmacDownloada%) As Integer
DeviceNumber = Pmac Select (hWnd)
OpenPmacDevice (DeviceNumber) ClosePmacDevice (DeviceNumber)
PmacGetResponseA (DeviceNumber, response, 255, n%100n)
為了使PMAC卡可以響應(yīng)上位機(jī)軟件的命令,還需要對(duì)PMAC卡進(jìn)行初始化,以確 定硬件地址、線(xiàn)程的開(kāi)啟和將站號(hào)、通訊方式等信息在通訊測(cè)試成功后寫(xiě)入window的注 冊(cè)表,完成PMAC在上位機(jī)上注冊(cè)的功能,以便我們換了通訊方式類(lèi)型的話(huà),下次開(kāi)啟 PEWIN32PRO時(shí)自動(dòng)的與卡進(jìn)行通訊[29]。初始化通常有以下兩種類(lèi)型:
1.通過(guò)PEWIN32PRO軟件來(lái)注冊(cè)。
2•使用PCOMM32PRO中的函數(shù)。
函數(shù)原型:Long Pmac Select (HWND hwnd)
在調(diào)用完成時(shí)會(huì)彈出一個(gè)初始化對(duì)話(huà)框如圖3-2所示。
初始化函數(shù)調(diào)用過(guò)程代碼如下:
OpenRuntimeLink() ;// 調(diào)用 OpenPmacDevice〇
dwDevice = PmacSelect(NULL);// 調(diào)用 PmacSelect〇
if (dwDevice >= 0 && dwDevice <= 7)
{if (OpenPmacDevice(dwDevice))
{ m_bDriverOpen = 1;
return true; // return TRUE unless you set the focus to a control
} }
Close〇; //關(guān)閉
PmacGetResponse(dwDevice,buf,255,n#lpn);
AfxMessageBox(buf);
由于PComm32PRO的設(shè)計(jì)理念是基于線(xiàn)程安全的,所以對(duì)數(shù)控加工中心機(jī)床的命令 在與PMAC卡通訊時(shí)要求進(jìn)行線(xiàn)程保護(hù)操作,例如一個(gè)應(yīng)用程序讀取I變量的操作進(jìn)行時(shí), 就不可以同時(shí)允許另外一個(gè)應(yīng)用程序也讀取相同的變量。PComm32PRO是通過(guò)LockPmac ()和ReleasePmac()兩個(gè)函數(shù)來(lái)實(shí)現(xiàn)線(xiàn)程的保護(hù)工作的。當(dāng)進(jìn)行某一操作時(shí)開(kāi)啟LockPmac ()以保護(hù)線(xiàn)程不被其它程序打擾,當(dāng)操作結(jié)束時(shí)調(diào)用RdeasePmac ()關(guān)閉保護(hù)。
本文采摘自“基于PMAC的加工中心開(kāi)放式數(shù)控系統(tǒng)研究”,因?yàn)榫庉嬂щy導(dǎo)致有些函數(shù)、表格、圖片、內(nèi)容無(wú)法顯示,有需要者可以在網(wǎng)絡(luò)中查找相關(guān)文章!
本文由伯特利數(shù)控整理發(fā)表文章均來(lái)自網(wǎng)絡(luò)僅供學(xué)習(xí)參考,轉(zhuǎn)載請(qǐng)注明!