View Single Post
Old 23-04-2010, 05:05 AM   #1
chymnon
Nhập môn đệ tử
 
Tham gia ngày: Mar 2009
Bài gửi: 7
:
[HELP] Chuyển dữ liệu qua RS232

Em dùng phần mềm tạo cổng COM ảo và mô phỏng trên Proteus như file đính kèm.
Sau đây là code C# của em:
Trích:

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 testCOM
{
public partial class MainForm : Form
{
SerialPort serialPort = new SerialPort("COM4", 9600, Parity.None, 8);
byte[] data;
public MainForm()
{
InitializeComponent();
serialPort.Open();

}

private void btSend_Click(object sender, EventArgs e)
{
serialPort.Write(txtSendingText.Text);

}

private void btExit_Click(object sender, EventArgs e)
{
Close();
}
}
}
Dạ xin hỏi là vì sao trên màn hình Virtual Terminal nó lại hiện ra các ký tự kia khi em send số 1? Có phải là do hàm "Write" chuyển dữ liệu ra COM là chuyển string nên bị lỗi? Và cách giải quyết như thế nào? Em xin cảm ơn
Hình Kèm Theo
File Type: jpg error.jpg (57.1 KB, 14 lần tải)
chymnon vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn