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
沒有留言:
張貼留言