TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bas Knippels
NA
9
615
How let a class send a signal to the main class
Aug 17 2017 5:00 AM
The question is about the serial class. One of the class's methods is void port_dataReceived(). This function is a serial event and get triggered when a byte is received over the serial port.
This byte must be processed in the rest of the code. Right now I can acces it with a pushbutton and that works but I need to this to work automatically.
The bytes can contain instructions which places text on the userinterface. For instance "
Textblok.Text += received_byte;
"
How can I let the serial class add the byte in the the textblock?
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Windows;
using
System.Diagnostics;
using
System.Windows.Controls;
using
System.Windows.Data;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Imaging;
using
System.Windows.Navigation;
using
System.Windows.Shapes;
using
System.IO.Ports;
class
Serial
{
private
SerialPort port =
new
SerialPort(
"COM3"
, 115200, Parity.None, 8, StopBits.One);
String received;
public
Serial()
{
port.DataReceived +=
new
SerialDataReceivedEventHandler(port_DataReceived);
port.Open();
}
public
void
port_DataReceived(
object
sender, SerialDataReceivedEventArgs e)
{
received = port.ReadExisting();
Debug.Write(received);
}
public
String getReceived()
{
return
received;
}
}
namespace
WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public
partial
class
MainWindow : Window
{
Serial serial =
new
Serial();
public
MainWindow()
{
InitializeComponent();
}
private
void
pagedown_Click(
object
sender, RoutedEventArgs e)
{
Textblok.Text = serial.getReceived();
Debug.Write(
"hello world"
);
}
private
void
menu_Click(
object
sender, RoutedEventArgs e)
{
}
private
void
pageup_Click(
object
sender, RoutedEventArgs e)
{
}
private
void
stop_Click(
object
sender, RoutedEventArgs e)
{
}
private
void
step_Click(
object
sender, RoutedEventArgs e)
{
}
private
void
start_Click(
object
sender, RoutedEventArgs e)
{
}
}
}
Reply
Answers (
2
)
how to get values from asp gridview to code behind to updat
Login form using data base