Hello,
a customer has equipment which writes the data in SQL database. And now he would like to have this data in variables in PcVue. Not as a part of historical trends but as some kind of "real-time" data.
Can you give me some ideas how it can be done? SV manager?
Or maybe DDE can work with SQL?
Thank you in advance.
Your customers can't make a communication directly between equipment and PcVue ?
Use SQL to have the last value for "Real-time" value is not vey commun.
He told me he can't connect directly to the equipment.
Yes, it's uncommon way of using database that's why I am asking here 🙂
I understand, but before make a huge development with script, customer have to know hat his request is not "normal"
A way to do that can be with Transact SQL request from Scada Basic or VBA to force PcVue value.
@Romain: I disagree with you as this request is not uncommon. I have it here regularly! Some other scada have a SQL driver by the way...
@Anna: The good way depends on the number of data to get and, more important, the polling period.
If it is reasonable you can do it easily by VBA. If a lot of data and/or fast polling then Manager Toolkit.
Do you have these figures?
Another point to decide the way is the Timestamp (and also Quality): If the user wants keeping the timestamp recorded in the DB then the only way is to use the Manager Toolkit as you can't set the timestamp (and quality) by VBA.
Anyway, to get the last value the SQL request is: SELECT TOP (1) * FROM [TableName]
Here I give you the script to do it when the Table has an HDS format. You can see it is very simple.
Note:
1. You must add the Reference "Microsoft ActiveX Data Objects 6.1 Library" (or another version, 6.1 is not mandatory)
2. You must change the ConnectionString according yours
Dim cnx As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rq As ADODB.Recordset
Public Sub SetVarValues()
On Error GoTo KBoom
cnx.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TST-HDS_DATABASE1;Data Source=.SQLEXPRESS_2016"
cnx.Open
cmd.ActiveConnection = cnx
cmd.CommandText = "SELECT TOP (1) [Name], [Value] FROM [TST-HDS_DATABASE1].[dbo].[SET_01]"
Set rq = cmd.Execute
rq.MoveFirst
While rq.EOF = False
Dim varName As String
Dim VarValue As Variant
varName = rq.Fields(0).Value
VarValue = rq.Fields(1).Value
Variables(varName).Value = VarValue
rq.MoveNext
Wend
cnx.Close
Exit Sub
KBoom:
Debug.Print "Error: ", Err.Description
cnx.Close
End Sub
Don't give this script to your customer before knowing the figures (number of data?, polling rate?, timestamp?, quality?).
Nico
I agree with Nico that this is a frequent request.
Just for the sake of completeness I would like to add that the requirement could also be fulfilled by putting a 3rd party component in between PcVue and the database server. I remember that the KepWare OPC server for instance includes a driver for connecting relational database systems.
Yes get data from a database is commun, but get data from database to use it a real time data for me it's not commun and not very efficient.
By the way wih the Nico's solution your customer will have a solution.
Good point Armin! I forgot Kepware & Co have this sql driver!
@Romain: Actually, and just for information, this request is quite common in the telemetry market. And, at least here in Malaysia, this is a market quite active. Typical project is: Several Water pumping stations are dispatched in an large Area. Datalogger is storing pressure and flow points periodically (~=5mn) then regularly (from every 1h to once a day) the logger sends by sms the file containing all the records. Finally a software provided by the logger manufacturer is importing the file to a DB.
Customer wants to see the 'real time' value (aka the last point) and of course the archives.
Nico
Recent posts on the thread reflect the answer I did to Anna via email last week - Was on an exhibition and it was easier with emails than posting to the forum. To summarize, no, it is not an "unusual" request. But it is a usual bias to put what we are not comfortable with in the list of unusual stuff. As said by others in the meantime, an SQL to OPC solution from Kepware or Matrikon should be able to do the job better than any VBA script.
https://www.matrikonopc.com/opc-drivers/836/index.aspx
https://www.ptc.com/en/store/kepware/drivers/odbc-client
If one wants to do some test, it is worth doing it for real, with a summary of what is fine and what is not. There is a template document available for OPC Server validation. Thanks


