Although the configuration software already has strong functions, there are also requirements for directly using third-party code in many occasions. For example, the user needs to transfer the real-time data collected by the configuration software to the VB program developed by himself for more complex data analysis, or to perform specific processing on the data collected by Century Star and then transmit it to Century Star. All these require a kind of data exchange mechanism.
Of course, there are many traditional ways to realize this exchange mechanism, such as using file sharing data DDE data and exchange mechanism. Although the traditional method can achieve the purpose of data exchange, its use method is cumbersome. To share data with files, it is necessary to perform file reading operations in the configuration software and external programs, which is not only troublesome but also relatively slow in processing speed, which is ineffective in projects that require better real-time performance. In order to allow third-party programs to easily read and write Century Star data, Century Star provides an OCX control based on ActiveX technology, which can be used in most development environments (such as VC++6.0, VB6.0), which is DBComm.
2nd Century Star Data Exchange Standard Control – DBComm
Century Star provides the standard control DBComm.ocx to exchange data with external third-party programs. The exchange contents include:
2.1 Real-time data exchange
External programs can read Century Star’s system variables (including system discrete, system integer, system real number and system information), memory variables (including memory discrete, memory integer, memory real number and memory information) and IO variables (including IO discrete, IO Integer, IO real number and IO information); can also rewrite the memory variable and IO variable of Century Star.
The relevant functions are as follows:
DiscValue=tagReadDisc(Tagname) The external program reads the current value of the discrete variable of Century Star;
IntValue=tagReadInt(Tagname) The external program reads the current value of the Century Star integer variable;
FloatValue=tagReadFloat(Tagname) The external program reads the current value of the real variable of Century Star;
MessValue=tagReadMess(Tagname) The external program reads the current value of the Century Star information variable;
tagWriteDisc(Tagname, DiscValue) The external program rewrites the current value of the discrete variable of Century Star;
tagWriteInt(Tagname, IntValue) The external program rewrites the current value of the Century Star integer variable;
tagWriteFloat(Tagname, FloatValue) The external program rewrites the current value of the real variable of Century Star;
tagWriteMess(Tagname, String) The external program rewrites the current value of the Century Star information variable;
InitComm() DBComm initialization function;
2.2 Historical data reading
That is to say, the external program can read the historical data of Century Star by time and variable name. The related functions are as follows:
TimeUINT=ConvertTime(Year, Month, Day, Hour, Minute, Second);
Time conversion function:
Read the historical data of Century Star according to the specified start and end date and time and the variable name of Century Star.
3 Application of DBComm in VB6.0
3.1 Schematic diagram of data exchange between VB project and Century Star project:
The following is a simple experiment to calculate the PID output power externally using a VB program:
Hardware required: Mitsubishi FX2N series PLC, FX2N-4AD-TC, heater, S-scale thermocouple, solid state relay.
Required software: Century Star configuration software 7.22, VB6.0.
The electrical schematic diagram is shown in the following figure:
The picture above is a heating control system. The PLC main module is responsible for controlling the on-off of the relay (PID output); the TC module is responsible for temperature acquisition (PID input); the upper computer Century Star is responsible for temperature setting, acquisition of lower computer signals, curve Display, data recording, data retrieval and other functions ; The VB part of the host computer is responsible for obtaining the set temperature SV from Century Star and measuring the temperature PV to calculate the PID output (the on-off time of the solid state relay).
3.2 Century Star Monitor
First, configure the control circuit correctly, connect the host computer to the PLC, then develop the Century Star monitoring program and create the corresponding driver, you can get the following monitoring screen:
3.3 VB plug-in program development
* Create a VB standard project.
* Projiec-components-DBComm ActiveX Control- Moudle.
* Initialize DBComm
* Read temperature setting and actual value from Century Star configuration software
* y0 output time calculation function (according to P=0.5, I=0.5, D=0)
Private Function PIDCalc(pp As PID, ByVal NextPoint As Double) As Double
Dim dError As Double
Dim Error As Double
Error = pp.SetPoint-NextPoint
pp.SumError = pp.SumError + Error
dError = pp.LastError – pp.PrevError
pp.PrevError = pp.LastError
pp.LastError = Error
PIDCalc = pp.P * Error + pp.i * pp.SumError + pp.D * dError
3.4 Heating output control
According to the heating time calculated in 2 (time percentage, x%*1s), output control to Y0 of PLC.
YO ON/OFF: tagWriteDisc (“y0”,1)/ tagWriteDisc (“y0”,0), Y0 pulse width modulation is shown in the following figure:
3.5 Experimental results
This project uses the Century Star configuration software to collect the actual temperature value (from PLC). By setting the target value of the temperature in the configuration software, the percentage of output power is calculated in the VB6.0 program, and the VB then calculates the heating time (Y0 time) ) is passed to the configuration software, and the configuration software is finally passed to the PLC to control the heating. Because the rough PID is used, the temperature control accuracy is within plus or minus 1 degree (the accuracy is not within the scope of this study), but VB has a good function of exchanging data in real time through DBComm and Century Star configuration software.
To sum up, the DBComm control provided by Century Star is easy to use and provides a complete data exchange interface for third-party programs. In addition, DBComm control can also access the historical database of Century Star configuration software, we will discuss it in detail next time.
The Links: CM300DX-24A KCS3224ASTT-X6