Nếu đây là lần đầu tiên đến với Điện Tử Việt Nam, bạn có thể đọc phần Hỏi đáp bằng cách nhấn vào liên kết. Có thể bạn cần đăng kí trước khi có thể gửi bài . Để bắt đầu xem bài viết, chọn diễn đàn bạn muốn thăm dưới đây.
Các bác ạ,em nhận được bài tập lập trình C# nhận dữ liệu từ cổng COM của máy tính hiển thị trên màn hình máy tính mà hiện h em chả biết j cả .Bác nào biết giúp đỡ em với
Tìm đi trên box này có nhiều mà... cái đó tui cũng đang tính làm.. cũng đang tìm tài liệu ... nhưng mà cũng chưa bik sao ... không biết khả năng thế nào nữa.
PC COM ports, USB virtual COM ports, and ports in embedded systems are all addressed in this updated guide to programming, interfacing, and using serial ports. Topics include using .NET’s SerialPort class for COM-port communications on PCs; upgrading existing RS-232 designs to USB or wireless networks; and creating serial networks of embedded systems and PCs. Example circuits and code provide a quick start to projects. Installation and maintenance staff will also find tips for ensuring reliable operation and problem tracking.
Cũng giống như VB thôi.Đây là đoạn chương trình giao tiếp cổng COM truyền nhận dữ liệu bằng C#:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Send_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen == true) serialPort1.Close();
//phần cài đặt này có thể chỉnh được trong Proberty của serialPort
serialPort1.PortName = "COM1";
serialPort1.BaudRate = 9600;
serialPort1.DataBits = 8;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.Open();
//write data ra port nối tiếp
serialPort1.Write(textBox1.Text);
//close the port
//serialPort1.Close();
}
private void Receive_Click(object sender, EventArgs e)
{
//read data từ port nối tiếp
char[] bodem= new char[10];
//đọc tất cả byte trong the stream và the input buffer
textBox2.Text = serialPort1.ReadExisting();
}
}
Hope this's helpful!
Có ai làm nhận dữ liệu qua sự kiện Receive không ? Mình làm bị lỗi "cross..." Liên quan đến "thớt", "mâm" không hiểu lắm nên phải chơi Timer hỗ trợ. Có ai có cách gì giải quyết không
Comment