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 ComReader_Sharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
            InitComPort();
            // Send data out through the COM port
            com.Output = "Serial Terminal Initialized";
        }        private void InitComPort()
        {
            // Set the com port to be 1
            com.CommPort = 1;            // This port is already open, close it to reset it.
            if (com.PortOpen) com.PortOpen = false;
            // Trigger the OnComm event whenever data is received
            com.RThreshold = 1;            // Set the port to 9600 baud, no parity bit, 8 data bits, 1 stop bit (all standard)
            com.Settings = "9600,n,8,1";            // Force the DTR line high, used sometimes to hang up modems
            com.DTREnable = true;
            com.RTSEnable = true;
            // No handshaking is used
            com.Handshaking = MSCommLib.HandshakeConstants.comNone;            // Don't mess with byte arrays, only works with simple data (characters A-Z and numbers)
            com.InputMode = MSCommLib.InputModeConstants.comInputModeText;            // Use this line instead for byte array input, best for most communications
            //com.InputMode = MSCommLib.InputModeConstants.comInputModeText;            // Read the entire waiting data when com.Input is used
            com.InputLen = 0;            // Don't discard nulls, 0x00 is a useful byte
            com.NullDiscard = false;            // Attach the event handler
            com.OnComm += new System.EventHandler(this.OnComm);            // Open the com port
            com.PortOpen = true;
        }
        private void OnComm(object sender, EventArgs e)  //  MSCommLib OnComm Event Handler
        {
            // If data is waiting in the buffer, process it.
            // Note: This is using the string method for simple data, be sure
            //       to use byte arrays (described below) for more generic data.
            if (com.InBufferCount > 0) ProcessComData();
        }
        private void ProcessComData()
        {
            // Send incoming data to a Rich Text Box
            char input =Convert.ToChar ( com.Input);
            rtfTerminal.AppendText(input.ToString()  + "\n"); //rtfTerminal 是richTextBox
        }////////////////////////////////////////////
用来读取单片机程序的
现在读取来成数据不对
大家帮我验证一下再附上单片机端的代码吧
看看到底那块不对
#include <c8051f340.h>
#define uchar unsigned char
#define uint unsigned int
void PORT_Init (void)
{
   XBR0      = 0x01;        // Port I/O Crossbar Control 0                                  
   XBR1      = 0x40;           //Port I/O Crossbar Control 1         
   P0MDOUT   = 0x10;           //Port 0 Output Mode Configuration 输出模式配置         }void UART0_Init (void)
{
   SCON0    |= 0x10;               // Port I/O Crossbar Control 0                                             
   CKCON     = 0x01;               // Clock Control时钟控制
   TH1       = 0x64; //波特率为9600 // Timer/Counter 1 High 计时器一高位
   TL1       = TH1;              // Timer/Counter 1 Low     计时器一低位
   TMOD      = 0x20;             //  Timer/Counter Mode 时间计数模式
   TR1       = 1;                ///  Timer1 on/off control  启动time1
   TI0       = 1;                //Transmit interrupt flag  传输中断标示
}void delay(void)
{
uint i;
for(i=1000;i>0;i--);  }
void main()
{
   char g;
   PCA0MD    &= ~0x40;     //   PCA0 Mode 模式            
   OSCICN    |= 0x03;         // Internal Oscillator Control       内部振荡器控制 
   PORT_Init();         //端口初始化               
   UART0_Init(); //串口初始化
  g=9;
   while(1)
   {
       delay();
     SBUF0=g;//每次发送一个'9'
   }
}