本文介绍了串口自动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想问一下,如何自动创建一个统一的串口?那里有任何样本源代码。谢谢
I want to asked, how to automatically create a serial port in unity? there any sample source code.Thanks
推荐答案
//unity code
using UnityEngine;
using System.Collections;
using System.IO.Ports;
public class serialControlBasic : MonoBehaviour {
SerialPort stream;
//valid bauds 1200,2400,4800,9600,14400,19200,38400,57600 and 115200
void Start () {
stream = new SerialPort("COM3", 9600); //change port to your needs
stream.Open(); //Open the Serial Stream.
}
// Update is called once per frame
void Update () {
}
}
一个小的Arduino测试代码会像
A small Arduino test code will something like
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.println(random(1,1000)); //Send Random number to computer
delay(10); //Delay between sends.
}
这篇关于串口自动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!