WinCE5 C# serialport控件的 接收数据 有关问题
发布时间:2010-06-13 22:28:55 文章来源:www.iduyao.cn 采编人员:星星草
WinCE5 C# serialport控件的 接收数据 问题!
问题说明:
我在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")]
delegate void HandleInterfaceUpdateDelegate(string text); //委托
HandleInterfaceUpdateDelegate interfaceUpdateHandle;
public TestCOM()
{
InitializeComponent();
Set_SerialPort(0);
}
byte[] WriteBuf = new byte[255];
byte[] ReadBuf = new byte[255];
int TimeNum = 0;
private void button1_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = "";
String[] Sendstr = textBox2.Text.Split(' ');
int writelen = Sendstr.Length;
for (int i = 0; i < Sendstr.Length; i++)
{
WriteBuf[i] = Convert.ToByte(Sendstr[i], 16);
}
Set_SerialPort(0);
serialPort1.Open();
serialPort1.Write(WriteBuf, 0,writelen);
//serialPort1.WriteLine(textBox2.Text);
serialPort1.Close();
}
catch (Exception ex)
{
textBox1.Text = ex.Message.ToString();
}
}
void Set_SerialPort(int bl)
{
if (bl == 0)
{
//serialPort1.PortName = "COM" + textBox3.Text;
if (comboBox3.Text != "")
{
serialPort1.PortName = comboBox3.Text;
}
else
{
serialPort1.PortName = "COM3";
}
if (comboBox1.Text == "")
{
serialPort1.BaudRate = 9600;
}
else
{
serialPort1.BaudRate = Convert.ToInt32(comboBox1.Text);
}
serialPort1.DataBits = Convert.ToInt32(numericUpDown1.Value);
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")
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
管道的另一端上无任何进程
我写了一个程序,运行正常。
后来,用上了sqlite数据库,然后编译部署都正常,但在WINCE 6模拟器上不能自动运...
-
Power键点亮屏幕的问题
我在程序里面成队使用了:
PowerPolicyNotify(PPN_UNATTENDEDMODE,TRUE);
PowerPolicyNotify(PPN_UNATTEND...
-
求助一个问题:windowsmobile ipl读分区的问题
ipl通过 BP_ReadData读 ramimage 分区信息 读取的时候发现必须要偏移0xc800才能读正...
-
vs2005+DevEmul_SDK.msi后仍旧没有“armv4”选项
OS:win7
IDE:先前有装vs2010做winForm,后装了vs2005(完全安装)
装完后安装了DevEmu...
-
Win7 64位操作系统如何安装arm9开发板的usb下载驱动啊
按照教程操作,超级终端打开也连上了,但是系统貌似对SECBULK.sys SECBULK.inf...
-
嵌入式开发工具
谁用过 LAZARUS 开发过嵌入式系统 ?
------解决方案--------------------
Lazarus 做 PC 上的程序,做嵌入式可能...
-
请推荐几个wince游戏软件下载的地方
最近开始玩wince,请推荐几个好的地方,可以下载游戏,软件的.多谢拉!
------解决方案--------...
-
FAT32 与单片机
根目录下文件与目录项数从那里得
还有根目录的下一簇从哪得
不是说根目录也是一个文件吗 它的目录项在哪里
---...
-
谁可以推荐一个WinCE下的视频播放器,最好可以播放AVI、RMVB、MP3等格式,谢谢。
如题,
麻烦大家推荐一个WinCE5.0下的视频播放器,
-...
-
WinCE6的BinFS问题,100分求解
1、BinFS能不能做在IDE硬盘上?
2、要支持BinFS,bootloader要做甚?
3、BinFS能不能作为一个普通文件放到...