Thanks for your help so far.
The PC App have started receiving data from the PIC.
the problem that remain is that when I typed Olakunle.
on the richtextbox1, I expected the pic to capture that data
and reply me with
"Welcome to the Pacific Energy :
Olakunle" on the richtextbox2
however, it now only display
Welcome to the Pacific Energy : without including the received Olakunle.
Please how can I know or make the pic receive my sent data from the PC and have the pic reply with
Welcome to the Pacific Energy :
Olakunle
or the pic reply with Welcome to the Pacific Energy :
and any other data I transmitted to the pic.
the code is as shown below.
Thanks.
Kunle.
PC Serial App Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace SerialPortApp_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
comboBox1.Items.Add(port);
}
}
SerialPort sp;
void sErial(string Port_Name)
{
sp = new SerialPort(Port_Name, 9600, Parity.None, 8, StopBits.One);
sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
sp.Open();
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string w = sp.ReadLine();
//string msg = sp.ReadExisting();
if (w != String.Empty)
{
Invoke(new Action(() => richTextBox2.AppendText(w)));
}
}
private void button3_Click_1(object sender, EventArgs e)
{
string t = comboBox1.Text.ToString();
sErial(t);
}
private void button2_Click(object sender, EventArgs e)
{
string t = comboBox1.Text.ToString();
string s = richTextBox1.Text.ToString();
sErial2(t, s);
}
void sErial2(string Port_Name, string Data_Send)
{
sp = new SerialPort(Port_Name, 9600, Parity.None, 8, StopBits.One);
sp.Open();
sp.Write(Data_Send);
sp.Close();
}
}
}
PIC Code
void newline(){
UART1_Write(13);
UART1_Write(10);
}
char txt[60];
void main() {
UART1_Init(9600);
UART1_Write_Text("What is your Name ?");
if(UART1_Data_Ready()==1){
UART1_Read_Text(txt, ".",
;
while(1){
UART1_Write_Text("Welcome to the Pacific Energy : ");
Delay_ms(1000);
newline();
UART1_Write_Text(txt);
Delay_ms(1000);
newline();
}
}
}