public void SendCommand_Network(Receiver r, String command)
{
try
{
int length = command.Length;
length++;
int total = length + 16;
char code = (char)length;
// build up packet header and rest of command - followed by <CR> (chr(13))
string line = "ISCP\x00\x00\x00\x10\x00\x00\x00" + code + "\x01\x00\x00\x00" + command + "\x0D";
if (r.tcpClient.Connected)
{
// send command to receiver
r.clientStreamWriter.WriteLine(line);
r.clientStreamWriter.Flush();
Log.Info("Sent command: " + line);
}
else
{
try
{
if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
{
Log.Debug("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort);
r.tcpClient = new TcpClient(r.IP, r.NetworkPort);
//get a network stream from server
r.clientSockStream = r.tcpClient.GetStream();
// create new writer and reader stream to send and receive
r.clientStreamWriter = new StreamWriter(r.clientSockStream);
r.clientStreamReader = new StreamReader(r.clientSockStream);
//Start listening
r.Connect();
// send command to receiver
//
r.clientStreamWriter.WriteLine(line);
r.clientStreamWriter.Flush();
Log.Info("Sent command: " + line);
}
else
{
Log.Info(r.Name + " - Properties not set");
}
}
catch (Exception ex)
{ Log.Error("Error creating connection to receiver. Command can not be sent", ex); }
}
}
catch (Exception e)
{ Log.Error("Error sending command", e); }
}