SCADA - VBS EN WINCC

 
Vista:

VBS EN WINCC

Publicado por Joan (1 intervención) el 23/10/2007 18:17:35
alguien me puede ayudar con la asignación de variables en vbs wincc. Hago lo que la ayuda dice y no funciona. El problema reside en que utilizamos un controlador de temperatura y humedad para una cámara climática. Unimos el wincc con el controlador a través de OPC. El problema reside en que el controlador emite el valor de la variable en formato integer(double para ser exactos), dicha variable es la hora, el problema es que en la conversión de dicho nº a caracter para que después el wincc lo pase por pantalla no me funciona.

el script es algo asi

procedure 1()
dim num
dim hora
dim min
dim seg
dim final

num=cdouble(HMIRuntime.tags("tiempo"))
hora=num/3600
min=num mod 3600
seg=min mod 60
min=min/60
final=hora & ":" & min & ":" seg
HMIRuntime.tags("tiempo_final").write=final

end procedure

esto lo meto en un campo de datos e/s, pero no me da nada. El OPC tampoco me da nada del valor de la variable.

ayuda!!!!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:VBS EN WINCC

Publicado por fido dido (1 intervención) el 12/11/2010 18:16:49
a ver si te sirve hermano!

Option Explicit
Function action
Dim objConnection
Dim objCommand
Dim objRecordset
Dim strConnectionString
Dim lngValue
Dim lngCount
Dim iSilo, iPro, iSeg, iMin, iHor, S, M, H
Dim iTipo
Dim lRem
Dim rPeso
Dim sHora
Dim sFecha
Dim rHora
Dim rFecha
Dim sSQLCampos, sSQLValores, sSQLText

On Error Resume Next

rPeso= Round(HMIRuntime.Tags("Peso_Har").Read)
iSilo = HMIRuntime.Tags("Silo_Har").Read

If (HMIRuntime.Tags("Ini_Harina").Read = 1) Then

HMIRuntime.Trace "///////////////////////////////////////////////////////////////////////" & vbNewLine
HMIRuntime.Trace "Actualización de Carga de Silo" & vbNewLine

'Carga las variables del HMI
iTipo = HMIRuntime.Tags("Tipo_Har").Read
iPro = HMIRuntime.Tags("Pro_Har").Read
lRem = HMIRuntime.Tags("Rem_Har").Read

rFecha = HMIRuntime.Tags("Fecha_Har").Read
If rFecha <> 0 Then
rFecha = FormatDateTime(rfecha,2)
Else
rFecha = FormatDateTime("01/01/2000",2)
End If

rHora = HMIRuntime.Tags("Hora_Har").Read
rHora = FormatDateTime(rHora,4)

iSeg = (Timer-HMIRuntime.Tags("Tiempo_Har").Read) \ 1
iMin = iSeg \ 60
iHor = iMin \ 60
iSeg = iSeg-iMin * 60
iMin = iMin-iHor * 60
S = "0" & iSeg
M = "0" & iMin
H = "0" & iHor
H=Right(H, Len(H) - Len(H) \ 3)
M=Right(M, Len(M) - Len(M) \ 3)
S=Right(S, Len(S) - Len(S) \ 3)

'Genera la Fecha y Hora en formato datetime de SQL
'sFecha = Date
'sHora = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)

'Dejo un rastro de los datos utilizados
HMIRuntime.Trace "Tiempo: " & H & ":" & M & ":" & S & vbNewLine
HMIRuntime.Trace "Fecha: " & rFecha & " " & rHora & vbNewLine
HMIRuntime.Trace "Silo: " & iSilo & vbNewLine
HMIRuntime.Trace "Peso: " & rPeso & vbNewLine
HMIRuntime.Trace "Proveedor: " & iPro & vbNewLine
HMIRuntime.Trace "Remito: " & lRem & vbNewLine

Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=fido;Data Source=.\WINCC"
objConnection.CursorLocation = 3
objConnection.Open

Set objRecordset = CreateObject("ADODB.Recordset")

Set objCommand = CreateObject("ADODB.Command")

sSQLCampos = "Silo, Peso, Tipo, Proveedor, Remito, Fecha, Tiempo"
sSQLValores = iSilo & ", " & rPeso & ", " & iTipo & ", " & iPro & ", " & lRem & ", " &_
"CONVERT(datetime, '" & rFecha & " " & rHora & "', 103), CONVERT(nchar, '" & H & ":" & M & ":" & S & "', 103)"

sSQLText = "INSERT INTO Carga_H( " & sSQLCampos & " ) VALUES ( " & sSQLValores & ");"

With objCommand

.ActiveConnection = objConnection
.CommandText = sSQLText
.Execute

End With


If (err.number = 0) Then

HMIRuntime.Trace "El informe de Carga de Materia Prima se ha generado exitosamente" & vbNewLine

Else

HMIRuntime.Trace "Ha ocurrido un error al generar el informe de Carga de Materia Prima" & vbNewLine
HMIRuntime.Trace "El numero del error es: " & err.number & vbNewLine
err.clear

End If

Set objCommand = Nothing
objConnection.Close
Set objRecordset = Nothing
Set objConnection = Nothing

HMIRuntime.Trace "///////////////////////////////////////////////////////////////////////" & vbNewLine

HMIRuntime.Tags("Ini_Harina").Write 0

End If

End Function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:VBS EN WINCC

Publicado por cobe (1 intervención) el 21/11/2010 14:12:24
Muy tarde ya lo resolví hace unos 3 años.
Pero gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar