Abdul Hayee
Member
- Joined
- Mar 31, 2020
- Messages
- 24
- Programming Experience
- Beginner
I want to use a serial port as a class. whenever user Click on Connect button , function will be call and Open the serial Port
whenever Disconnect button is pressed, function will be call and Close the serial Port.
Can you guide me where i am wrong?
Thanks
whenever Disconnect button is pressed, function will be call and Close the serial Port.
Can you guide me where i am wrong?
Main Program:
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 serial_testing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnConnect_Click(object sender, EventArgs e)
{
Port_Initializer();
}
private void btnDisconnect_Click(object sender, EventArgs e)
{
Port_Closer();
}
}
}
MyClass:
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace serial_testing
{
class MyClass
{
public SerialPort serialPort1 = null;
public void Port_Initializer()
{
serialPort1.PortName = "COM10";
serialPort1.BaudRate = 9600;
serialPort1.Open();
}
public void Port_Closer()
{
serialPort1.Close();
}
}
}
Thanks