Exemplo n.º 1
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;
            }
        }
    }
Exemplo n.º 2
0
 void OnDestory()
 {
     if (serialPort != null)
     {
         serialPort.Close();
     }
 }
Exemplo n.º 3
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;
        }
    }