VFP 愛用者社區 首頁 VFP 愛用者社區
本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
 
 常見問題常見問題   搜尋搜尋   會員列表會員列表   會員群組會員群組   會員註冊會員註冊 
 個人資料個人資料   登入檢查您的私人訊息登入檢查您的私人訊息   登入登入

透過 PLC 的 ActiveX 元件 讀取資料的問題

 
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區
上一篇主題 :: 下一篇主題  
發表人 內容
aujolin



註冊時間: 2006-04-11
文章: 4


第 1 樓

發表發表於: 星期二 五月 15, 2007 11:18 am    文章主題: 透過 PLC 的 ActiveX 元件 讀取資料的問題 引言回覆

目前使用 MITSUBISHI 的 PLC,要從 PLC 上面讀取、寫入資料
透過安裝 MX Component,使用其提供的 ActiveX 元件來對 PLC 作存取


以下是 VB 的範例


Private Type udt32BitInteger
l32BitInteger As Long
End Type

Private Type udtInteger
iarrInteger(19) As Integer
End Type


Dim lReturnCode As Long 'Return code
Dim buffer32BitInteger As udt32BitInteger 'User-defined type for '32bit Integer'
Dim bufferInteger As udtInteger 'User-defined type for reading to the PLC


udtIntegerudtInteger'Error Handler
On Error GoTo CatchError

'The WriteDeviceBlock2 method is executed.(from D10-D11)
lReturnCode = ActEasyIF1.ReadDeviceBlock2("D10", 2 , bufferInteger.iarrInteger(0))

'When ActEasyIF returns error code, display error message.
If lReturnCode <> 0 Then
DisplayErrorMessage (lReturnCode)
Exit Sub
End if

'Copy the 'bufferInteger' to the user-defined type for '32bit Integer' data.
LSet buffer32BitInteger = bufferInteger

'Set the 32bit integer data to the TextBox as string.
txt_Read32BitInteger.Text = CStr(buffer32BitInteger.l32BitInteger)

Exit Sub

CatchError: 'Exception processing

CatchErrorCatchErrorszErrMsg = Error$(Err)'
MsgBox szErrMsg, vbCritical
End

===============================================

問題來了
在 VB 中,利用
ActEasyIF1.ReadDeviceBlock2("D10", 2 , bufferInteger.iarrInteger(0))
可讀取到資料,並放到 bufferInteger.iarrInteger 中
但是在 VFP 中,
dimension laInteger(20)
for lnI = 1 to 20
laInteger(lnI) = 0
endif
Thisform.ActEasyIF1.ReadDeviceBlock2("D10", 2 , laInteger )
執行後
laInteger 中的值卻都還是 0,
有試過把 laInteger 換成一個變數 lnInteger , lnInteger=0
結果還是一樣,回傳值是 0
有試過把 laInteger 換成 @laInteger 結果會回傳 OLE 錯誤 型態不對應,


還請各位先進提供看法以及建議,謝謝各位的觀看以及回覆。
回頂端
檢視會員個人資料 發送私人訊息
aujolin



註冊時間: 2006-04-11
文章: 4


第 2 樓

發表發表於: 星期五 五月 25, 2007 3:23 pm    文章主題: Re: 透過 PLC 的 ActiveX 元件 讀取資料的問題 引言回覆

aujolin 寫到:
目前使用 MITSUBISHI 的 PLC,要從 PLC 上面讀取、寫入資料
透過安裝 MX Component,使用其提供的 ActiveX 元件來對 PLC 作存取

< 部分內容省略 >

===============================================

問題來了
在 VB 中,利用
ActEasyIF1.ReadDeviceBlock2("D10", 2 , bufferInteger.iarrInteger(0))
可讀取到資料,並放到 bufferInteger.iarrInteger 中
但是在 VFP 中,
dimension laInteger(20)
for lnI = 1 to 20
laInteger(lnI) = 0
endif
Thisform.ActEasyIF1.ReadDeviceBlock2("D10", 2 , laInteger )
執行後
laInteger 中的值卻都還是 0,
有試過把 laInteger 換成一個變數 lnInteger , lnInteger=0
結果還是一樣,回傳值是 0
有試過把 laInteger 換成 @laInteger 結果會回傳 OLE 錯誤 型態不對應,


還請各位先進提供看法以及建議,謝謝各位的觀看以及回覆。




最後測試結果
Thisform.ActEasyIF1.ReadDeviceBlock2("D10", 2 , @laInteger(1) )
指定將回傳值放到 laInteger(1) 中

VB 的程式是可以把多的暫存器位址做回傳,
上述的程式可以回傳 D10 和 D11,並放到 laInteger(0) 和 laInteger(1)
但是 VFP 的程式,只能夠回傳一個,資料會放到 laInteger(1) 中

以上為最後測試出來的結果,跟各位分享一下
回頂端
檢視會員個人資料 發送私人訊息
從之前的文章開始顯示:   
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區 所有的時間均為 台北時間 (GMT + 8 小時)
1頁(共1頁)

 
前往:  
無法 在這個版面發表文章
無法 在這個版面回覆文章
無法 在這個版面編輯文章
無法 在這個版面刪除文章
無法 在這個版面進行投票
無法 在這個版面附加檔案
無法 在這個版面下載檔案


Powered by phpBB © 2001, 2005 phpBB Group
正體中文語系由 phpbb-tw 維護製作