串口自动 [英] Serial Port Automatically
本文介绍了串口自动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想问一下,如何自动创建一个统一的串口?那里有任何样本源代码。谢谢
I want to asked, how to automatically create a serial port in unity? there any sample source code.Thanks
推荐答案
man the dropkick trolls为什么他们甚至懒得发帖,哦等他们试图搞笑..传说中的自己午餐盒。
无论如何,你的问题的答案一定会让你开始,你将需要将com3和波特率更改为你需要的任何端口和速度
Man the dropkick trolls why do they even bother to post, oh wait they are trying to be funny .. legends in their own lunchboxes.
Anyhow the answer to your question in unity this will get you started you will need to change the com3 and baud rate to whatever port and speed you need
//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.
}
这篇关于串口自动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文