namespace luoqicheng.SCAN
{
internal class DataLogicScan : SCANBase
{
private Com m_communication;
private string m_ipAddress = string.Empty;
private int m_port = 0;
public DataLogicScan(Com communication, string ip, int port)
{
m_communication = communication;
m_ipAddress = ip;
m_port = port;
}
public string Type
{
get { return "DATALOGIC"; }
}
public bool Init()
{
try
{
if (!m_communication.IsOpen)
{
m_communication.Init();
if (!m_communication.IsOpen)
{
return false;
}
}
return true;
}
catch (Exception ex)
{
return false;
}
}
public Tuple<bool, string> Scan(int x)
{
return new Tuple<bool, string>(item1: false, string.Empty);
}
public Tuple<bool, string> Scan()
{
try
{
if (!m_communication.IsOpen)
{
m_communication.Init();
}
if (m_communication.IsOpen)
{
for (int i = 0; i < 3; i++)
{
Tuple<bool, string, string> tuple = m_communication.SendRedReceive("+", 500);
Close();
if (tuple.Item1)
{
string item = tuple.Item2;
int num = item.IndexOf("\0");
if (num > -1)
{
return new Tuple<bool, string>(item1: true, item.Substring(0, num).Trim());
}
}
}
}
return new Tuple<bool, string>(item1: false, string.Empty);
}
catch (Exception ex)
{
return new Tuple<bool, string>(item1: false, string.Empty);
}
}
public void Close()
{
try
{
m_communication.SendRedReceive("-", 500);
}
catch (Exception ex)
{
}
}
public bool Status()
{
try
{
if (!m_communication.IsOpen)
{
m_communication.Init();
if (!m_communication.IsOpen)
{
return false;
}
}
if (m_communication.IsOpen)
{
return true;
}
return false;
}
catch (Exception ex)
{
return false;
}
}
}
}