问题说明:
我在WinCE5环境里,使用vs2005(C#)编写串口Demo ,使用serialport控件,现在数据接收不行,查看资料后说需要适用委托,我按照例子更改后仍然不能接收,将接收这一段的代码贴出来,请大家指点!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO.Ports;
using System.Threading;
namespace DrawList
{
public partial class TestCOM : Form
{
//[DllImport("kernel32.dll", EntryPoint="CreateFile")]
if (serialPort1.DataBits == 7)
{
serialPort1.StopBits = System.IO.Ports.StopBits.Two;
}
if (serialPort1.DataBits == 8)
{
serialPort1.StopBits = System.IO.Ports.StopBits.One;
}
if (serialPort1.DataBits == 9)
{
serialPort1.StopBits = System.IO.Ports.StopBits.None;
}
if (comboBox2.Text == "Odd")
{
serialPort1.Parity = System.IO.Ports.Parity.Odd;
}
else if (comboBox2.Text == "Even")
{
serialPort1.Parity = System.IO.Ports.Parity.Even;
}
else if (comboBox2.Text == "None")
{
serialPort1.Parity = System.IO.Ports.Parity.None;
}
else if (comboBox2.Text == "")
{
serialPort1.Parity = System.IO.Ports.Parity.None;
}
interfaceUpdateHandle = new HandleInterfaceUpdateDelegate(AddText); //实例化委托对象
serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived);