unity3d 串口通信

根据网上查阅的资料测试并修改的,各种资料各种坑,此处经过一天的修改测试

终于完善了串口通信,以下是代码,脚本直接挂在摄像机就可以了

还有一些bug,不过感觉勉强可以用

using UnityEngine;
using System.Collections;
using System.IO;
using System.IO.Ports;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Text;//16进制转换

public class ChuanK1 : MonoBehaviour
{

    public string portName = "COM1";
    public int baudRate = 9600;
    public Parity parity = Parity.None;
    public int dataBits = 8;
    public StopBits stopBits = StopBits.One;
    SerialPort sp = null;       //串口的通信类
    byte[] data = new byte[128];  //用户存储6位数据    
    Thread dataReceiveThread;

    string message = "BB";//发送
    string msg; //接收到的数据显示在Label
    string tishi;//提示串口是否打开

    string str1 = "";
    string str2 = "";
    List<string> liData = new List<string>();
    string st
  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值