示例#1
0
        public void Test_CSerialPort_OpenPort()
        {
            SetupPort();

            Assert.IsTrue(hlPort.OpenPort());
            Assert.IsTrue(llPort.IsOpen);

            Clean();
        }
示例#2
0
 public void SetupPort()
 {
     llPort = new SerialPort();
     hlPort = new CSerialPort(llPort, highLevelDataHandler);
     while (hlPort.OpenPort("COM5") == false)
     {
     }
 }
示例#3
0
 private void button_OpenSP_Click_1(object sender, EventArgs e)
 {
     if (highLevelSerialPort.IsPortOpen())
     {
         if (highLevelSerialPort.ClosePort())
         {
             button_OpenSP.Text = "Disconnected";
         }
         else if (!highLevelSerialPort.IsPortOpen())
         {
             button_OpenSP.Text = "Disconnected";
         }
         else
         {
             MessageBox.Show("Cannot close port");
         }
     }
     else
     {
         string port = comboBox_Ports.Text;
         if (port == "")
         {
             MessageBox.Show("No port selected");
         }
         else
         {
             if (highLevelSerialPort.OpenPort(port))
             {
                 button_OpenSP.Text = "Connected";
                 byte[] DataOut = { DOLLAR_SIGN, CHAR_UPPER_S, CHAR_CR };
                 highLevelSerialPort.Write(DataOut);
             }
             else
             {
                 MessageBox.Show("Cannot open port");
             }
         }
     }
 }
示例#4
0
    /// <summary>
    /// Finds a printer using the specified serial connection.
    /// </summary>
    /// <returns>
    /// An enumerator for a coroutine.
    /// </returns>
    /// <param name='aSerialPort'>
    /// A serial port connection.
    /// </param>
    IEnumerator FindPrinter(ISerialPort aSerialPort)
    {
        m_foundPrinter = false;
        int timeout = kLoopTimeout;

        while (!aSerialPort.isConnected && timeout-- > 0)
        {
            string[] availablePorts = m_serialPort.AvailablePorts();
            Text.Log(@"Found {0} available port{1}.", availablePorts.Length,
                     Text.S(availablePorts.Length));

            foreach (string aPortPath in availablePorts)
            {
                Text.Log(@"Trying to open {0}", aPortPath);

                bool success = false;
                try {
                    success = aSerialPort.OpenPort(aPortPath, kBaudRate);
                    Text.Log("Opened {0} at {1}.", aPortPath, kBaudRate);
                }
                catch (System.Exception e) {
                    Text.Error(e);
                    continue;
                }

                if (success)
                {
                    // Unity reboots the Propeller on OSX but not on Windows.
                    yield return(StartCoroutine(ResetCoroutine()));

                    // We're in text mode upon startup, so try pinging.
                    aSerialPort.Write("ping ");
                    // Not blocking, so wait a bit.
                    yield return(new UnityEngine.WaitForSeconds(1.0f));                   //0.02f);

                    string response = "(null)";
                    int    numRead  = aSerialPort.Read(8, out response);
                    response = response.Trim();
                    Text.Log("Received {0} byte{1}: {2}", numRead, Text.S(numRead), response);

                    if (response.Contains("pong"))
                    {
                        yield return(StartCoroutine(CheckVersion(aSerialPort)));

                        m_foundPrinter = m_wasProgrammingSuccessful;
                        if (m_foundPrinter)
                        {
                            Text.Log("Connected to " + aPortPath);
                            aSerialPort.Write("data ");

                            m_threadsActive = true;
                            m_txThread      = new Thread(TransmitData);
                            m_txThread.Name = "Tx Thread";
                            m_txThread.Start();

                            m_rxThread      = new Thread(ReceiveData);
                            m_rxThread.Name = "Rx Thread";
                            m_rxThread.Start();

                            Dispatcher.Broadcast(kOnSerialConnectionEstablished);
                        }
                        yield break;
                    }
                    aSerialPort.Close();
                    yield return(null);
                }
            }
            yield return(new WaitForSeconds(1));
        }
        if (timeout <= 0)
        {
            Text.Log(@"Couldn't find printer.");
            enabled = false;
        }
    }
示例#5
0
 /*------------------------------------------------------------------------------------
 * Date : 2016.02.24
 * Author : HSLEE
 * Function : LSEPortOpen()
 * Description : Scanner LSE Controller Serial COM Port Open
 *               m_COM - Hardware Layer ISerialPort 생성
 *  ------------------------------------------------------------------------------------*/
 public int LSEPortOpen()
 {
     return(m_COM.OpenPort());
 }