Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Collections;
- using System.IO.Ports;
- public class Comunicacao : MonoBehaviour
- {
- public string mensagem;
- public static SerialPort sp = new SerialPort("COM3", 9600);
- void Awake()
- {
- sp.Open();
- }
- void Start()
- {
- OpenConnection();
- foreach (string str in SerialPort.GetPortNames())
- {
- Debug.Log(string.Format("Existing COM port: {0}", str));
- }
- }
- void OpenConnection()
- {
- if(sp != null)
- {
- if (sp.IsOpen)
- {
- print("Porta aberta");
- }
- else
- {
- print("Porta == null");
- }
- }
- }
- void OnApplicationQuit()
- {
- sp.Close();
- }
- // Update is called once per frame
- void Update()
- {
- Debug.Log(sp.ReadLine());
- mensagem = sp.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement