资源简介
利用串口控件实现的16进制收发通讯程序:收到的数据以16进制显示,发送数据以16进制形式发送。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace HexCommPort
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender EventArgs e)
{
if (mycomm.IsOpen)
{
mycomm.Close();
}
mycomm.ReadTimeout = 32;
try
{
mycomm.Open();
button3.Text = “关闭串口1“;
}
catch
{
button3.Text = “打开串口1“;
MessageBox.Show(“没发现此串口或串口已经在使用“);
}
}
private byte[] getdata()
{
int len = tsend.Text.Length;
int j = 0;
byte []datat = new byte[len];
for(int i=0;i {
if((tsend.Text[i]<=‘9‘)&&(tsend.Text[i]>=‘0‘)&&(tsend.Text[i+1]>=‘0‘)&&(tsend.Text[i+1]<=‘9‘)&&(tsend.Text[i+2]<=‘ ‘))
{
datat[j] = (byte)((tsend.Text[i]-‘0‘)*16+(tsend.Text[i+1]-‘0‘));
j++;
}
}
byte[] datarev = new byte[j];
for(int k=0;k {
datarev[k] = datat[k];
}
return datarev;
}
private bool ishex(char x)
{
bool re = false;
if((x<=‘9‘)&&(x>=‘0‘))
{
re = true;
}
else if((x<=‘F‘)&&(x>=‘A‘))
{
re = true;
}
else if ((x <= ‘f‘) && (x >= ‘a‘))
{
re = true;
}
return re;
}
private byte[] GetByteData(string s)
{
byte[] data = new byte[s.Length / 2];
for (int i = 0; i < s.Length / 2; i++)
{
if (s[i * 2] <= ‘9‘)
{
data[i] = (byte)((s[i * 2] - ‘0‘) * 16);
}
else if (s[i * 2] <= ‘f‘ && s[i * 2] >= ‘a‘)
{
data[i] = (byte)((s[i * 2] - ‘a‘ + 10) * 16);
}
else if (s[i * 2] <= ‘F‘ && s[i * 2] >= ‘A‘)
{
data[i] = (byte)((s[i * 2] - ‘A‘ + 10) * 16);
}
if (s[i * 2 + 1] <= ‘9‘)
{
data[i] = (byte)(data[i] + (byte)((s[i * 2 + 1] - ‘0‘)));
}
else if (s[i * 2 + 1] <= ‘f‘ && s[i * 2 + 1] >= ‘a‘)
{
data[i] = (byte)(data[i] + (byte)((s[i * 2 + 1] - ‘a‘ + 10)));
}
else if (s[i * 2 + 1] <= ‘F‘ && s[i * 2 + 1] >= ‘A‘)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5612 2008-06-24 11:47 HexCommPort\HexCommPort\Properties\Resources.resx
文件 249 2008-06-24 11:47 HexCommPort\HexCommPort\Properties\Settings.settings
文件 1184 2008-06-24 11:47 HexCommPort\HexCommPort\Properties\AssemblyInfo.cs
文件 2876 2008-06-24 11:47 HexCommPort\HexCommPort\Properties\Resources.Designer.cs
文件 1094 2008-06-24 11:47 HexCommPort\HexCommPort\Properties\Settings.Designer.cs
文件 6820 2008-06-24 16:00 HexCommPort\HexCommPort\Form1.cs
文件 3229 2008-06-24 12:00 HexCommPort\HexCommPort\HexCommPort.csproj
文件 5632 2005-12-08 14:51 HexCommPort\HexCommPort\bin\Debug\HexCommPort.vshost.exe
文件 24576 2008-06-24 16:00 HexCommPort\HexCommPort\bin\Debug\HexCommPort.exe
文件 26112 2008-06-24 16:00 HexCommPort\HexCommPort\bin\Debug\HexCommPort.pdb
文件 180 2008-06-24 14:29 HexCommPort\HexCommPort\obj\Debug\HexCommPort.Form1.resources
文件 180 2008-06-24 12:00 HexCommPort\HexCommPort\obj\Debug\HexCommPort.Properties.Resources.resources
文件 24576 2008-06-24 16:00 HexCommPort\HexCommPort\obj\Debug\HexCommPort.exe
文件 842 2008-06-24 14:29 HexCommPort\HexCommPort\obj\Debug\HexCommPort.csproj.GenerateResource.Cache
文件 26112 2008-06-24 16:00 HexCommPort\HexCommPort\obj\Debug\HexCommPort.pdb
文件 296 2008-06-24 16:00 HexCommPort\HexCommPort\obj\HexCommPort.csproj.FileList.txt
文件 470 2008-06-24 11:47 HexCommPort\HexCommPort\Program.cs
文件 4747 2008-06-24 14:29 HexCommPort\HexCommPort\Form1.Designer.cs
文件 6008 2008-06-24 14:29 HexCommPort\HexCommPort\Form1.resx
文件 922 2008-06-24 11:47 HexCommPort\HexCommPort.sln
..A..H. 11776 2008-06-24 16:48 HexCommPort\HexCommPort.suo
目录 0 2008-06-24 11:47 HexCommPort\HexCommPort\obj\Debug\TempPE
目录 0 2008-06-24 14:01 HexCommPort\HexCommPort\obj\Debug\Refactor
目录 0 2008-06-24 11:47 HexCommPort\HexCommPort\bin\Debug
目录 0 2008-06-24 11:47 HexCommPort\HexCommPort\obj\Debug
目录 0 2008-06-24 11:47 HexCommPort\HexCommPort\Properties
目录 0 2008-06-24 11:47 HexCommPort\HexCommPort\bin
目录 0 2008-06-24 11:47 HexCommPort\HexCommPort\obj
目录 0 2008-06-24 11:47 HexCommPort\HexCommPort
目录 0 2008-06-24 11:47 HexCommPort
............此处省略3个文件信息
- 上一篇:C# TCP服务器,支持多个客服端连入
- 下一篇:asp.net实验报告
相关资源
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论