blah blah blah is here! blah blah » Close

up1down
link

Hi, I'm trying to write a program to control an external device (connection via crossover cable).
It isn't throwing me any errors but the device is not changing it's setting (I've triple checked the skippy codes). Anyone able to take a look and give me any suggestions would be greatly appreciated.

The connection is initialised as a result of a yes/no message box.

Here is the code:

case DialogResult.Yes:
// "Yes" processing
IPAddress ia = IPAddress.Parse(ipAddress);
IPEndPoint ie = new IPEndPoint(ia, 5555);

Socket sock1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

try
{
sock1.Connect(ie);
}

catch (SocketException e)
{
string error = e.ToString();
MessageBox.Show(error, "Problem connecting to host!",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
sock1.Shutdown(SocketShutdown.Both);
sock1.Close();
return;
}

try
{
string fMessage = "OUTPut:SQUelch ON";
Encoding ASCII = Encoding.ASCII;
Byte[] ByteGet = ASCII.GetBytes(fMessage);
sock1.Send(ByteGet, ByteGet.Length, 0);



MessageBox.Show("Did Squelch change?", "Check.",
MessageBoxButtons.OK, MessageBoxIcon.Warning);

sock1.Shutdown(SocketShutdown.Both);
sock1.Close();

}
catch (SocketException e)
{
string error = e.ToString();
MessageBox.Show(error, "Problem communicating to host!",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
sock1.Shutdown(SocketShutdown.Both);
sock1.Close();
return;
}

break;


case DialogResult.No:
// "No" processing
break;


}
}
catch (FormatException fEx)
{
MessageBox.Show(fEx.Message);
}
}

MadHatter
2309

check the device protocol to make sure you've implemented it *correctly* a lot of simple protocols like this terminate in a CRLF or something similar, and until you flush that down the pipe, it won't do anything. also I'd suggest not doing your initial test from a form. create a console app and step through it in the debugger (because of the way windows is threaded).

MickW
151

Thanks for the advice MadHatter. It was indeed the coding for the command - it needed \n at the end of it! Took me a damn age to find that out!!! Cheers.

last answered one year ago

1 answers

link

Add \n to the control command and always fully read the device documentation to avoid wasting loads of time. Didn't help that I'm new to this so it was entirely conceivable that I'd messed up something else.

Working now!!

Feedback