3 Replies Latest reply on Mar 9, 2020 5:48 AM by DheerajK_81

    C# API - issue with disconnection of dongle port

    D.Sd_3235936

      Hi,

       

      I am using the C# API given for the CySamart dongle to send some data to the device from my PC.

      Using example: CySmart API C# example

       

      I noticed that occasionally I can't connect to the dongle port.

      I get multiple errors from the API such as The port 'COM#' does not exist or port device does not exist. (In both cases, Windows show me that the port does exist and is not used by any process)

      I try to disconnect using : public CyApiErr CloseCommunicator(ICySmartDongleCommunicator communicator);

      and connect back, still does not work. The port is stuck.

       

      The only solution I came up with is to disconnect the dongle physically from the port and re-plug it back.

      Unfortunately, This is not a valid solution for my team.

       

      Is there another solution for that? Some sore of API flow that will acquire the port and make it work?

        • 1. Re: C# API - issue with disconnection of dongle port
          DheerajK_81

          Hello D.Sd_3235936,

           

          Can you please tell which API you used to obtain the COM port and received the error "Com# port doesn't exist"? From what I see in the API reference guide, you need to provide the COM port in the code and then call "CyDongleInfo (string comPortName, CySmartDongleType type)".

           

          Are you running the Notification or Scanner application examples or have you created your own custom application? If its the latter, please attach the project so that I can have a look.

           

          If you tried to debug, please let me know which line of code is throwing the error.

           

          Regards,

          Dheeraj

          • 2. Re: C# API - issue with disconnection of dongle port
            D.Sd_3235936

            Hi

            The code i am using:

             

            public bool ConnectDongle(string COMPort)

                    {

                        Dongle_ = new CyDongleInfo(COMPort, CyDongleInfo.CySmartDongleType.CY5677);

                        DongleManager_ = CySmartDongleMgr.GetInstance();

                        CyApiErr err = DongleManager_.TryGetCySmartDongleCommunicator(Dongle_, out Comm_);

                        if (err.IsOK)

                        {

                            Console.WriteLine("Dongle connect " + err.Message);

                            return true;

                        }

                        else

                        {

                            Console.WriteLine("Dongle connect err "+ err.Message);

                            DisconnectBleDevice();

                            DisconnectDongle();

                            return false;

                        }

                    }

             

            I will try to debug again later and provide more info.

            • 3. Re: C# API - issue with disconnection of dongle port
              DheerajK_81

              Are you saying that the function new CyDongleInfo(COMPort, CyDongleInfo.CySmartDongleType.CY5677) fails? Please attach your stack trace information when the failure occurs.

               

              Regards,

              Dheeraj