设为首页 加入收藏
首 页 企业简介 项目案例 软件定制 行业软件 解决方案 企业资讯 服务专区 客服中心
服务项目
案例展示 更多 >>
·维修管理系统 2012/5/14
·园区游客服务管理系统 2012/5/10
·党风廉政信息公开平台 2012/5/10
·职工提案系统软件 2012/1/11
·电信客户资源管理系统软… 2012/1/11
·洗衣收银软件 2012/1/11
·触摸查询系统软件 2012/1/11
·西安来电弹屏软件 2011/8/31
·西安软件公司仓库管理软… 2011/6/9
·会员管理系统 2011/6/9
联系人:李先生
电  话:029-87878512
手  机:13468700578
地  址:西安市欧亚大道丝路国际创意梦工厂4号楼
在线咨询:  762176615
Email:junsoft@126.com
 
当前的位置 >> 返回首页 >> 解决方案
西安软件公司开发串口
发布者:西安软件公司   发布时间:2018/8/20   阅读:10次

1.字符发送

1   string strSend = "00 01 02 03";
2   serialPort1.Write(strSend);

 

2.字符接收

1 ReadDataFromSerial Rdfs_str = new ReadDataFromSerial(DataShowMthod);
2 Serialdata = serialPort1.ReadExisting();
3 Invoke(Rdfs_str);

 

1 this.txtDataReceive.Text +=Serialdata;

3.ASCII发送

 
1   string strSend = "00 01 02 03";
2   string str = strSend.Replace(" ","");
3   int len = str.Length / 2;
4   byte[] ret = new byte[len];
5   for(int i=0;i<len;i++)
6         ret[i]=(byte)(Convert.ToInt32(str.Substring(i*2,2),16));
7   serialPort1.Write(ret,0,ret.Length);
 

 

4.ASCII接收

方法1:

1 ReadDataFromSerial Rdfs_hex = new ReadDataFromSerial(DataShowMethod);
2 Serialdata = serialPort1.ReadExisting();
3 Invoke(Rdfs_hex);

 

1 string str="";
2 byte[] bt = System.Text.Encoding.Default.GetBytes(Serialdata);
3 for (int i = 0; i < bt.Length; i++)
4     str += bt[i].ToString("X2");
5 this.txtDataReceive.Text += str;

 

方法2:

1 byte[] bt=new byte[SP.BytesToRead];
2 SP.Read(bt,0,bt.Length);
3 for(int i=0;i<bt.Length;i++)
4     Str += bt[i].ToString("X2");

 


网站首页 | 关于我们 | 售后服务 | 网站地图 | 查看留言 | 在线留言 | 客服中心
© 版权所有:西安润宇软件科技有限公司 
公司地址:西安市丝路国际创意梦工厂4号楼  联系电话:029-87878512 手机:13468700578 联系人:李先生
Copyright ® 2011-2020 Xbwbw.com Inc. All Rights Reserved 
技术支持:西安润宇软件科技有限公司  陕ICP备11000720号-2