2014年7月15日 星期二

Read RS232 Port

This Example can read All COMPort ,can using to read Arduino, STM32, TI.... Develop board!

RS232.cs

using UnityEngine;
using System.Collections;
using System.IO.Ports;
using System;

public class RS232 : MonoBehaviour {

 SerialPort sp = new SerialPort("COM2", 9600);

 // Use this for initialization
 void Start () {
//  sp = new SerialPort("COM10", 9600);
  sp.ReadTimeout=100;
  sp.Open();
 }
 
 // Update is called once per frame
 void Update () {
  try{
   print (sp.ReadLine());
  }catch(Exception e){};
 }
}

And Arduino source code
void setup(){
    Serial.begin(9600);
}

void loop(){
    Serial.println("Hello this is Arduino!");
}

* You need change to .NET 2.0 framework (in Project Setting)

Download Project:
 - GoogleDrive
 - Mega
 - Dropbox
 - OneDrive
 - Ideone
 - Magnet

沒有留言:

張貼留言

© ERIC RILEY , 自由無須告知轉貼
Background Japanese Sayagata by Olga Libby