Hi
I am battling for days now to send and receive the correct characters to hardware from my code. It works fine in tera term.
I have to send ASCII 4 " alt 004" in tera Term to poll the datalogger to return the data stream saved in memory. The hardware works fine and I get the correct data, but I can't seem to get the harware polled from my software. If I do a manual trigger on the hardware it sends the data, but it shows in some binary format. I have tried several ways to decode an encode, but it just seems to slip out of my reach.
Help will be greatly appreciated.
private void SendData()
{
if (serialPort1.IsOpen)
{
try
{
serialPort1.WriteLine(pollPur);
MessageBox.Show("Command Issued: " + pollPur);
}
catch
{ }
}
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
{
try
{
string PortData = serialPort1.ReadExisting();
}
catch (TimeoutException)
{
return; // Data not ready yet
}
}
private void btnOpenPort_Click_1(object sender, EventArgs e)
{
// If the port is open, close it.
if (serialPort1.IsOpen) serialPort1.Close();
else
{
// Set the port's settings
serialPort1.BaudRate = int.Parse(cmbBaudRate.Text);
serialPort1.DataBits = int.Parse(cmbDataBits.Text);
serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), cmbStopBits.Text);
serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), cmbParity.Text);
serialPort1.PortName = cmbPortName.Text;
serialPort1.ReadTimeout = 500;
serialPort1.WriteTimeout = 500;
// Open the port
serialPort1.Open();
SendData();
textBox10.Text = serialPort1.ReadLine();
}
if (serialPort1.IsOpen)
{
btnOpenPort.BackColor = Color.LimeGreen;
}
else
{
btnOpenPort.BackColor = Color.Red;
}
if (serialPort1.IsOpen) toolStripMenuItem7.Text = "&Disconnect";
else toolStripMenuItem7.Text = "&Connect";
}