You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Data;
using Mesnac.Equips;
using Mesnac.Equips.BaseInfo;
using System.Runtime.InteropServices;
namespace Mesnac.Equip.Display.Text.Default
{
public class Equip : BaseEquip
{
public override bool Open()
{
lock (this)
{
blockReadCount = new Dictionary<string, int>();
return true;
}
}
private object[] getInfo(string str)
{
string info = str;
if (info.IndexOf("@") > 0)
info = info.Substring(info.IndexOf("@") + 1);
if (info.IndexOf("/") > 0)
info = info.Substring(0, info.IndexOf("/"));
string[] ss = info.Split(':');
object[] Result = new object[ss.Length - 1];
for (int i = 1; i < ss.Length; i++)
{
Result[i - 1] = double.Parse(ss[i]);
}
return Result;
}
private Dictionary<string, int> blockReadCount = new Dictionary<string, int>();
public override bool Read(string block, int start, int len, out object[] buff)
{
lock (this)
{
bool Result = false;
buff = new object[len];
int iReadCount = 0;
if (blockReadCount.TryGetValue(block, out iReadCount))
{
blockReadCount.Remove(block);
}
string buffstr = string.Empty;
for (int i = 0; i < 2; i++)
{
iReadCount++;
StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"ReceiveText.txt");
string nextLine = string.Empty;
int index = 0;
while (!string.IsNullOrWhiteSpace(nextLine = sr.ReadLine()))
{
string info = nextLine.Substring(nextLine.IndexOf("@") + 1);
string _block = info.Substring(0, info.IndexOf(":"));
if (_block == block)
{
index++;
}
if (iReadCount == index)
{
buffstr = nextLine;
Result = true;
break;
}
}
sr.Close();
if (Result)
{
break;
}
iReadCount = 0;
}
blockReadCount.Add(block, iReadCount);
if (Result)
{
object[] array = new object[len];
array = getInfo(buffstr);
if (array.Length >= len + start)
{
for (int i = 0; i < len; i++)
{
buff[i] = array[i];
}
}
}
return Result;
}
}
public override bool Write(int block, int start, object[] buff)
{
lock (this)
{
if (!this.Open())
{
return false;
}
return true;
}
}
public override void Close()
{
lock (this)
{
}
}
}
}