h30631
級別: 略有小成
|
請問MX Component 使用vb 來寫,要用哪個指令抓取32位d值? 怎麼是都抓16位而已,求助~ [ 此帖被h30631在2013-01-03 17:01重新編輯 ] |
---|---|
|
litung
臺灣-李同在
級別: VIP會員
|
指令的話,使用 【ReadDeviceBlock2】 但要特別處理,才能讀到。 詳細,請參考mx內附的程式範例。 祝好運 |
|
---|---|---|
|
litung
臺灣-李同在
級別: VIP會員
|
好人作到底,給你完整的code 自己測試看看,有問題再討論 ===================================== Option Explicit '/*****************************************************/ '/*撰寫者:李同在 */ '/*日期:2009/09/07 V1.0 */ '/*用途:讀取三荾PLC的資料 */ '/*****************************************************/ Dim bufferBit As udtBitInteger '使用者自定型態 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 '/**************************************************************/ '/*功能:連續讀取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 |
|
---|---|---|
|
litung
臺灣-李同在
級別: VIP會員
|
你不是臺灣來的嗎?怎麼不在臺灣那邊發問? 你的CALL有問題,CALL回來的東西要放那裡?誰(程式)會知道? 當然就錯誤了。 一樣,直接給你現成的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 |
|
---|---|---|
|