namespace SerialCounter { public partial class frmSerialCNT : Form { SerialPort Rs232 = new SerialPort(); public frmSerialCNT() { InitializeComponent(); } private void frmSerialCNT_Load(object sender, EventArgs e) { Rs232.PortName = "COM2"; Rs232.BaudRate = 9600; Rs232.DataBits = 8; Rs232.Parity = 0; Rs232.Open(); } private void btnCounter_Click(object sender, EventArgs e) { int i; string str; for (i = 0; i < 256; i++) { Rs232.Write(""+Convert.ToChar(i)); } Thread.Sleep(200); str=Rs232.ReadExisting(); MessageBox.Show(str.Substring(100,50)); } } } Thanks
|