http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 4104|回复: 3

[开发助手] 关于C#串口的问题

[复制链接]
发表于 2015-8-8 11:04:33 | 显示全部楼层 |阅读模式
1金钱
我才接触C#,做了单片机串口软件,在软件里可以发送数据但是 是能发送0-9;在发送两位数的时候 却只能发送个位,请哪位知道的仁兄,告知一二,不胜感激,程序源码: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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                serialPort1.BaudRate = 9600;
                serialPort1.Open();

            }
            catch
            {
                MessageBox.Show("串口打开失败");
                return;
            }



        }
        byte time = 0;

        private void button1_Click(object sender, EventArgs e)
        {
            time++;
            if(time>15)
                time =0;


            try
            {

                serialPort1.Write(time.ToString());// 数据 发送


            }
            catch
            {

                MessageBox.Show("出现错误");
            }
        }
        //char[] ty = new char[2];

        //int real;

        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
           // textBox2.Text = real.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}




1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2015-9-14 18:21:21 | 显示全部楼层
个人感觉,你的问题应该是出在这里
byte time = 0;
==》 int time =0;
修改成这样试试
回复

使用道具 举报

发表于 2015-9-14 18:22:15 | 显示全部楼层
byte time = 0; ==》int byte = 0;
修改成这样试试吧
回复

使用道具 举报

发表于 2015-9-14 18:24:32 | 显示全部楼层
byte time = 0; ==》 int time = 0;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-29 10:25

© 2014-2021

快速回复 返回顶部 返回列表