using
System;
using
System.Collections.Generic;
using
System.IO;
using
System.Net.Sockets;
using
System.Text;
namespace
RemoteAGV
{
static
public
class
COMM
{
static
private
TcpClient m_TcpClient =
null
;
static
NetworkStream m_ClientStream =
null
;
static
public
Byte[] m_WriteBuffer =
new
Byte[10];
static
public
bool
Connect()
{
m_TcpClient =
new
TcpClient();
if
(m_TcpClient.ConnectAsync(
"192.168.0.8"
, 8899).Wait(1000))
m_ClientStream = m_TcpClient.GetStream();
else
return
false
;
return
true
;
}
static
public
void
Close()
{
if
(m_ClientStream !=
null
) m_ClientStream.Close();
if
(m_TcpClient !=
null
) m_TcpClient.Close();
}
public
static
void
ClearWriteBuffer()
{
Array.Clear(m_WriteBuffer, 0, m_WriteBuffer.Length);
}
public
static
bool
WriteData()
{
try
{
if
(m_TcpClient.Connected && m_ClientStream !=
null
)
{
m_ClientStream.Write(m_WriteBuffer, 0, m_WriteBuffer.Length);
m_ClientStream.Flush();
}
}
catch
(IOException ex)
{
return
false
;
}
return
true
;
}
public
static
void
WriteEndData()
{
ClearWriteBuffer();
Byte _BCC = 0;
COMM.m_WriteBuffer[0] = 60;
COMM.m_WriteBuffer[1] = 83;
COMM.m_WriteBuffer[2] = 62;
COMM.m_WriteBuffer[3] = 0;
COMM.m_WriteBuffer[4] = 0;
COMM.m_WriteBuffer[5] = 0;
COMM.m_WriteBuffer[6] = 0;
for
(
int
i = 0; i < 7; i++)
{
_BCC ^= COMM.m_WriteBuffer[i];
}
COMM.m_WriteBuffer[7] = _BCC;
WriteData();
}
}
}