Vai al contenuto
PLC Forum


Chiarimenti Sulla Comunicazione Visual Basic-s7200


sorecaro

Messaggi consigliati

Diciamo che i post per Libnodave potevano essere stati inseriti in questa altra discussione Link, aperta da sorecaro.

Qui si parlava di PCACCESS, che e' un OPC Server, e quindi qualcosa di diverso. Link

Poicche Libnodave non utilizza la tecnologia OPC, e sarebbe un OpenSource software.

Link al commento
Condividi su altri siti


sto cercando di capire l'esempio dato da pcaccess in visual basic e qualcosa sono risuscito ad interpretare. allora cominciamo.

Private Sub cmdAddItem_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAddItem.Click

On Error GoTo ErrorHandler

Dim i As Integer

Dim ErrorFlag As Boolean

Dim ItemObj As OPCSiemensDAAutomation.OPCItem

'UPGRADE_WARNING: Il limite inferiore della matrice ItemIDs è stato cambiato da 1 a 0. Fare clic per ulteriori informazioni: 'ms-.://MS.V***pressCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'

Dim ItemIDs(2) As String

'UPGRADE_WARNING: Il limite inferiore della matrice ItemClientHandles è stato cambiato da 1 a 0. Fare clic per ulteriori informazioni: 'ms-.://MS.V***pressCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'

Dim ItemClientHandles(2) As Integer

Dim Errors() As Integer ' Array for returned Item related errors

ErrorFlag = False

MyItems = MyGroup.OPCItems ' Get OPCItems Collection Object from MyOPCServer

' Initialize the [iN] parameters for the Add Items call

' ItemIDs -> ItemIDs of the Items to add

' ItemClientHandles -> Client defined handles for the Items. The Server sends these handles in the Callbacks

ItemIDs(1) = txtItem2.Text

ItemIDs(2) = txtItem2.Text ' Read ItemId 2 from Text Box

ItemClientHandles(1) = 1

ItemClientHandles(2) = 2

' [OUT] parameters are

' ItemServerHandles -> Server defined handles for the Items. The client must use these handles for all Read/Write calls

' Errors -> Item related errors

' Add Items to the Group

Call MyItems.AddItems(2, ItemIDs, ItemClientHandles, MyItemServerHandles, Errors)

' Check Item Errors

For i = 1 To 2

If Not Errors(i) = 0 Then

MsgBox("Item " & Str(i) & " FAILED. Error Code = " & Str(Errors(i)), MsgBoxStyle.Critical)

ErrorFlag = True

End If

Next

' Continue only if all Items SUCCEEDED

Dim RemoveErrors() As Integer

'UPGRADE_WARNING: Il limite inferiore della matrice RemoveHandles è stato cambiato da 1 a 0. Fare clic per ulteriori informazioni: 'ms-.://MS.V***pressCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'

Dim RemoveHandles(1) As Integer

If ErrorFlag Then

' Remove Succeede Items

For i = 1 To 2

If Errors(i) = 0 Then

RemoveHandles(1) = MyItemServerHandles(i)

Call MyItems.Remove(1, RemoveHandles, RemoveErrors)

End If

Next

Else

' Set Button Enable

cmdAddItem.Enabled = False

cmdRemGroup.Enabled = False

cmdRemItem.Enabled = True

cmdWriteSync.Enabled = True

cmdWriteAsync.Enabled = True

cmdReadSync.Enabled = True

cmdReadAsync.Enabled = True

End If

Exit Sub

questa dovrebbe essere la sub del pulsante Aggiungi Item. l'item di pcaccess viene aggiunto quando nella txt1item viene scritto ad esempio 2,M0.0,bit premo il pulsante aggiunfi item e viene aggiunto ne MYitems .se io cambio la dicitura di txtitem1.text in "2,M0.0,bit" il risultato dovrebbe essere lo stesso??

Private Sub cmdWriteAsync_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdWriteAsync.Click

On Error GoTo ErrorHandler

Dim i As Integer

'UPGRADE_WARNING: Il limite inferiore della matrice Values è stato cambiato da 1 a 0. Fare clic per ulteriori informazioni: 'ms-.://MS.V***pressCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'

Dim Values(2) As Object

Dim Errors() As Integer ' Array for returned Item related errors

Dim CID As Integer ' CancelID, servergenerierter Wert, mit dem die Transaktion identifiziert

' Initialize the [iN] parameters for the SyncWrite call

' Values -> Values to write

'UPGRADE_WARNING: Impossibile risolvere la proprietà predefinita dell'oggetto Values(1). Fare clic per ulteriori informazioni: 'ms-.://MS.V***pressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'

Values(1) = txtWriteVal1.Text ' Read Value 1 from Text Box

'UPGRADE_WARNING: Impossibile risolvere la proprietà predefinita dell'oggetto Values(2). Fare clic per ulteriori informazioni: 'ms-.://MS.V***pressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'

Values(2) = txtWriteVal2.Text ' Read Value 2 from Text Box

' ItemServerHandles -> Server defined handles from the AddItems call

MyTID = MyTID + 1 ' Increment Transaction ID

' Write Values Asyncronous

Call MyGroup.AsyncWrite(2, MyItemServerHandles, Values, Errors, MyTID, CID)

' Check Item Errors

For i = 1 To 2

If Not Errors(i) = 0 Then MsgBox("Item " & Str(i) & " FAILED. Error Code = " & Str(Errors(i)), MsgBoxStyle.Critical)

Next

Exit Sub

ErrorHandler:

MsgBox(Err.Description & Chr(13) & "Writing Items Asyncronous", MsgBoxStyle.Critical, "ERROR")

End Sub

questa e' la sub del pulsante scrivi valore nell item. se io cambio values(1)=txtwritevall.text in values(1)= 1 penso che nell'item 1 (2,M0.0,bit) mi dovrebbe scrivere il valora 1. ci sono o ho sbagliato tutto??

Link al commento
Condividi su altri siti

scusa se non ti ho risposto prima ma ho avuto dei dei problemik con fastweb. allora l'errore che mi da e' =IMPOSSIBILE ESEGUIRE IL CAST DI OGGETTI DI TIPO 'SYSTEM.INT32[*] SUL TIPO 'SYSTEM.INT32[]. ADDING ITEM TO THE GROUP.

penso che l'errore sia dovuto ad un fatto di conversione da vb6 a vb2005 perche con vb6 funziona correttamente.

provando cpon vb6 va tutto bene e risesco ad associare un valore ad un item. ma appena mi creo un pulsante nuoivo, gli copio il contenuto della sup di un pulsante del progetto di esempio che dovrebbe scrivere un valore in un item non va, mi dice che l'oggetto non e' associato. ho fatto varie prove ma niente, lo so che chiedo troppo ma se era possibile avere un piccolo esempio completo,sia vb6 o vb2005express edition, che abbia 2 pulsanti, uno che legge un valore, ed un altro che lo scirve perche non rieco a farlo, ho fatto le prove usando excel e va tutto a meraviglia

Link al commento
Condividi su altri siti

Crea un account o accedi per commentare

Devi essere un utente per poter lasciare un commento

Crea un account

Registrati per un nuovo account nella nostra comunità. è facile!

Registra un nuovo account

Accedi

Hai già un account? Accedi qui.

Accedi ora
×
×
  • Crea nuovo/a...