/*
     * INPUT: Friendly name of COM port where dongle is located
     * OUTPUT: None
     *
     * SUMMARY: Checks for correct operational state,
     * gets COMX location from input, and attempts to
     * attach to the port
     *
     * ATTACH SUCCEED: update operational state, start processing scan results
     * ATTACH FAIL: state unchanged, prints error message to debug log
     *
     * RETURNS: NONE
     */
    public void attachPort(string friendlyName)
    {
        if (operatingState == ConnectionState.NONE || operatingState == ConnectionState.DETACHED)
        {
            StringBuilder comName = EnfluxUtils.parseFriendlyName(friendlyName);

            if (comName != null)
            {
                StringBuilder returnBuffer = new StringBuilder(EnfluxVRSuit.MESSAGESIZE);

                if (EnfluxVRSuit.attachSelectedPort(comName,
                                                    returnBuffer) < 1)
                {
                    operatingState = ConnectionState.ATTACHED;
                    scanUpdater.StartScanning();
                }
                else
                {
                    Debug.Log(returnBuffer);
                }
            }
        }
        else
        {
            Debug.Log("Unable to attach, program is in wrong state "
                      + Enum.GetName(typeof(ConnectionState), operatingState));
        }
    }
Exemple #2
0
 /**
  * parse friendly name to find COM port
  * pass COM port in to connect
  * */
 public void attachPort(string friendlyName)
 {
     if (operatingState == ConnectionState.NONE || operatingState == ConnectionState.DETACHED)
     {
         System.Text.RegularExpressions.Regex toComPort =
             new System.Text.RegularExpressions.Regex(@".? \((COM\d+)\)$");
         if (toComPort.IsMatch(friendlyName.ToString()))
         {
             StringBuilder comName = new StringBuilder()
                                     .Append(toComPort.Match(friendlyName.ToString()).Groups[1].Value);
             Debug.Log(comName);
             attachedPort = new AttachedPort();
             if (EnfluxVRSuit.attachSelectedPort(comName, attachedPort) < 1)
             {
                 operatingState = ConnectionState.ATTACHED;
                 scanUpdater.StartScanning();
             }
             else
             {
                 Debug.Log("Error while trying to attach to port: " + comName);
             }
         }
     }
     else
     {
         Debug.Log("Unable to attach, program is in wrong state "
                   + Enum.GetName(typeof(ConnectionState), operatingState));
     }
 }