Experience/Examples using Nordic nRF52840 (BLE) with C#? - c#

Does anyone have experience using the Nordic NRF52840 with a C# app to act as a receiver?
I'm trying to communicate with an Onset InTemp thermometer and although I've had quite a bit of success with the native Windows 10 BLE, I'm having some problems. See: C#, BLE. Why does GetGattServicesAsync hang forever? Is there a work around such as turning off/on BLE? for details.
Nordic advertises that they only have C++, Python and Node.js libraries. See https://devzone.nordicsemi.com/f/nordic-q-a/65516/using-nrf52840-dongle-as-receiver-client-for-onset-thermometer for example. I need either a C# library OR perhaps some hints on how to build the C++ library with Visual Studio (there are no instructions that I can see) and setup the interop layer (method signature etc.). I think this would go much faster if I saw an example :). And I'm guessing this type of work has been done before.
Another possibility is to call the Node.js libraries from C# which I understand is possible but again, I'd need some initial examples. Probably more so as I've never used Node.js either on its own or from C#.
Thanks, Dave

Related

Share data between C++ and C# or VB (2 running program)

is there a way (other than network(i hate io-streams)) to communicate between 2 process? one in c++ and other one in C# or VB.
my problem is, im writing a AVR program using c++, but for debugging purpose i need a GUI to test different inputs. since i donno anything about GUI in c++ ( and i have no plan to learn it), i want to write the GUI using .net and somehow connect it to my c++ code.
since i have 2 running process i cant use p/invoke and other similar methods. If i could share my variables between 2 process or call a function in c# from c++ (from running process to running process), that would solve my problem.
anything other than sockets?
Since you mentioned .NET you probably on MS Windows. You may use DDE (Dynamic Data Exchange):
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648774(v=vs.85).aspx
You can find .NET tutorial for it here:
http://blogs.artinsoft.net/Mrojas/archive/2009/06/10/DDE-in-NET.aspx
If you want fast dummy solution that will work for you just for debugging not as real solution. You may share your data by writing them to the hard disk and reading it from it again. It is not hard neither complicated.
What about databases? if you are using MS you can try MSSQL.
Its absolutely free for small databases i think :)

Best programming language to convert a C# system to cross platform application?

I have done a lot of research regarding this issue. but i am still confused in choosing the right programming language. I wanted to convert my system which is programmed using C# to a cross platform system. Even though c# is an cross platform language the mono project is not successful according to my research.
Please give me your suggestions to this problem? I believe c++ and java will be an ideal programming language but java doesn't provide good GUI and if i choose c++ i will get stucked when converting my dll to c++.
Please provide your suggestions. Thank you.
Since Java syntax is a lot like C# syntax it would be easier to convert the code to Java. And there are actually some nice GUI libraries for Java.
See which-gui-library-is-the-best-in-java (Deleted in the meantime but Swing and SWT were favoured there)
I don't know what you mean by a good GUI, but you could use SWT which gives native integration to file/Open dialog boxes etc, rather than using the Java ones.
Of course a lot depends on how cross paltform you need it to be. Some devices only support C.
"cross platform" is not a fixed term. For example: Using the Eclipse RCP you have SWT on board. Your code uses the RCP stuff and would be platform neutral. But the embedded SWT libs would require either per-platform installable packages or one big package containing the SWT libs for all supported platform. If this is OK for you, you could use Java+SWT+(anything else you want) and have nice GUIs.
There is NO truly cross-platform language or technique. Yes, Java and Python can provide some abstraction over a platform... But everything stuck if only you add ":" to your file-name.
I mean, creating a software that is truly runs on many platform is FAR more than only choosing between Java, C# and C++. If one developed such software, one would understand me...
There is NO problems with Mono if you consider Mono as a target platform from the beginning. The most problems with mono happens when something is already written in .NET without ever aimed to be run on Mono. In this case there could be problems. If you bare in mind Mono from the beginning it is still the excellent platform.
As something that wasn't suggested here yet, I could refer you using python with Glide as cross-platform solution of creating applications with GUI.
Or you can see the Vala GObject system. Which syntax is really C# alike.

Change default audio device on Windows 7

I want to be able to change the default audio output device on Windows 7 programatically using C# (and probably some underlying Win32 API calls, as well). I've already done my homework, and I've heard a lot of mixed comments from different sources, so I wanted to ask this question again to get a straight answer. Is this actually possible (through any means)? If so, how would I go about doing this?
And please do not suggest a solution with "AutoIt" or some other similar program... this is a C#/.NET-specific question.
A little up-to-date answer, which is compatible with Windows 10.
This program is able to do it in a beautiful manner (hotkey to switch between pre-selected devices) and is written on C# :
SoundSwitch on GitHub
Some reverse engineering should get you there (for my use this program was just perfect as it is).
It makes use of that library (same author) which is in C++ :
AudioEndpointLibrary on GitHub
So if you know C++ (which I don't enough), you might go further in the analysis of how it works. Or just use the library like SoundSwitch does.
Just in case anyone stumbles across this thread in the future... here's some C++ code that'll do it by calling some undocumented Win32 APIs. This can be compiled into an EXE and then called silently from a .NET application, so you could build a .NET program around this code.
http://web.archive.org/web/20190317012739/http://www.daveamenta.com/2011-05/programmatically-or-command-line-change-the-default-sound-playback-device-in-windows-7/

Windows Mobile development: C++ or C# -- which one is better? why?

While doing Windows Mobile development, which language should I use? C# or C++ or something else? Why one is better than others?
It depends what you're coding.
Making native calls to the OS are possible via P/Invoke from C#, but extensive use is probably easier via native C++. You'll also require C++ for using some hardware that has not been wrapped by the Compact Framework.
Most hardware (GPS, camera, etc.), is available via CF. If you're working with a Win Mobile 6.x device, you're probably better off with C#. In addition to hardware, Pocket Office's (POOM) object model is also available to C#, so you can integrate with it.
It's worth noting that most references to Windows Phone 7 refer to managed code and the possibility of Silverlight. With Silverlight in the mix, you'll have to code with C#.
Unless your app is high performance or is extremely miserly with memory, use C# or VB.NET.
Scott
It depends on task mainly.
c++ has following pros/cons:
Direct access to resources, faster programs
Can access very deep OS parts, not needed for high level applicaiton
harder to develop and requires to manage resources by developer
C#:
Runs under virtual machine (CLR), that's why is slower
Faster and easier application development
Rich build-in library
There is no right answer for this, becasue there is no one-size-fits-all "better" definition. If you know C++ and have a lot of C++ code assets already, C++ sure looks appealing. If you know c# and not C++, then C# sure looks appealing.
C++ applications load faster, but for many applications, that's not relevent. C# applications can certainly be written faster, but they also don't have determinism. I'd never even attempt a UI in C++ any longer, nor would I think about doing database access in C++. I wouldn't write a driver in C# though, or a shell extension.
Generally speaking, most solutions I've ever delivered were a mix of the two. C# has its strengths. It's fast to write, easier to debug and unit test, hard (though not impossible) to create leaks and for some operations (like data access or XML parsing) it's just easier.
C++ has its strengths too, like speed of execution (though C# can be made to go just as fast for many things), determinism and the ability to plug in to things that want native entry points.
So my answer? You need to know both, and likely write your solutiuon using both. The percentage of each you end up using depends on what your end goal is.
It depends.
At least present a specific use-case. And possibly use SO search? :)
C++ or C# to program mobile barcode device?
Edit:
Apparently others were faster to the draw, and gave more articulated answers. Nevertheless, I still recommend reading the above SO thread.
From my experience it is easier to start with c#, and if the api provided by the compact framework is enough for you then you are ok.
On the other hand if your project is somewhat complex, or if you want to do something that is not in the compact framework you may end needing to create a helper .dll in c++. Even in this case you maybe good doing your main program in c#, and programming helpers dll in c++.
If you go directly to program in c++ you may benefit from the fact that you have a raw performance better than c#, which is good if you are doing a game.
But you will also suffer more from the limitation of windows mobile OS. Like a maximum of 32MB per process, or that all .dll share the same address space.
So in the end it really depends on what are planning to do and the experience you have.

Calling C# code from Java?

Does anyone have a good solution for integrating some C# code into a java application?
The code is small, so I could re-write in java, but I would rather reuse the code if possible. Don't repeat yourself, etc.
Also, I know I can expose the C# as a web service or whatever, but it has some security/encryption stuff in there, so I would rather keep it tightly integrated if possible.
Edit: It's going to be on a server-based app, so "downloading" another runtime is irrelevant.
You would use the Java Native Interface to call your C# code compiled into a DLL.
If its a small amount of C#, it would be much easier to port it to Java. If its a lot, this might be a good way to do it.
Here is a highlevel overview of it:
http://en.wikipedia.org/wiki/Java_Native_Interface
Your other option would be to create a COM assembly from the C# code and use J-Interop to invoke it.
http://sourceforge.net/projects/j-interop/
I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.
If it's short, I think you're better off re-writing the code in java. Downloading one 50Mb runtime is bad enough.
There is an IL to Java Bytecode compiler GrassHopper which may be of use to you. I've never tried it though.
I'd look at rewriting your code in Java though
EDIT: Note that Grasshopper seems to be no longer available.
We used JNBridge for this, and it worked great. It handles Java->.NET and vice versa, all in-proc.
If you do not want to rewrite hadle it as an Inter-process communication and choose one of following:
Named pipes
Sockets
SOAP
I would rewrite it if it's not too much trouble.
The web service would work, but it seems like that would be a lot of overhead just to reuse a little code.
http://www.infoq.com/articles/in-process-java-net-integration suggests running CLR and JVM in the same process space and passing calls back and forth. It sounds very efficient. I'm going to give it a try and integrate it into Jace if it works well.
If it is a piece of code that is exposable as a command line utility, I just make the other host language use a system call to execute the utility.
If your C# app needs to call Java, compile a special Java main that takes appropriate command line args and returns text output.
It the oldest, simplest method.
You can call your c# classes (compiled in a dll) via a bridging library, various libraries are available, every one with his characteristics. JNBridge generate proxy classes that you can call to manage the code in java classes. JCOBridge let you load your c# classes and use it from java using the invoke mechanism, also javonet let you import java classes and call java code using the invoke mechanism. All the explored solutions are commercial solutions that let you call java code from .NET and vice-versa with graphical user interface integration and other amenities.
Links:
jnbridge java-.NET bridge Developer and Deployment license schema with 30 day free trial
jcobridge java-.NET bridge Developer and Deployment license schema with unlimited Trial
javonet java-.NET bridge Research and Professional license schema with 30-day unlimited Trial after sign-up

Categories

Resources