|
@@ -46,7 +46,6 @@ namespace SIASUN.TwinCatLogger
|
|
//{
|
|
//{
|
|
// textNotice.Text = "创建开机自动启动任务失败:" + ex.Message;
|
|
// textNotice.Text = "创建开机自动启动任务失败:" + ex.Message;
|
|
//}
|
|
//}
|
|
- 小数位数 = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["小数位数"]);
|
|
|
|
单文件行数 = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["单文件行数"]);
|
|
单文件行数 = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["单文件行数"]);
|
|
//LogonStart.CreateLogonTask(!runInDebug);
|
|
//LogonStart.CreateLogonTask(!runInDebug);
|
|
timer1.Interval = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["刷新时间"]);
|
|
timer1.Interval = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["刷新时间"]);
|
|
@@ -106,7 +105,6 @@ namespace SIASUN.TwinCatLogger
|
|
|
|
|
|
#region 数据
|
|
#region 数据
|
|
bool runInDebug = false;
|
|
bool runInDebug = false;
|
|
- int 小数位数 = 0;
|
|
|
|
int 单文件行数 = 0;
|
|
int 单文件行数 = 0;
|
|
int 当前行数 = 0;
|
|
int 当前行数 = 0;
|
|
|
|
|
|
@@ -149,7 +147,7 @@ namespace SIASUN.TwinCatLogger
|
|
return typeof(float);
|
|
return typeof(float);
|
|
if (typename.ToUpper() == "LREAL")
|
|
if (typename.ToUpper() == "LREAL")
|
|
return typeof(Double);
|
|
return typeof(Double);
|
|
- return typeof(bool);
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
private bool LoadPointList()
|
|
private bool LoadPointList()
|
|
@@ -170,12 +168,13 @@ namespace SIASUN.TwinCatLogger
|
|
arrItem = line.Split(',');
|
|
arrItem = line.Split(',');
|
|
if (arrItem.Length != 3)
|
|
if (arrItem.Length != 3)
|
|
continue;
|
|
continue;
|
|
- plcPoint.name = arrItem[0];
|
|
|
|
- if (!runInDebug || plcPoint.type == null)
|
|
|
|
- {
|
|
|
|
- plcPoint.address = arrItem[1];
|
|
|
|
- plcPoint.type = GetTypeByName(arrItem[2]);
|
|
|
|
- }
|
|
|
|
|
|
+ plcPoint.name = arrItem[0].Trim();
|
|
|
|
+ plcPoint.address = arrItem[1].Trim();
|
|
|
|
+ if (plcPoint.address.Length == 0)
|
|
|
|
+ continue;
|
|
|
|
+ plcPoint.type = GetTypeByName(arrItem[2].Trim());
|
|
|
|
+ if (plcPoint.type == null)
|
|
|
|
+ continue;
|
|
pointList.Add(plcPoint);
|
|
pointList.Add(plcPoint);
|
|
textNotice.Text = "已从" + filePath + "读取" + pointList.Count.ToString() + "条数据定义";
|
|
textNotice.Text = "已从" + filePath + "读取" + pointList.Count.ToString() + "条数据定义";
|
|
}
|
|
}
|
|
@@ -251,7 +250,11 @@ namespace SIASUN.TwinCatLogger
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- int handle = adsClient.CreateVariableHandle(varName);
|
|
|
|
|
|
+ int handle = 0;
|
|
|
|
+ if (varName.Contains("."))
|
|
|
|
+ handle = adsClient.CreateVariableHandle(varName);
|
|
|
|
+ else
|
|
|
|
+ handle = adsClient.CreateVariableHandle("." + varName);
|
|
return handle;
|
|
return handle;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
@@ -330,6 +333,7 @@ namespace SIASUN.TwinCatLogger
|
|
}
|
|
}
|
|
|
|
|
|
public delegate void AsyncEventHandler();
|
|
public delegate void AsyncEventHandler();
|
|
|
|
+ private static object m_Lock = new object();
|
|
|
|
|
|
private string getValue(int index)
|
|
private string getValue(int index)
|
|
{
|
|
{
|
|
@@ -347,7 +351,7 @@ namespace SIASUN.TwinCatLogger
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void BeginReadAllValues()
|
|
|
|
|
|
+ private void ReadAllValues()
|
|
{
|
|
{
|
|
AsyncEventHandler asy = new AsyncEventHandler(AsyncReadAllValues);
|
|
AsyncEventHandler asy = new AsyncEventHandler(AsyncReadAllValues);
|
|
IAsyncResult result = asy.BeginInvoke(null, asy);
|
|
IAsyncResult result = asy.BeginInvoke(null, asy);
|
|
@@ -360,36 +364,21 @@ namespace SIASUN.TwinCatLogger
|
|
for (int i = 0; i < handleList.Count; i++)
|
|
for (int i = 0; i < handleList.Count; i++)
|
|
{
|
|
{
|
|
string value = getValue(i);
|
|
string value = getValue(i);
|
|
- int p = value.IndexOf('.');
|
|
|
|
- if (p > 0)
|
|
|
|
- line.Append("," + value.Substring(0, p + 1 + 小数位数));
|
|
|
|
- else
|
|
|
|
- line.Append("," + value);
|
|
|
|
|
|
+ line.Append("," + value);
|
|
}
|
|
}
|
|
- fileWriter.WriteLine(line);
|
|
|
|
- 当前行数++;
|
|
|
|
- if (单文件行数 > 0 && 当前行数 >= 单文件行数)
|
|
|
|
|
|
+ lock (m_Lock)
|
|
{
|
|
{
|
|
- fileWriter.Flush();
|
|
|
|
- fileWriter.Close();
|
|
|
|
- CreateLogFile();
|
|
|
|
|
|
+ fileWriter.WriteLine(line);
|
|
|
|
+ 当前行数++;
|
|
|
|
+ if (单文件行数 > 0 && 当前行数 >= 单文件行数)
|
|
|
|
+ {
|
|
|
|
+ fileWriter.Flush();
|
|
|
|
+ fileWriter.Close();
|
|
|
|
+ CreateLogFile();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void ReadAllValues()
|
|
|
|
- {
|
|
|
|
- BeginReadAllValues();
|
|
|
|
- //string time = DateTime.Now.ToString("HH:mm:ss.fff");
|
|
|
|
- //fileWriter.Write(time);
|
|
|
|
- //for (int i = 0; i < handleList.Count; i++)
|
|
|
|
- //{
|
|
|
|
- // string value = adsClient.ReadAny(handleList[i], pointList[i].type).ToString();
|
|
|
|
- // fileWriter.Write("," + value);
|
|
|
|
- //}
|
|
|
|
- //fileWriter.WriteLine();
|
|
|
|
- //fileWriter.Flush();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
{
|
|
if (isRecording)
|
|
if (isRecording)
|