C# API - issue with disconnection of dongle port

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
D_Sd_3235936
Level 4
Level 4
25 sign-ins 50 questions asked 25 replies posted

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?

0 Likes
3 Replies
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

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

0 Likes

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.

0 Likes

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

0 Likes