CySmart API C# example

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

cross mob
Anonymous
Not applicable

Wondering if there is a bare bones example in C# code using the CySmart API to setup and talk to the dongle ??

   

The reference guide does not provide one, and its not clear to me at least how to properly start things up, etc..

0 Likes
1 Solution
AnjanaM_61
Moderator
Moderator
Moderator
5 comments on KBA First comment on KBA 5 questions asked

Hi Artyom,

   

This was a bug in the dispose implementation of the API.

   

This is already fixed in CySmart 1.2 SP1 release. You  needs to replace the old DLLs with the new DLLs.

   

This release should be available on the web in WW14 (in another 2/3 weeks time) .

   

Thanks & Regards,
Anjana

View solution in original post

0 Likes
31 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

You can get the  complete code from Cypress if you open a case. There are  no barebone examples that I know of.

Anonymous
Not applicable

Thanks.. I'll give that a go..

0 Likes
Anonymous
Not applicable

Apparently Cypress does not share the C# sources to the CySmart app, nor do they provide any other example as an option to help get an API driven application off the ground... not the 'helpful response' we were expecting..  we've suggested signing an NDA to get a peek.. we'll see how that goes.. sigh.. 

   

Otherwise, their response to my case has been a bit disappointing:

   

"Thanks for contacting Cypress Technical support. Currently we don't have any example source code using Cymsart API."

   

And after a second inquiry about the CySmart code itself:

   

"The CySmart source code for windows tool is internal and cannot be shared. We provide CySmart API reference guide available at http://www.cypress.com/documentation/software-and-drivers/cysmart-bluetooth-le-test-and-debug-tool."
 

0 Likes
lock attach
Attachments are accessible only for community members.
GauravS_31
Moderator
Moderator
Moderator
10 questions asked 250 solutions authored 250 sign-ins

I have attached a sample code for using CySmart C# APIs. I hope this helps. Let me know if you have any questions or if you face any problems with the code.

Anonymous
Not applicable

grsr, Thank you very much for your samples!  I design electronics and develop embedded software/firmware.  I developed a Bluetooth instrument and needed to make a demo app but I don't know C#.  I was able to study and expand your samples.  Thanks!!!

0 Likes
Anonymous
Not applicable

Hi grsr,

   

Thank you very much for your samples!

   

It would be helpful if you can share what correct sequence should be done for reading data on  CySmart dongle (GATT client) that was sent from PSoC BLE (GATT server). Encapsulation using CySmart API WriteCharacteristic (CyGattWriteInfo info) working for me great, since CyGattWriteInfo(ushort handle, params byte[] value) has parameter "value" and I able to send notifications, once I need to receive I should use  ReadCharacteristic(CyGattReadInfo info), but CyGattReadInfo object has no value I can read? According to documentation this object holds the information necessary to read an attribute value, but were the value actually stored? 

0 Likes
GauravS_31
Moderator
Moderator
Moderator
10 questions asked 250 solutions authored 250 sign-ins

If the GATT Server is notifying data to GATT Client, then you should not use ReadCharacteristic(CyGattReadInfo info) API. The GATT client shall receive notification as a callback "OnCharacteristicChanged" under CyGattClientCallback. The class CyCharacteristicChangedInfo will encapsulate the Handle-Value pair of the notified data. The ReadCharacteristic API should be used to read data that is already written into the GATT database of the GATT Server.

0 Likes
Anonymous
Not applicable

Hi grsr, 

   

Thanks for your answer!

   

Unfortunately "OnCharacteristicChanged" callback is not fired in my case, but while I'm using CySmart 1.2 application I able to see GATT Server's message under 0x010 hanle. What can be a possible reason?

0 Likes
GauravS_31
Moderator
Moderator
Moderator
10 questions asked 250 solutions authored 250 sign-ins

You need to enable CCCD in CySmart C# code to receive notifications. If you are doing so, check if you have entered the correct attribute handle of the CCCD. Open CySmart 1.2 and check the attribute handle of the CCCD. It should equal the attribute handle of the characteristic to be notified + 1. Use this value in the C# code.

0 Likes
Anonymous
Not applicable

Hello GRSR,

   

Thank you for support!

   

I’m doing following sequence:

   

Step 1. override void OnCharacteristicChanged(CyCharacteristicChangedInfo info) and enabling public Action<CyCharacteristicChangedInfo> CharacteristicChangedHandler { get; set; }

   

under class GattClientCb : CyGattClientCallback

   

 

   

Step 2. Once m_gattClientCb initialized, I’m linking m_gattClientCb to CharacteristicChangedHandler (m_gattClientCb.CharacteristicChangedHandler = (info) => while here I’m using data GetPrintableValue(info.Value))

   


Step 3. In main function I’m creating
m_cyGattReadInfo = new CyGattReadInfo(0x0011); (0x0011 value taken from CySmart 1.2, I can see changes (received data) on 0x0010 handler, accourding to previous suggestion it should be equal to attribute handle of the characteristic to be notified + 1). And enabling m_peerDevice.GattClient.ReadCharacteristic(m_cyGattReadInfo);

   

 

   

Step 4. No notification is received and no OnCharacteristicChanged event fired in this case.

   

A’m I missing something?

   

Please advice.

0 Likes

Thanks a lot!
 

   

@cypress why this type of example are not available ?

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello,

   

I'm trying to reuse notification example. for one of my requirement.

   

Currently without any modifications introduced, i'm connecting USB dongle with a bluetooth device. and enabling notification on one particular characteristic like temperature mode. but when ever i change temperature mode i don't get the notification.

   

I have attached the screen capture of the cySmart App for the device. the selected characteristic is for temp mode. 00 - C and 01 is F.

   

when i change the value in cySmart App it get reflected in the Device. Now when i use the Notification Logger example and set notification for temperature mode characteristic and change the mode in device i don't get any notifications.

   

Can you help me to resolve this issue.

0 Likes

Hi,

I'm trying to run this code example but It says that the cysmart dongle is not valid, I have changed the COM port but it don't work can you help me ?( I'm a beginner, so I'm sorry if my question is stupid )

0 Likes

This thread is 3 years old. I strongly suggest you to open a new thread providing all information we need as Workspace archive, donge part number, error description.

Bob

0 Likes
Anonymous
Not applicable

Hi GRSR, 

   

ı will use your example code. this code read a data from psoc. I need send a data from computer to psoc. How can I do this ? 

0 Likes
GauravS_31
Moderator
Moderator
Moderator
10 questions asked 250 solutions authored 250 sign-ins

If your question implies sending data from CySmart dongle (GATT client) to PSoC BLE (GATT server) then first the GATT client should discover attributes on the GATT server after establishing connection. Then you need to use the CySmart API WriteCharacteristic (CyGattWriteInfo info). The class CyGattWriteInfo will encapsulate the data you need to send. Try implementing the CySmart APIs for attribute discovery and characteristic read or write and let me know if you face any difficulties. The CySmart API reference guide is available at the link mentioned in post#4. Attach the project code if necessary.

0 Likes
Anonymous
Not applicable

Hi grsr, 

   

 

   

Thank you about this code it's very helpful to me. I'm trying actually to make my own but I'm facing to a problem.

   

I want to use the ReadCharacteristic(CyGattReadInfo info) method to read a characteristic value but I'm unable to read it.

   

Can you help me ?

   

I called it with the parameter : "CyGattReadInfo GattInfo = new CyGattReadInfo(0x001E);" but when I call "err = GattClient.ReadCharacteristic(GattInfo);" it's an unknow name for visual studio. To read this data I made the callback but my problem is about to launch the read operation. I guess the problem is coming from my way to declare "ICyGattClient GattClient;" but I don't see how to manage with this object.

   

Thank you.

   

Best regards,

   

Guillaume

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi,

   

I am attaching another simple code example. This is a simple GUI that demosntrates scanning, connection, Write, Read and receiving notification.

   

You can download the project from this link:

   

https://www.dropbox.com/s/w5v7oje0ssuz2ix/MADY-40.zip?dl=0

   

Also, document for testing the project is attached here.

   

Regards,

   

- Madhu Sudhan

0 Likes
Anonymous
Not applicable

Thank you very much about this help. I'm starting with this language and I was a bit confused, it will really help and others I guess.

   

 

   

Best regards,

   

Guillaume.

0 Likes
Anonymous
Not applicable

Hi Madhu,

   

Can you explain a little bit the meaning for this function in C#

   

ScanCallBack.ScanStatusChangedHandler = status => { };

   

and

   

ScanCallBack.ScanResultHandler = status => { };

   

I found that after execute those command then the Handlers will be not " NULL"

   

*I'm not good at C# and now I'm trying to call the Cysmart API y LabVIEW.

   

Regards,

   

Uthai T.

0 Likes

Hello Madhu,

  Thanks for providing the example, Could you please tell me which characteristic is targeted for READ and WRITE buttons on the Form?

I thought it requires the Characteristic UUID is required for read/write operation, but your example is using CCCD info, how to get a CCCD info for any characteristic, Please clarify this. 

Thanks,

Naga.

0 Likes

Has anyone successfully paired with a device that is configured with unauthenticated paring with encryption? I'm using code that was posted earlier in this thread. I try to pair with the following line:

err = m_peerDevice.Pair(new CyPairSettings(CySecurityLevel.UNAUTHENTICATED_PAIRING_WITH_ENCRYPTION, false, 16, CyPairingProperties.USE_MITM));

err indicates successful. I've tried changing bonding to true and CyPairingProperities, but nothing seems to work. The OnPairingComplete event is called with a status of BLE_ERROR_GAP_AUTH_PASSKEY_ENTRY_FAILED.

Any ideas?

0 Likes
Anonymous
Not applicable

Is there anybody from Cypress team who can advice what the correct way of object release while using CySmart dongle. According to API and examples there is two functions for device connection:
1. Dongle connection: dongleMgr.TryGetCySmartDongleCommunicator(info, out m_communicator);

   

2. External device connection: BleMgr.Connect(new CyConnectInfo(deviceAddr, new CyBleConnectionSettings()));

   

And two functions for device disconnection:

   

3. Disconnect from external device first: BleMgr.Disconnect(m_peerDevice);

   

​4. Disconnect dongle instance: CySmartDongleMgr.GetInstance().CloseCommunicator(m_communicator);

   

I wrote simple application that nothing do besides connect to two different devices following 1-4 process. in a while(true) loop. Unfortunately I have memory leak there, I'm sure dll cannot do that, so probably I'm releasing resources in a wrong way, but I cannot find nothing in API or classes (CySmartDongleMgr, ICyBleMgr) that reminds me the other way (except to CySmartDongleMgr::CloseCommunicator and  ICyBleMgr::Disconnect)

   

Please advice.

0 Likes
AnjanaM_61
Moderator
Moderator
Moderator
5 comments on KBA First comment on KBA 5 questions asked

Hi Artyom,

   

This was a bug in the dispose implementation of the API.

   

This is already fixed in CySmart 1.2 SP1 release. You  needs to replace the old DLLs with the new DLLs.

   

This release should be available on the web in WW14 (in another 2/3 weeks time) .

   

Thanks & Regards,
Anjana

0 Likes
Anonymous
Not applicable

Hi Anjana,

   

Could you please point on updated .dll location, unfortunately I cannot find it undercy5677-cysmart-bluetooth-low-energy-ble-42-usb-dongle folder or other place..

   

 

   

Best regards,

   

Artyom

0 Likes

Hi Anjana,

   

I am aslo facing same issue as Artyom mentioned "while closing communicator I am getting error  says Unhandled Exception: System.ObjectDisposedException: Safe handle has been closed ". I have tried new DLLs from CySmart 1.2 SP1 release as you mentioned that

   

"This was a bug in the dispose implementation of the API.

   

This is already fixed in CySmart 1.2 SP1 release."

   

but still I am getting same error. Please provide any solution if it is possible.

0 Likes
Anonymous
Not applicable

Hello,

   

I´m using the dongle to access to cypress APIs and develop my GUI. In this respect, I would like have your support in the following questions:

   

1) Is there an event and/or callback from cypress APIs to detect when the BLE device, to which I was already connected, suddenly no more available is, (for instance due to  power supply failure), so that my GUI doesn´t crash or get blocked?

   

2) Is it possible to access to cypress APIs by using another Bluetooth USB (for instance, ASUS Bluetooth USB Sticks), rather than using  the CySmart BLE Dongle?

   

Very appreciated for your help

   

Nuno Alves

0 Likes
Anonymous
Not applicable

Hello nuno.antunes_2058241,

   

 

   

A mounth passed since your question but I now have the same question, did you solved it please ?

   

 

   

Regards,

   

Guillaume

0 Likes
Anonymous
Not applicable

Timeouts are your friend in the case of unknown disconnections and preventing blocks/crashes.

   

I don't know what is available specifically for the cysmart library, but I would suspect that you can check return values and events that refer to connections/timeouts/connected-operation functions to see what is going on.

0 Likes
Anonymous
Not applicable

Okey e.pratt, thank you about your answer, will be usefull to me as usual, keep that !

   

 

   

Best regards,

   

John

0 Likes
Anonymous
Not applicable

Hi

I am really struggling with the CySmart API. I tried a simple connection to a Device. But all I get is a time-out (BLE_ERROR_TOOL_REQUEST_TIMEDOUT).

This is what I do (I removed the error handling from the code, because this works):

CySmartDongleMgr dongleMgr = CySmartDongleMgr.GetInstance();

CyApiErr err = dongleMgr.TryGetCySmartDongleCommunicator(new CyDongleInfo(COM_PORT_NAME, CyDongleInfo.CySmartDongleType.CY5670), out m_communicator);

m_bleMgrCb = new BleMgrCb();

AutoResetEvent sync = new AutoResetEvent(false);

m_bleMgrCb.ConnectionHandler = (result, status) =>

{

  if (status == CyStatus.BLE_STATUS_OK)

  {

    ...

  }

  else

  {

    ...

  }

  sync.Set();

};

err = BleMgr.Connect(new CyConnectInfo(deviceAddr, new CyBleConnectionSettings()));

Any idea what I am doing wrong? The connection handler is only called when there is a time out.

Thanks in advance

0 Likes