
scottel21 (Customer) asked a question.
I am writing a C# application to control the STP-MTRD 23042RE device. Everything going to the device is working great, but I cannot seem to read data from the device. Can someone help me get this going? Here are some code snippets I'm working with.
1. Opening the port:
Port = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
Port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
Port.Open();
2. Sending the IP command
public static string IPcommand = "IP";
Command = Encoding.ASCII.GetBytes(IPCommand);
Command = AddCRtoByteArray(Command);
Port.Write(Command, 0, Command.Length);
3. Receive data from device
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// Show all the incoming data in the port's buffer
string text = Port.ReadExisting();
trace(text);
}
All commands (such as CJ and SJ) are working, but my callback is never called.
Any guidance on what I need to change would be extremely appreciated! Thank you.
Take a look at the following thread.
https://stackoverflow.com/questions/13754694/what-is-the-correct-way-to-read-a-serial-port-using-net-framework
It may help you out.
Regards,
Garry
https://accautomation.ca/
Hi Garry,
Thanks so much for responding. I checked out the link you provided. The good news is that my code is pretty much verbatim with the first solution offered in the thread. The bad news is that it still isn't working. :(
Might you have any further insight on how to make it work?
Thanks again!