|
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
aujolin
註冊時間: 2006-04-11 文章: 4
第 1 樓
|
發表於: 星期一 四月 23, 2007 4:08 pm 文章主題: VFP 呼叫 DLL 元件 Byte 格式的問題 |
|
|
目前使用 VFP 在控制一塊 I/O 卡,
有使用到該 I/O 卡的 DLL,
以下為 VB 的範例說明
Write Data to USBIO
函式原型BOOL WriteIOData(DWORD,LPBYTE,DWORD,LPDWORD)
參數1 : DWORD dwDevice 裝置編號
參數2 : LPBYTE pSrc Data Pointer 8051有2個Port
byte[0]=Port1,byte[1]=Port2
參數3 : DWORD dwSize dwSize=2 , 2個Port
參數4 : DWORD dwRet 傳回寫入的大小
其中必須寫兩個byte至USBIO,因有兩個PORT,Port1 Port2
不能只寫一個byte給USBIO,否則會發生USBIO等待第二個
Byte的情形
宣告
Private Declare Function WriteIOData Lib _ "DevLink.dll" ( _ ByVal hInst As
Integer, _ ByRef pSrc As Byte, _ ByVal dwSize As Integer, _ ByRef dwRet As
Integer _
) As Byte
執行
Private Sub Command2_Click()
tmp(0) = "&h" & Text3.Text
tmp(1) = 100
A = WriteIOData(0, tmp(0), 2, ret1)
Text5.Text = A
Text6.Text = ret1
End Sub
問題來了,
Byte 的格式在 VFP 中要如何宣告呢?
有試過用 Integer 的方式宣告,呼叫正常,但是資料寫入失敗 (I/O卡無反應),
有試過用 Varbinary 的方式宣告,呼叫時便發生錯誤。
還請各位先進能幫忙。
PS:目前是使用 VFP9 |
|
回頂端 |
|
|
garfield Site Admin
註冊時間: 2003-01-30 文章: 2157
第 2 樓
|
發表於: 星期二 四月 24, 2007 10:59 am 文章主題: |
|
|
用"益眾"的卡 ^^.
Declare INTEGER OpenLinkDevice IN DevLink.dll Integer hInst, Integer @ pHandle
Declare INTEGER WriteIOData IN DevLink.dll integer hDevice, string @ pSrc, Integer dwSize,integer @ dwRet
Declare INTEGER ReadIOData IN DevLink.dll integer hDevice,string @ pSrc,integer dwSize,integer @ dwRet
mopen=0
Thisform.hardhandle= OpenLinkDevice(0, @mopen)
mstr = CHR(thisform.portvalue1.Value)+CHR(thisform.portvalue2.Value)
mdwret = 0
mret = WriteIOData(Thisform.hardhandle, @mstr, LEN(mstr), @mdwret) _________________ 利用>>搜尋<<的功能會比問的還要快得到答案. |
|
回頂端 |
|
|
aujolin
註冊時間: 2006-04-11 文章: 4
第 3 樓
|
發表於: 星期二 四月 24, 2007 3:47 pm 文章主題: |
|
|
garfield 寫到: | 用"益眾"的卡 ^^.
Declare INTEGER OpenLinkDevice IN DevLink.dll Integer hInst, Integer @ pHandle
Declare INTEGER WriteIOData IN DevLink.dll integer hDevice, string @ pSrc, Integer dwSize,integer @ dwRet
Declare INTEGER ReadIOData IN DevLink.dll integer hDevice,string @ pSrc,integer dwSize,integer @ dwRet
mopen=0
Thisform.hardhandle= OpenLinkDevice(0, @mopen)
mstr = CHR(thisform.portvalue1.Value)+CHR(thisform.portvalue2.Value)
mdwret = 0
mret = WriteIOData(Thisform.hardhandle, @mstr, LEN(mstr), @mdwret) |
手頭上的 I/O 卡 剛好是[益眾]的
使用您所寫的 DLL 檔函數宣告方式,
測試結果已可以用,謝謝您的回覆,
又多學到了一招。
也有打去原廠做技術詢問,
不過他們也只能提供一些基本的資料,
那些資料都是 I/O 卡安裝光碟上面有的資料。
本來已經不抱希望了,
打算用 VB 再編譯一個 DLL 檔讓 VFP 來呼叫,
Byte 和 Integer 的部份就交給 VB 來處理,
還好,現在總算解決了。 |
|
回頂端 |
|
|
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|