예제 #1
0
파일: SPP.cs 프로젝트: awas2/CoolScopeLoop
    void Start()
    {
        serialPort            = this.GetComponent <SerialPortUtility.SerialPortUtilityPro>();
        serialPort.OpenMethod = SerialPortUtility.SerialPortUtilityPro.OpenSystem.BluetoothSSP;
        Debug.Log("serialPort:" + serialPort);

        if (serialPort != null)
        {
            //Debug.Log("serial port is not null");
            serialPort.Open();

            /*if (serialPort.IsOpened())
             *          {
             *                  Debug.Log("writing");
             *                  serialPort.WriteCRLF("Open");
             *                  Debug.Log("wrote");
             *                  Debug.Log("serialPort:" + serialPort);
             *          }
             *          else
             *          {
             *                  Debug.Log("serial port is not opened");
             *          }*/
            //			Debug.Log("done");
        }
    }
예제 #2
0
파일: SPP.cs 프로젝트: awas2/CoolScopeLoop
 void Update()
 {
     if (!serialPort.IsOpened())
     {
         serialPort.Open();
         Debug.Log("serialport is opening");
     }
     if (Input.GetKeyDown("space") || Input.touchCount > 0)
     {
         Debug.Log("key was pressed");
         Debug.Log("writing");
         serialPort.WriteCRLF("unity");
         Debug.Log("wrote");
     }
 }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        if (serialPort != null)
        {
            if (Input.GetKeyDown(writeSimple))
            {
                //send
                serialPort.WriteCRLF("TestData");
            }
            if (Input.GetKeyDown(writeList))
            {
                List <string> dataArray = new List <string>();
                dataArray.Add("AAA");
                dataArray.Add("BBB");
                dataArray.Add("CCC");
                serialPort.Write(dataArray, ",", "<CR><LF>");
                //AAA,BBB,CCC<CR><LF>
            }
            if (Input.GetKeyDown(writeDictionary))
            {
                Dictionary <string, string> dataArray = new Dictionary <string, string>();
                dataArray.Add("AAA", "BBB");
                dataArray.Add("CCC", "DDD");
                serialPort.Write(dataArray, ",", "<CR><LF>");
                //AAA,BBB,CCC,DDD<CR><LF>
            }
            if (Input.GetKeyDown(writeBinary))
            {
                byte[] bin = new byte[6] {
                    0x00, 0x01, 0x02, 0x03, 0x04, 0xFF
                };
                serialPort.Write(bin);
            }

            //for Arduino micro leonardo
            if (Input.GetKeyDown(KeyCode.R))
            {
                serialPort.Close();

                int saveBaudRate = serialPort.BaudRate;
                serialPort.BaudRate = 1200;                     //Reset Command
                serialPort.Open();
                //Reset
                serialPort.Close();
                serialPort.BaudRate = saveBaudRate;
            }
        }
    }
예제 #4
0
    // Use this for initialization
    void Awake()
    {
        //Because processing of plugin carries out by start, it is necessary to generate by Awake.

        //serialPort = new SerialPortUtility.SerialPortUtilityPro(); //do not use
        serialPort = this.gameObject.AddComponent <SerialPortUtility.SerialPortUtilityPro>();

        //config
        serialPort.OpenMethod   = SerialPortUtility.SerialPortUtilityPro.OpenSystem.USB;
        serialPort.VendorID     = "";
        serialPort.ProductID    = "";
        serialPort.SerialNumber = "";
        serialPort.BaudRate     = 115200;       //115200kbps

        serialPort.ReadProtocol = SerialPortUtility.SerialPortUtilityPro.MethodSystem.Streaming;
        serialPort.ReadCompleteEventObject.AddListener(this.ReadComprateString);                //read function
        serialPort.RecvDiscardNull = true;

        serialPort.Open();
    }
예제 #5
0
    void Update()
    {
        if (httpreq == 2)
        {
            //request
            if (serialPort != null)
            {
                System.Threading.Thread.Sleep(10);
                serialPort.WriteCRLF("HTTP/1.1 200 OK");
                serialPort.WriteCRLF("Date: Mon, 04 Feb 2019 09:23:07 GMT");
                serialPort.WriteCRLF("Server: SerialPort Utility Pro");
                serialPort.WriteCRLF("Connection: close");
                serialPort.WriteCRLF("Content-Type: text/html");
                serialPort.WriteCRLF("");
                serialPort.WriteCRLF("<!DOCTYPE html><html><body>Serial Port Utility Pro</body></html>");
                serialPort.WriteCRLF("");

                System.Threading.Thread.Sleep(100);
                serialPort.Close();
                serialPort.Open();
            }
            httpreq = 0;
        }
    }