h30631
級別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 90 個
工控威望: 230 點
下載積分: 812 分
在線時間: 339(小時)
注冊時間: 2012-09-05
最后登錄: 2018-04-17
查看h30631的 主題 / 回貼
樓主  發(fā)表于: 2012-12-26 07:54
請問MX Component  使用vb 來寫,要用哪個指令抓取32位d值?
怎麼是都抓16位而已,求助~
[ 此帖被h30631在2013-01-03 17:01重新編輯 ]
litung
臺灣-李同在
級別: VIP會員
精華主題: 2 篇
發(fā)帖數(shù)量: 578 個
工控威望: 3224 點
下載積分: 14494 分
在線時間: 405(小時)
注冊時間: 2009-06-06
最后登錄: 2024-09-19
查看litung的 主題 / 回貼
1樓  發(fā)表于: 2013-01-02 09:53
指令的話,使用 【ReadDeviceBlock2】
但要特別處理,才能讀到。
詳細(xì),請參考mx內(nèi)附的程式範(fàn)例。

祝好運
簡單的心,是真正有福
單純的心,是真正的快樂    
T480 i5-8250U,32GB,SSD:2TB+256G
litung
臺灣-李同在
級別: VIP會員
精華主題: 2 篇
發(fā)帖數(shù)量: 578 個
工控威望: 3224 點
下載積分: 14494 分
在線時間: 405(小時)
注冊時間: 2009-06-06
最后登錄: 2024-09-19
查看litung的 主題 / 回貼
2樓  發(fā)表于: 2013-01-02 14:50
好人作到底,給你完整的code
自己測試看看,有問題再討論

=====================================
Option Explicit
'/*****************************************************/
'/*撰寫者:李同在                                     */
'/*日期:2009/09/07 V1.0                              */
'/*用途:讀取三荾PLC的資料                            */
'/*****************************************************/
Dim bufferBit As udtBitInteger        '使用者自定型態(tài) for 32bit Integer
Dim bufferInteger As udtInteger
Public lRet As Long                   'PLC回傳值
Const MAX_SIZE_OF_ARRAY = 20          'Size of array for reading/writing 'Word' data to the PLC
'Data for reading/writing to the PLC
Private Type udtInteger
  iarrInteger(MAX_SIZE_OF_ARRAY - 1) As Integer
End Type
'資料位元
Private Type udtBitInteger
  l32Bit As Long
End Type

'/**************************************************************/
'/*功能:連續(xù)讀取32BIT PLC D值的資料                           */
'/*用法:Call Read32Bit("D0", "D2", "D4", "D6", "D8")          */
'/**************************************************************/
Public Function Read32Bit(ParamArray PLC_Data()) As String()
  Dim sRead32BitData() As String    '存放資料用
  Dim iCnt As Integer               '迴圈計算
 
  ReDim sRead32BitData(UBound(PLC_Data))
  For iCnt = LBound(PLC_Data) To UBound(PLC_Data)
    lRet = frmPLC.PLC.ReadDeviceBlock2(UCase(PLC_Data(iCnt)), CLng(2), bufferInteger.iarrInteger(0))
    LSet bufferBit = bufferInteger    '複製'bufferInteger'到 '32bit Integer'
    sRead32BitData(iCnt) = CStr(bufferBit.l32Bit)
  Next
  Read32Bit = sRead32BitData
End Function
簡單的心,是真正有福
單純的心,是真正的快樂    
T480 i5-8250U,32GB,SSD:2TB+256G
litung
臺灣-李同在
級別: VIP會員
精華主題: 2 篇
發(fā)帖數(shù)量: 578 個
工控威望: 3224 點
下載積分: 14494 分
在線時間: 405(小時)
注冊時間: 2009-06-06
最后登錄: 2024-09-19
查看litung的 主題 / 回貼
3樓  發(fā)表于: 2013-01-02 21:54
你不是臺灣來的嗎?怎麼不在臺灣那邊發(fā)問?

你的CALL有問題,CALL回來的東西要放那裡?誰(程式)會知道?
當(dāng)然就錯誤了。

一樣,直接給你現(xiàn)成的CODE,有問題再討論
VB語法不懂的,請自行找資料了解。
================================================
'讀取sv位置資料
Public Sub ReadSVData(iSVAxis As Integer)
  Dim arrData As Variant
  Dim iCnt As Integer

  Select Case iSVAxis
    Case 1:
      arrData = Read32Bit("D1000", "D1002", "D1004", "D1006", "D1008", "D1010", "D1012")
      For iCnt = LBound(arrData) To UBound(arrData)
        lblAxis1Poistion(iCnt).Caption = arrData(iCnt)
      Next iCnt
    Case 2:
      arrData = Read32Bit("D1018", "D1020", "D1024", "D1026", "D1028", "D1030", "D1032")
      For iCnt = LBound(arrData) To UBound(arrData)
        lblAxis2Poistion(iCnt).Caption = arrData(iCnt)
      Next iCnt
    Case 3:
      arrData = Read32Bit("D1034", "D1036", "D1038", "D1040", "D1042", "D1044", "D1046", "D1048", "D1050")
      For iCnt = LBound(arrData) To UBound(arrData)
        lblAxis3Poistion(iCnt).Caption = arrData(iCnt)
      Next iCnt
    Case 4:
      arrData = Read32Bit("D1054", "D1056", "D1058", "D1060", "D1062", "D1064", "D1066", "D1070", "D1072", "D1074", "D1076", "D1078", "D1080")
      For iCnt = LBound(arrData) To UBound(arrData)
        lblAxis4Poistion(iCnt).Caption = Format(arrData(iCnt) / 100, "##00.00")
      Next iCnt
  End Select
End Sub
簡單的心,是真正有福
單純的心,是真正的快樂    
T480 i5-8250U,32GB,SSD:2TB+256G
litung
臺灣-李同在
級別: VIP會員
精華主題: 2 篇
發(fā)帖數(shù)量: 578 個
工控威望: 3224 點
下載積分: 14494 分
在線時間: 405(小時)
注冊時間: 2009-06-06
最后登錄: 2024-09-19
查看litung的 主題 / 回貼
4樓  發(fā)表于: 2013-01-03 15:43
若問題解決了,煩請改一下標(biāo)題分類。
簡單的心,是真正有福
單純的心,是真正的快樂    
T480 i5-8250U,32GB,SSD:2TB+256G