New to serial port communication, used to C#, so I'm using a WPF app to communicate.
I have a thermal controller that came with a setup app and a user manual.
I am tasked with writing an application that will send commands to raise/lower the temperature.
To start, I would like to simply read the set temperature.
In APPENDIX C of the manual there are examples of the commands available.
The Read command (INPUT1) example says to "send" *00010000000041^
and I will receive a similar string that I can use to interpret the set temperature of the controller.
My Problem
I do not know how to properly send this command or receive the result!
The MainWindow.xaml.cs
instantiates a MainViewmodel
object, and that's where my code lies.
The constructor:
public MainViewmodel( MainWindow mw ){
TheMainWindow = mw;
DisplayAllPorts();
SP_COM5 = InitializePort( "COM5" );
// ReadTemp() is an empty try/catch block right now.
ReadTemp( SP_COM5 );
}
The InitializePort
method: this works, I tested by Opening and Closing the port.
public SerialPort InitializePort( string portName ){
var baud = 9600;
var parity = Parity.None;
var dataBits = 8;
var stopBits = StopBits.One;
var port = new SerialPort(portName, baud, parity, dataBits, stopBits);
port.ReadTimeout = 500;
port.WriteTimeout = 500;
port.DataReceived += SP_DataReceived;
return port;
}
What I need to know is how to to send that Read command *00010000000041^
.
Do I need to convert it into a byte array?
Will I receive a string back, or a series of bytes? I do understand a DataReceived event should be attached to the SerialPort object in question.
What is the correct SerialPort
read method to use in this case?
How do you (personally) interpret the examples in the manual attached?
Thank you for any help!
question from:https://stackoverflow.com/questions/65944027/c-sharp-serialport-read-command-help-interpretation