Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.IO.Ports;
- using System.Threading;
- public class Sending : MonoBehaviour{
- //public static SerialPort sp = new SerialPort("COM4",9600,Parity.
- public SerialPort sp = new SerialPort("----------);
- public string message2;
- float timePassed = 0.0f;
- //Use this for initialization
- void Start()
- {
- OpenConnection();
- }
- //Update is called once per frame
- void Update(){
- //timePassed+= Time.deltaTime;
- //if(timePassed)=0.2f){
- //print("BytesToRead" +sp.BytesToRead);
- message2 = sp.ReadLine ();
- print (message2);
- ///timePassed = 0.0f;
- //}
- }
- public void OpenConnection()
- {
- if(sp != null)
- {
- if (sp.IsOpen) {
- sp.Close ();
- print ("Closing port, because it was already open!");
- } else {
- sp.Open ();//open the connection
- sp.ReadTimeout = 16;
- print ("Port Opened!");
- //message = "Port Opened";
- }
- }
- else
- {
- if (sp.IsOpen)
- {
- print ("Port is already open");
- }
- else
- {
- print ("Port == null");
- }
- }
- }
- void OnApplicationQuit()
- {
- sp.Close();
- }
- public void sendStop(){
- sp.Write ("s");
- }
- public void sendForward(){
- sp.Write("f");
- }
- public void sendBack(){
- sp.Write("b");
- }
- public void sendRight(){
- sp.Write("r");
- }
- public void sendLeft(){
- sp.Write("l");
- }
- }
- using UnityEngine;
- using System.Collections;
- public class CallForward: MonoBehaviour {
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- }
- void OnMouseDown(){
- print ("Clicked");
- Sending.sendForward();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement