Hello there !
I am try a very simple to read serialport of OPTA
using System;
using System.IO.Ports;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace OptaStudy2
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
}
private void BtnConnect_Click(object sender, EventArgs e)
{
if (!serialPort1.IsOpen)
{
serialPort1.BaudRate = 9600;
serialPort1.PortName = "COM4"; // As per your setup, make sure it's the correct COM port
serialPort1.Parity = Parity.None;
serialPort1.DataBits = 8;
serialPort1.StopBits = StopBits.One;
serialPort1.NewLine = "\r\n"; // Arduino println sends \r\n for new line
try
{
serialPort1.Open();
BtnConnect.Text = "Disconnect";
}
catch (Exception ex)
{
MessageBox.Show("Error opening port: " + ex.Message);
}
}
else
{
serialPort1.Close();
BtnConnect.Text = "Connect";
}
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
string data = serialPort1.ReadExisting();
richTextBox1.Invoke(new MethodInvoker(delegate
{
richTextBox1.Text += data;
}));
}
catch (Exception ex)
{
// Log or display the error message
MessageBox.Show("Failed to read from serial port: " + ex.Message);
}
}
private void Main_Load(object sender, EventArgs e)
{
}
}
}
and in my IDE
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Test message");
delay(1000);
}
i am using OPTA Finnder AFX000002 ,
this code is work very well with arduino uno, but OPTA is not
is there any different uno vs OPTA here ?