*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using S7;
namespace lib
{
class Program
{
public static void Main(string[] args)
{
S7.PLC plc = null;
string gsConnectionString="Provider=SQLOLEDB.1;"+
"Password=*****;"+
"Persist Security Info=True;"+
"User ID=app-user;"+
"Initial Catalog=*****;"+
"Data Source=*****\\SQLEXPRESS";
OleDbConnection gc_DBConnection = new OleDbConnection(gsConnectionString);
OleDbCommand gCm_DBCommand = new OleDbCommand();
OleDbDataAdapter gDa_DataAdapter = new OleDbDataAdapter();
string gsSQLQuery;
DataSet _DsCounter = new DataSet();
gsSQLQuery = "SELECT [HOST], [FIELD], conf_Counter.[FUNCTION] FROM conf_Counter, proc_CounterReset WHERE conf_Counter.[FUNCTION] = [proc_CounterReset].[FUNCTION] AND [VALUE] = 'True'";
gCm_DBCommand.CommandText = gsSQLQuery;
gCm_DBCommand.Connection = gc_DBConnection;
gDa_DataAdapter.SelectCommand = gCm_DBCommand;
gDa_DataAdapter.Fill(_DsCounter);
gCm_DBCommand.Connection = gc_DBConnection;
gCm_DBCommand.Connection.Open();
foreach (DataRow _Row in _DsCounter.Tables[0].Rows)
{
plc = new PLC(CPU_Type.S7300, _Row.ItemArray[0].ToString(), 0, 2);
ErrorCode errCode = plc.Open();
if (errCode == ErrorCode.NoError)
{
plc.Write(_Row.ItemArray[1].ToString(), 1);
gsSQLQuery = "UPDATE proc_CounterReset SET [VALUE]='False' WHERE [FUNCTION] = '" + _Row.ItemArray[2].ToString() + "'";
gCm_DBCommand.CommandText = gsSQLQuery;
gCm_DBCommand.ExecuteNonQuery();
}
}
gCm_DBCommand.Connection.Close();
_DsCounter = new DataSet();
gsSQLQuery = "SELECT [HOST], [FIELD], conf_Counter.[FUNCTION] FROM conf_Counter, proc_Counter WHERE conf_Counter.[FUNCTION] = [proc_Counter].[FUNCTION]";
gCm_DBCommand.CommandText = gsSQLQuery;
gCm_DBCommand.Connection = gc_DBConnection;
gDa_DataAdapter.SelectCommand = gCm_DBCommand;
gDa_DataAdapter.Fill(_DsCounter);
gCm_DBCommand.Connection = gc_DBConnection;
gCm_DBCommand.Connection.Open();
foreach (DataRow _Row in _DsCounter.Tables[0].Rows)
{
plc = new PLC(CPU_Type.S7300, _Row.ItemArray[0].ToString(), 0, 2);
ErrorCode errCode = plc.Open();
if (errCode == ErrorCode.NoError)
{
UInt32 b1;
if(_Row.ItemArray[2].ToString().IndexOf("LEV")<0)
b1 = (UInt32)plc.Read(_Row.ItemArray[1].ToString());
else
b1 = (UInt16)plc.Read(_Row.ItemArray[1].ToString());
gsSQLQuery = "UPDATE proc_Counter SET [VALUE]='" + b1 + "' WHERE [FUNCTION] = '" + _Row.ItemArray[2].ToString() + "'";
gCm_DBCommand.CommandText = gsSQLQuery;
gCm_DBCommand.ExecuteNonQuery();
}
}
gCm_DBCommand.Connection.Close();
}
}
}