Serial port communication in Visual Studio C# - c#

I have used this code in VS
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string RxString,ComPort;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
serialPort1.PortName = "COM5";
serialPort1.BaudRate = 9600;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.Handshake = Handshake.None;
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
}
private void Start_Click(object sender, EventArgs e)
{
serialPort1.PortName = ComPort;
serialPort1.BaudRate = 9600;
serialPort1.Open();
if(serialPort1.IsOpen)
{
Start.Enabled = false;
Stop.Enabled = true;
textBox1.ReadOnly = false;
}
}
private void Stop_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
Start.Enabled = true;
Stop.Enabled = false;
textBox1.ReadOnly = true;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (serialPort1.IsOpen) serialPort1.Close();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!serialPort1.IsOpen) return;
char[] buff = new char[1];
buff[0] = e.KeyChar;
serialPort1.Write(buff, 0 , 1);
e.Handled = true;
}
private void DisplayText(object sender, EventArgs e)
{
textBox1.AppendText(RxString);
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
RxString = serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ComPort = comboBox1.SelectedItem.ToString();
}
}
}
but it's not working, I have tried using an avr for transmitting characters and successfully tested in hercules what its transmitting. But it is not showing up in my program. Please help.
I have updated the code and its working fine for receiving part but not transmitting correctly, i am not getting any error it is just not working as it should have worked.

You must set all the properties of your serialPort1.
Also, you should try to debug at multiple place to help us where it's going wrong : Does IsOpen return true? if no, this explain why you receive nothing.
See MSDN example if you want to try something is supposed to work : http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx
Be sure that the serial port is not alerady open by another program and you have selected the good COM PORT. Otherwise the code looks good. (You could also looks in the RxString value each time you are passing by. (maybe many empty space or "/r"))

[Serializable]
public class Customer
{
[XmlElement("FirstName")]
public string FirstName { get; set; }
[XmlElement("LastName")]
public string LastName { get; set; }
[XmlElement("Age")] public int Age { get; set; }
public bool ShouldSerializeLastName()
{
return Age > 18; // Enter here only if it is XmlSerialize.
}
}

Related

How to make two forms receive information from the serial port that receives information from Arduino?

I am developing a graphical interface that reads variables from different sensors that arrive through the serial port, so far I have managed to read all the variables with a single form but now I want to have two forms.
The first form asks the user to choose the COM and confirms whether the connection was successful or not. Once the connection is successful, the second form is opened where the variables from the sensors will be shown in "labels", the readings sent from Arduino are read by the serial port and stored in an array:
data[0], data[1], data[2] etc...
This is the first form where Serialport1 is found and the data arrives through the serialPort1_DataReceived event:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.Media;
namespace AUTOCLAVES_GUI
{
public partial class GUI_AUTOCLAVES_GENERADOR_DE_VAPOR : Form
{
/*VARIABLES GLOBALES*/
string puerto_seleccionado;
public GUI_AUTOCLAVES_GENERADOR_DE_VAPOR()
{
InitializeComponent();
string[] puertos = SerialPort.GetPortNames();
foreach (string mostrar in puertos)
{
comboBox1.Items.Add(mostrar);
}
}
private void Salir_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Minimizar_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private void Maximizar_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Maximized;
Maximizar.Visible = false;
Restaurar.Visible = true;
}
private void Restaurar_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Normal;
Restaurar.Visible = false;
Maximizar.Visible = true;
}
private void MenuSideBar_Click(object sender, EventArgs e)
{
if (Sidebar.Width == 270)
{
Sidebar.Visible = false;
Sidebar.Width = 68;
SidebarWrapper.Width = 90;
LineaSidebar.Width = 68;
AnimacionSidebar.Show(Sidebar);
}
else
{
Sidebar.Visible = false;
Sidebar.Width = 270;
SidebarWrapper.Width = 300;
LineaSidebar.Width = 268;
AnimacionSidebarBack.Show(Sidebar);
}
}
private void bunifuFlatButton8_Click(object sender, EventArgs e)
{
try
{
serialPort1.Close();
serialPort1.Dispose();
serialPort1.Open();
CheckForIllegalCrossThreadCalls = false;
label2.Text = "CONEXIÓN EXITOSA";
label2.ForeColor = Color.Green;
label2.Font = new Font(label2.Font, FontStyle.Bold);
openChildForm(new MUESTREO_EN_TIEMPO_REAL());
}
catch
{
label2.Text = "CONEXIÓN FALLIDA";
label2.ForeColor = Color.Red;
label2.Font = new Font(label2.Font, FontStyle.Bold);
MessageBox.Show("REVISE CONEXIÓN DE ARDUINO", "ADVERTENCIA", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
puerto_seleccionado = comboBox1.Text;
serialPort1.PortName = puerto_seleccionado;
}
private void bunifuFlatButton7_Click(object sender, EventArgs e)
{
comboBox1.Items.Clear();
label2.Text = "SIN CONEXIÓN";
label2.ForeColor = Color.White;
string[] puertos = SerialPort.GetPortNames();
foreach (string mostrar in puertos)
{
comboBox1.Items.Add(mostrar);
}
}
private Form activeForm = null;
private void openChildForm(Form childForm)
{
if (activeForm != null)
activeForm.Close();
activeForm = childForm;
childForm.TopLevel = false;
childForm.FormBorderStyle = FormBorderStyle.None;
childForm.Dock = DockStyle.Fill;
panel1.Controls.Add(childForm);
panel1.Tag = childForm;
childForm.BringToFront();
childForm.Show();
}
private void bunifuFlatButton2_Click(object sender, EventArgs e)
{
openChildForm(new MUESTREO_EN_TIEMPO_REAL());
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string[] data = serialPort1.ReadLine().Split(',');
if (data.Length > 10)
{
}
else
{
MessageBox.Show("Intente nuevamente", "ADVERTENCIA", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}
}
}
}
Here is my second form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AUTOCLAVES_GUI
{
public partial class MUESTREO_EN_TIEMPO_REAL : Form
{
public MUESTREO_EN_TIEMPO_REAL()
{
InitializeComponent();
}
private void MUESTREO_EN_TIEMPO_REAL_Load(object sender, EventArgs e)
{
}
private void Salir_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
I hope someone can help me overcome this problem.

Button can be enabled only if textbox AND datetimepicker is filled

[Edited Version based on replies]
I would like the button1 to be enabled only if both textbox and datetimepicker are filled. I am able to do for the text but not for datetimepicker. Here is my full code. FYI: my datetimepicker is being formatted to empty initially to allow user to choose a date himself.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Inspection
{
public partial class Vdetails : Form
{
public Vdetails()
{
InitializeComponent();
Vnew.Enabled = false;
}
//Allow user input date
private void DTafes_ValueChanged(object sender, EventArgs e)
{
DTafes.CustomFormat = #"";
}
private void DTfa_ValueChanged_1(object sender, EventArgs e)
{
DTfa.CustomFormat = #"";
}
private void DTfe_ValueChanged(object sender, EventArgs e)
{
DTfe.CustomFormat = #"";
}
//Condition to allow button to go next
private void ActivateButton()
{
Button1.Enabled = (Vehicle.Text != "" && Distance.Text != "");
}
private void Vehicle_TextChanged(object sender, EventArgs e)
{
ActivateButton();
}
private void Distance_TextChanged(object sender, EventArgs e)
{
ActivateButton();
}
}
What and how do I add the code to allow for datetimepicker to be filled. Hope that someone could help me.
The dateTimePicker has no textchanged-event. There will never be an empty string inside the dateTimePicker. (Maybe you can set it via code, but not by user-input) You can use the valueChanged-event of the dateTimePicker to do something when the date was changed by the user.
Since the text will never be empty, you dont have to check it in you ActiveButton-function.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void ActiveateButton()
{
this.button1.Enabled = textBox1.Text != string.Empty;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
ActiveateButton();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
ActiveateButton();
}
}
DateTimePicker is always got a value but you can listen to the ValueChanged event
private bool dateChanged;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
dateChanged = false;
button1.Enabled = false;
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
dateChanged = true;
SetEnabledness();
}
private void SetEnabledness()
{
button1.Enabled = !string.IsNullOrWhiteSpace(textBox1.Text) && dateChanged;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
SetEnabledness();
}
If you have more than one DateTimePicker you can use a HashSet instead of a bool (just make sure you wire up all the ValueChangedEvents to dp_ValueChanged e.g.
private HashSet<DateTimePicker> dateChanged = new HashSet<DateTimePicker>();
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
dateChanged.Clear();
button1.Enabled = false;
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker2.Format = DateTimePickerFormat.Custom;
dateTimePicker3.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = #" ";
dateTimePicker2.CustomFormat = #" ";
dateTimePicker3.CustomFormat = #" ";
}
private void dp_ValueChanged(object sender, EventArgs e)
{
var dp = (DateTimePicker) sender;
dp.Format = DateTimePickerFormat.Short;
dateChanged.Add(dp);
SetEnabledness();
}
private void SetEnabledness()
{
button1.Enabled = !string.IsNullOrWhiteSpace(textBox1.Text) && dateChanged.Count == 3;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
SetEnabledness();
}

C# Serial Port Communication Arduino

I have a project where I need to communicate with Arduino over the serial ports. The problem I face is that I cannot print continously the data I receive from the serial monitor on multiple lines on a richtextbox. When I press the button "Reveice" I do receive only one value and after this, pressing again the Receive button will overwrite the line.
I'm tring to fix this for few days, but it's my first time programming in c# so I'm asking for your help.
The code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace aplicatie_comanda_v1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
getAvilablePorts();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.Close();
progressBar1.Value = 0;
button3.Enabled = true;
button1.Enabled = false;
receive.Enabled = false;
richTextBox1.Clear();
}
private void label1_Click(object sender, EventArgs e)
{
}
void getAvilablePorts()
{
string[] ports = SerialPort.GetPortNames();
comboBox1.Items.AddRange(ports);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
try
{
if (comboBox1.Text == "" || comboBox2.Text == "" && serialPort1 != null && serialPort1.IsOpen)
{
richTextBox1.Text = "Select COM port and BAUD rate !";
serialPort1.Close();
}
else
{
string cmd = Convert.ToString(comboBox1.Text);
int baud = Convert.ToInt32(comboBox2.Text);
serialPort1.PortName = cmd;
serialPort1.BaudRate = baud;
serialPort1.DtrEnable = true;
serialPort1.RtsEnable = true;
serialPort1.Open();
progressBar1.Value = 100;
button1.Enabled = true;
button2.Enabled = true;
textBox1.Enabled = true;
button3.Enabled = false;
}
}
catch (UnauthorizedAccessException)
{
richTextBox1.Text = "Unauthorized !";
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string text = textBox1.Text;
serialPort1.Write(text);
}
private void receive_Click(object sender, EventArgs e)
{
try
{
richTextBox1.Text = serialPort1.ReadLine() + "\n";
}
catch (TimeoutException)
{
richTextBox1.Text = "Timeout !";
}
}
private void button4_Click(object sender, EventArgs e)
{
serialPort1.Write("w");
}
private void button5_Click(object sender, EventArgs e)
{
serialPort1.Write("s");
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
serialPort1.Write("a");
}
private void button7_Click(object sender, EventArgs e)
{
serialPort1.Write("d");
}
private void button12_Click(object sender, EventArgs e)
{
serialPort1.Write("b");
}
private void button13_Click(object sender, EventArgs e)
{
string cmd = Convert.ToString(trackBar1.Value);
serialPort1.Write(cmd);
}
private void button8_Click(object sender, EventArgs e)
{
serialPort1.Write("q");
}
private void button11_Click(object sender, EventArgs e)
{
serialPort1.Write("e");
}
private void button9_Click(object sender, EventArgs e)
{
serialPort1.Write("z");
}
private void button10_Click(object sender, EventArgs e)
{
serialPort1.Write("c");
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
while (serialPort1.IsOpen)
{
try
{
string date = serialPort1.ReadLine();
richTextBox1.Text = date + "\n";
}
catch (TimeoutException)
{
richTextBox1.Text = "Timeout !";
}
}
}
}
}
Print screen of the final app: http://i.imgur.com/5f8EOly.png
Thank you !
I haven't written any Serial applications in C# yet, but already did a few projects involving Java <-> Arduino communication.
My first guess would be that you overwrite the existing line with the received line.
richTextBox1.Text = serialPort1.ReadLine() + "\n";
instead you would want:
richTextBox1.Text += serialPort1.ReadLine() + "\n";
Also you should take a look at this article on MSDN:
https://msdn.microsoft.com/en-us/library/system.io.ports.serialport.datareceived(v=vs.110).aspx
This shows how you could use Events to continuously receive text from the Arduino.

"System.UnauthorizedAccessException" error when opening second serial port

i Need to open a second serialPort in my Visual C# program to read data from my arduino.
it already worked fine, but in the case you see below it does not work..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using CommandsPD4I;
namespace CSharpExample
{
public partial class CSharpExample : Form
{
public ComMotorCommands motor1;
public CSharpExample()
{
InitializeComponent();
motor1 = new ComMotorCommands();
motor1.SetSteps(Convert.ToInt32(numericSchritte.Value));
}
SerialPort arduino;
delegate void InvokeLB(string Data);
InvokeLB lbRecievedDelegate;
int xPos = 0;
private void StartBtn_Click(object sender, EventArgs e)
{
// Set comm settings for motor 1
motor1.SelectedPort = ComPortBox1.Text;
motor1.Baudrate = Convert.ToInt32(BaudrateBox1.Text);
// Set motor address
motor1.MotorAddresse = Convert.ToInt32(Motor1ID.Value);
// Set relative positioning mode
motor1.SetPositionType(1);
// Start travel profile
if (motor1.ErrorFlag)
{
StatusLabel1.Text = "Status 1: " + motor1.ErrorMessageString;
}
else
{
StatusLabel1.Text = "Status 1: OK";
}
}
private void StopBtn_Click(object sender, EventArgs e)
{
// Stop travel profile
motor1.StopTravelProfile();
}
private void timer1_Tick(object sender, EventArgs e)
{
lblPosition.Text = Convert.ToString(motor1.GetPosition());
lblStatus.Text = motor1.ErrorMessageString;
// this.chart1.Series["Kraft"].Points.AddXY(xPos, Convert.ToDouble(lblKraft.Text));
// xPos++;**strong text**
}
private void btnHoch_Click(object sender, EventArgs e)
{
motor1.SetDirection(0);
motor1.SetPositionType(1);
motor1.StartTravelProfile();
}
private void btnRunter_Click(object sender, EventArgs e)
{
motor1.SetDirection(1);
motor1.SetPositionType(1);
motor1.StartTravelProfile();
}
private void numericSchritte_ValueChanged(object sender, EventArgs e)
{
motor1.SetSteps(Convert.ToInt32(numericSchritte.Value));
}
private void numericGeschwindigkeit_ValueChanged(object sender, EventArgs e)
{
motor1.SetMaxFrequency(Convert.ToInt32(numericGeschwindigkeit.Value));
}
private void btnDiagramm_Click(object sender, EventArgs e)
{
if (timer1.Enabled)
{
timer1.Stop();
}
else
{
timer1.Start();
}
}
private void btnResetDiagramm_Click(object sender, EventArgs e)
{
this.chart1.Series["Kraft"].Points.Clear();
xPos = 0;
}
private void arduino_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string RecievedLine = " ";
while (RecievedLine != "")
{
RecievedLine = arduino.ReadLine();
lblKraft.Invoke(lbRecievedDelegate, new object[] { RecievedLine });
}
}
void Invokelabel1(string Data)
{
label1.Text = Data;
this.chart1.Series["Kraft"].Points.AddXY(xPos, Convert.ToDouble(lblKraft.Text));
xPos++;
}
private void btnArduino_Click(object sender, EventArgs e)
{
//Hier erstellen wir unseren Serialport und legen die Einstellungen fest
arduino = new SerialPort("COM7", 9600);
if (!arduino.IsOpen)
{
arduino.Open();
if (arduino.IsOpen)
{
lblArduino.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(200)))), ((int)(((byte)(0)))));
lblArduino.Text = "Verbunden mit " + arduino.PortName;
}
}
lbRecievedDelegate = new InvokeLB(Invokelabel1);
arduino.DataReceived += new SerialDataReceivedEventHandler(arduino_DataReceived); //DataRecieved Event abonnieren
}
}
}
When i leave out this:
motor1.SelectedPort = ComPortBox1.Text;
motor1.Baudrate = Convert.ToInt32(BaudrateBox1.Text);
then it works..
I hope you can help :)

Adding description to append text RFID serial in C#

I want to add texts / descriptions after the RFID reader has scanned some tags. I tried using the IF statements but it did nothing.
Its output are the tag numbers but the texts I wanted to add didnt show or display. Please help, thanks!
I want the output to be 00000919BEAE = Milk
Here's our code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
Dictionary<string, string> tags = new Dictionary<string, string>() {
{ "00000919BEAE", "Milk" } ,
{"0000092A1132", "Fruits"}};
public string RxString;
public Form1()
{
InitializeComponent();
}
private void buttonStart_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM15";
serialPort1.BaudRate = 9600;
serialPort1.Open();
if (serialPort1.IsOpen)
{
buttonStart.Enabled = false;
buttonStop.Enabled = true;
textBox1.ReadOnly = false;
}
}
private void buttonStop_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
buttonStart.Enabled = true;
buttonStop.Enabled = false;
textBox1.ReadOnly = true;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (serialPort1.IsOpen) serialPort1.Close();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// If the port is closed, don't try to send a character.
if(!serialPort1.IsOpen) return;
// If the port is Open, declare a char[] array with one element.
char[] buff = new char[1];
// Load element 0 with the key character.
buff[0] = e.KeyChar;
// Send the one character buffer.
serialPort1.Write(buff, 0, 1);
// Set the KeyPress event as handled so the character won't
// display locally. If you want it to display, omit the next line.
e.Handled = true;
}
private void DisplayText(object sender, EventArgs e)
{
textBox1.AppendText(RxString);
if (tags.ContainsKey(RxString))
{
Console.Write(tags[RxString]); // this will print Milk
}
}
private void serialPort1_DataReceived
(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
RxString = serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
}
}
Try making RxString and the value you are comparing it to both uppercase, like this:
if (RxString.ToUpper() == tagid1.ToUpper())
{
string milk = "Milk";
Console.Write(milk);
}
if (RxString.ToUpper() == tagid2.ToUpper())
{
string fruits = "Fruits";
Console.Write(fruits);
}
if (RxString.ToUpper() == tagid3.ToUpper())
{
string soda = "Soda";
Console.Write(soda);
}
if (RxString.ToUpper() == tagid4.ToUpper())
{
string meat = "Meat";
Console.Write(meat);
}
I want the output to be 000A1234D980 = Milk
but you have condition
if (RxString == tagid1)
{
string milk = "Milk";
Console.Write(milk);
}
tagid1 is equal to "00000919BEAE", so your condition will fail.
debug and see which value exactly you get for RxString you can find the answer why your condition fail
Update :
You can use Dictionary for this
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("00000919BEAE", "Milk");
tags.Add("0000092A1132", "Fruits");
in your DisplayText method you can check for RxString key exist in the tag dictionary and if exist you can print
if (tags.ContainsKey(RxString))
{
Console.Write(tags[RxString]); // this will print Milk
}
Sample code :
public partial class Form1 : Form
{
Dictionary<string, string> tags = new Dictionary<string, string>() {
{ "00000919BEAE", "Milk" } ,
{"0000092A1132", "Fruits"}};
public string RxString { get; set; }
public Form1()
{
InitializeComponent();
}
private void DisplayText(object sender, EventArgs e)
{
textBox1.AppendText(RxString);
if (tags.ContainsKey(RxString))
{
textBox1.AppendText(RxString + ":" + tags[RxString]);
}
}
}

Categories

Resources