How to setup Logitech's LED Illumination SDK with C# - c#

I am trying to setup the Logitech LED SDK in order to create a script that allows to change backlight of specific keys. However when I follow the instructions given in the documentation
I get the following ERROR: error CS0103: The name 'LogitechGSDK' does not exist in the current contex
I have created a short video that illustrates how I tried to set it up
If anyone knows what I'm doing wrong or can explain to me how I can setup SDK for a C# project it would be very much appreciated.
I have tried following the documentation given with the download I have linked to and looked for similar posts but I've only found one for Java
I am trying to run the following code which was given as an example in the documentation found here: logitechSDK
location: LED_SDK_9.00\LED\Samples\Logi_SetTargetZone_Sample_CS\Logi_SetTargetZone_Sample_CS

This error means that LogitechGSDK is not known in the context. You have probably not included correct references to the project or not included the LogitechGSDK.cs in your project.
If SDK contains some examples, start with them. Make sure that you can build and run simple example, then play with it and make your own.
EDIT:
You need to add namespace reference:
using LedCSharp;
add it on top of the Program.cs file.
The LogitechLedEnginesWrapper.dll (x86 or x64) should be coppied to the output directory (where the .exe file is created), not the project directory.
Check terminal commands:
dotnet build
and
dotnet run
Good luck!

Related

Using MySQL ANTLR4 grammar in C#, getting "The type or namespace name 'MySQLBaseLexer' could not be found"

I am trying to play around with the ANTLR4 grammars for MySQL to do some basic statement parsing. This is my first time using ANTLR. I created a blank C# console project in VS2017, installed the ANTLR4, ANTLR4.CodeGenerator and Antlr4.Runtime nuget packages as well as the ANTLR Language Support extension. I added in the MySQLLexer.g4, MySQLParser.g4 and the predefined.tokens file. When I try to build the solution I get the following error:
The type or namespace name 'MySQLBaseLexer' could not be found (are you missing a using directive or an assembly reference?"
I have been looking through the tutorials, SO, and other blogs that discuss using ANTLR4 on C# but nothing seems to resolve the errors. Could anyone point me in the right direction to get this working correctly?
Thanks!
I assume you are using the two grammar files located here. While those grammars may not contain C++ code, it requires the base class you mention which is C++ code, so you will need to port MySQLBaseLexer.cpp and auxiliary code to C#, which is found in the Git repo. The readme in the ANTLR4 grammar directory contains a few more details about this requirement.
Also, why don't you try using Visual Studio 2019, the official Java Antlr Tool 4.7.2 (which requires Java), and my Net Core template for generating an Antlr C# program? Everything is integrated into a build and run F5. Check out this and this. The C# tool is at least two years behind the official release of Antlr. Further, the *.tokens is a generated file.
I don't understand why people keep checking in Antlr-generated files into a repo. It should not be checked in and used, especially if you use my template. The .g4 files are your source. If you need an extension for editing Antlr grammars in VS, you might want to check out my AntlrVSIX extension.
I was interested on this topic once I saw this topic, but went on vacations recently and I could finish the sample.
Here is a sample:
https://github.com/hmadrigal/playground-dotnet/tree/master/MsDotNetCore.MySqlParser
I created where the grammar provided by workbench (https://github.com/mysql/mysql-workbench/tree/8.0/library/parsers/grammars) has been adapted to work on .NET Core (using .NET standard for portability)
I created this sample project, it is not meant for production, and I am not an ANTLR expert, but I love coding and parsers.
Take a look at README.md and https://github.com/hmadrigal/playground-dotnet/blob/master/MsDotNetCore.MySqlParser/MySqlParser.TerminalApp/MySqlParserTester.cs could be your bootstrap. If I ever get to write a blog post I'll share the notes in here.

How to start using Google API v3?

I downloaded and compiled the official Google's API for .Net successul removing some incompatible referenced projects (Mobile WP81 projects).
Now, I'm trying to getting started with my very first steps to use the API, I'm following the official examples of Youtube API, the big problem I have is that I can't reproduce the example because these Namespaces are missing ...so I can't import them:
Imports Google.Apis.Authentication
Imports Google.Apis.Authentication.OAuth2
Imports Google.Apis.Authentication.OAuth2.DotNetOpenAuth
Imports Google.Apis.Samples.Helper
Imports Google.Apis.Youtube.v3
Imports Google.Apis.Youtube.v3.Data
These are the assemblies that I have compiled and referenced in my project:
Google.Apis.Auth.dll
Google.Apis.Auth.PlatformServices.dll
Google.Apis.Core.dll
Google.Apis.dll
Google.Apis.PlatformServices.dll
Plus these external dependencies:
BouncyCastle.Crypto.dll
log4net.dll
Newtonsoft.Json.dll
Zlib.Portable.dll
What I'm missing?.
UPDATE
I think that exists two problems, the first is that seems the example is old because the Namespace Google.Apis.Authentication seems has changed to Google.Apis.Auth, however, I still can't find the equivalent Namespaces for these:
Google.Apis.Authentication.OAuth2.DotNetOpenAuth
Google.Apis.Samples.Helper
Google.Apis.Youtube.v3
Google.Apis.Youtube.v3.Data
And the second problem, seems that I need to download an additional Google's library/dependency to obtain the Youtube API then be able to see the Youtube Namespaces, I think so, but I don't know where to download.
Note: This solution has been tried and tested
First and foremost I myself did not go to Github to get the API's for .Net. One reason and usually has been a problem at least for me is because of trying to figure out dependencies and such. With that in mind I recommend using NuGet and use the Package Manager Console. The reason is simple, you do not have to worry about compiling source, reference issue's with other libraries, dependencies etc...
How Did I get It To Work?
Please follow these steps as not only getting the API to actually work, but I did find out that there are more issue's with the official example you provided above (not your fault). I believe its a change in the newer version, specifically the YouTubeService class. Haven't had much time knocking this one down or yet report it to them, but is an issue with awaitand ExecuteAsync... Anyway's let get to work.
Get a new C# project going at least 4.5; I did a C# form application. The one you referenced was console, but will still print out information in the Visual Studio Ouput Window. Save this project off and run it at least one time; creates the bin\debug directory that you need before using the Package Manager for NuGet.
Go to Tools --> NuGet Package Manager --> Package Manager Console.
Once loaded copy and paste: Install-Package Google.Apis.YouTube.v3 and then hit enter to download the package. You will see it download everything and should be good to go. You will notice a new file under your project: packages.config which is related to this package, do not remove it. Also here is the link to that NuGet, grab it HERE
At this point, just re-build and run your program. Everything should be great to go at this point.
This end's your actual Issue I have addressed
Now on to the issue's I came across using the provided (official) example.
First you need to get the client_secrets.json and you can do that through the Developer Console. Download the json file and put it in your bin\debug directory. You can worry about placing it elsewhere later...
In that example find the code below:
// Retrieve the contentDetails part of the channel resource for the authenticated user's channel.
var channelsListResponse = await channelsListRequest.ExecuteAsync();
You need to remove: await keyword and ExecuteAsync() to: Execute(). This is the problem I came across and it was a pain in the a$$. It would execute, but I never received a response back, never, never... That was until I removed the listed above and replaced them.
There is one more place you need to modify as well. Please see below...
// Retrieve the list of videos uploaded to the authenticated user's channel.
var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();
You need to do the same for this line as well as I said above. Once done, you should be able to run the application and get result's back.
I hope you find this useful and relieving as much as I did. Also as I mentioned, this isn't reported to Google yet about the ExecuteAsync issue. I hope someone reports this so it can be addressed and fixed.
Happy Coding!
Reference To Await

SharpMap -Gdal Raster Layer, The type initializer for 'SharpMap.Layers.GdalRasterLayer' threw an exception [duplicate]

I started to use gdal_csharp dll in my application and read a geotiff file. but it says:
The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.
it's my code
string fileName = #"/path to geotiff file";
OSGeo.GDAL.Dataset DS =
OSGeo.GDAL.Gdal.Open(fileName, OSGeo.GDAL.Access.GA_ReadOnly);
can anyone help?
Edit:
I have these dlls
This is the full error message:
It says that cannot load gdal_wrap. But when I'm going to add that dll to my application the below message is shown:
As an update to this there is now GDAL maintained by the SharpMap team as a nuget package here which is updated regularly. You'll need to install both the "GDAL.Native" and "GDAL" package for your project to use the GDAL library. Once installed via nuget, they'll automatically create a "GdalConfiguration.cs" that you call into to initialize the GDAL paths before starting. The only thing to note is the packages are setup to automatically copy their appropriate GDAL libraries to your output build directory. If you need to deploy the application you'll have to do a bit of extra effort.
To solve this one I downloaded the prebuilt libraries as described here and grabbed FWTools from here.
The unmanaged DLLs I used came from \install_dir\FWTools2.4.7\bin and the C# wrapper from \install_dir\FWTools2.4.7\csharp.
gdal14.dll, msvcp71.dll and msvcr71.dll came from here, which is mentioned in that first link.
The error you are receiving re gdal_wrap.dll is referring to one of its dependencies. I threw that DLL into depends and it found a lengthy list of dependent libraries. Note that this list is likely longer due to my use of the FWTools distribution - if you built your version from source it may look different, though the same principles apply.
To get the above code to work on my machine I had the following files in my output directory:
gdal14.dll
gdalconst_csharp.dll
gdalconst_wrap.dll
gdal_csharp.dll
gdal_fw.dll
gdal_wrap.dll
geos_fw.dll
geotiff_fw.dll
hdf5dll.dll
hdf_fw.dll
jpeg12_osgeo.dll
jpeg_osgeo.dll
libcurl.dll
libeay32.dll
libexpat.dll
libmysql.dll
libpq.dll
libtiff_fw.dll
lti_dsdk_dll.dll
mfhdf_fw.dll
msvcp71.dll
msvcr71.dll
NCScnet_fw.dll
NCSEcw_fw.dll
NCSUtil_fw.dll
netcdf.dll
ogdi_32b1.dll
proj.dll
sqlite3.dll
ssleay32.dll
szlibdll.dll
xerces-c_2_7.dll
zlib1.dll
zlib_osgeo.dll
Now these don't necessarily all have to live in the output directory - as long as they are on your path somewhere (e.g., \Windows\System32) you should be fine.
I know it's an old question, but I believe my answer might help someone.
I was able to successfully compile and run examples using c# gdal by doing the following:
Downloading GDAL sdk from http://www.gisinternals.com/ (64 bit in my case)
Executing the SDKShell.bat script to set the system environment paths, etc.
Creating a project in Visual Studio. And referencing all .net dlls (the ones that names end with _csharp.dll), located in \bin\gdal\csharp\ inside downloaded SDK
Setting platform target in Visual Studio project settings to x64 to get rid og bad image format exceptions. The last step wouldn't be necessary if I'd choosse 32bit version of SDK to work with.
I did not install fwtools at all. It seems like the last build of fw_tools is relatively old, and sdk is still maintained.
I know this is a reasonably old question now, but I found this in google after researching the same problem myself, so this means that for searches on this error this is still a very relevant page to update given it's still in the top 5 from the big G when the same problem is searched.
In my case it was the answers from "DeusExMachina25" and "Grzegorz SÅ‚awecki" that struck a chord.
I'm writing some software that makes use of the current builds of "sharp map" on NUGet (as of 24th of June 2016) and my software kept throwing the same gdal_wrap message as the OP originally reported, even though I'm using the GDAL package provided by the Sharpmap team.
I didn't realize that the NUGet installer for the package had installed a configuration class for me, but after reading through this thread and finding out that it does I went looking for it.
Sure enough I found the file 'GdalConfiguration.cs' in my project and added a call to it in an appropriate place in my project, expecting GDAL to be initialized correctly.
However, after I did this, I still had the same problem.
So, I set a break point on the beginning of the GDAL routine that had been added, and waited until the break point was hit.
I then traced through the method, and eventually found the following line:
var gdalPath = Path.Combine(executingDirectory, "gdal");
at around line 64 in the file.
Tracing through this, I noticed that the path being built was:
d:\geodata\maptest\maptest\bin\debug\gdal
but the NUGet installer had installed all the dependent assemblies in
d:\geodata\maptest\maptest\bin\debug
Exactly where I expected them to be.
I changed line 64 so that it now read:
var gdalPath = Path.Combine(executingDirectory, "");
and voila, the error went away and everything started to work.
I could have done things the other way too, and created a folder called gdal, then copied everything into that, but that then would have gotten deleted when I did a "clean" on the project.
Since the config class, set's up various environment variables based on this path, quickly changing that one line also fixes up the path for the GDAL data files , plugins and a few other things too.
You could try using Dependency Walker to see if there are any dlls that gdal_csharp is trying to grab but cannot.
Have you added the path to your GDAL libraries to your PATH environment variable? I downloaded my files from http://vbkto.dyndns.org/sdk/?_sm_au_=iVVqjsHS2n46WP00 and here's my path: C:\libs\release-1600-gdal-1-9-mapserver-6-2\bin.
To use the C#-bindings of GDAL you need an installation of FWTools (from http://fwtools.maptools.org/) as well as the most current binaries that match your system (from http://vbkto.dyndns.org/sdk/). Afterwards it is important to include the bin-directory of FWTools (example for 64bit-systems: C:\Program Files (x86)\FWTools2.4.7\bin) in your PATH variable as well as the necessary dlls (gdal_csharp.dll was mentioned in the question) in your Visual Studio project references. I outlined the complete processs here.
This process works on 32 bit as well as 64 bit systems, I tested it with VS 2010 and 2012.
Remove the path to python from the system variables. Because the main gdal paths conflict with python 27
Did you forget to:
GdalConfiguration.ConfigureGdal();
GdalConfiguration.ConfigureOgr();
Gdal.AllRegister();
Ogr.RegisterAll();
In my case the issue was:
I had 2 projects in my solution: ProjectA and ProjectB
I was executing ProjectA, and ProjectA was referencing ProjectB
ProjectB is the one that contained the references to both GDAL and GDAL.Native
ProjectA tried to find GDAL.Native's files under ProjectA\bin\Debug\netcoreapp3.1\gdal ... but in reality those files are under ProjectB\bin\Debug\netcoreapp3.1\gdal
Possible solutions:
Dirty solution: just copy the files from ProjectB under ProjectA\bin\Debug\netcoreapp3.1
Okayish solution: add the GDAL.Native package to each one of your "entry projects"
I don't like either of those solutions. This stuff happens under GdalConfiguration.cs, so maybe there is a way to modify it to find the correct path.

How do I use Clang from a C# project?

My goal is to use Clang within a C# program to parse C++ source code and build an AST.
If I understand correctly, I need to get libClang from somewhere as it is a C wrapper around Clang, and then I should be able to use the code in the following link to be able to use libClang from a C# project.
https://github.com/SimonRichards/clang-sharp
My problem is I am lost on how to install Clang. I have download the source from here:
https://github.com/FunkMonkey/libClang
and I tried running the makefiles through the visual studio command prompt but it just gives me an error:
Makefile(14) : fatal error U1034: syntax error : separator missing
Stop.
I'm quite confused as I'm not used to github and makefiles. I think the general process I need to follow is:
Install LLVM - where and what is this?
Install Clang - where is this?
Install libClang - how to run the makefiles?
Use SimonRichard's clang-sharp
I was unable to use the project listed here, however, I was able to get up and running using http://www.nuget.org/packages/ClangSharp
There are plenty of documentation how one can get started to use LLVM / Clang. And all this documentation is pretty explicitly mentioned on the websites:
http://llvm.org/docs/GettingStarted.html
http://llvm.org/docs/CMake.html
http://clang.llvm.org/get_started.html
And bunch of stuff around.

Exception while using GDAL in C#

I started to use gdal_csharp dll in my application and read a geotiff file. but it says:
The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.
it's my code
string fileName = #"/path to geotiff file";
OSGeo.GDAL.Dataset DS =
OSGeo.GDAL.Gdal.Open(fileName, OSGeo.GDAL.Access.GA_ReadOnly);
can anyone help?
Edit:
I have these dlls
This is the full error message:
It says that cannot load gdal_wrap. But when I'm going to add that dll to my application the below message is shown:
As an update to this there is now GDAL maintained by the SharpMap team as a nuget package here which is updated regularly. You'll need to install both the "GDAL.Native" and "GDAL" package for your project to use the GDAL library. Once installed via nuget, they'll automatically create a "GdalConfiguration.cs" that you call into to initialize the GDAL paths before starting. The only thing to note is the packages are setup to automatically copy their appropriate GDAL libraries to your output build directory. If you need to deploy the application you'll have to do a bit of extra effort.
To solve this one I downloaded the prebuilt libraries as described here and grabbed FWTools from here.
The unmanaged DLLs I used came from \install_dir\FWTools2.4.7\bin and the C# wrapper from \install_dir\FWTools2.4.7\csharp.
gdal14.dll, msvcp71.dll and msvcr71.dll came from here, which is mentioned in that first link.
The error you are receiving re gdal_wrap.dll is referring to one of its dependencies. I threw that DLL into depends and it found a lengthy list of dependent libraries. Note that this list is likely longer due to my use of the FWTools distribution - if you built your version from source it may look different, though the same principles apply.
To get the above code to work on my machine I had the following files in my output directory:
gdal14.dll
gdalconst_csharp.dll
gdalconst_wrap.dll
gdal_csharp.dll
gdal_fw.dll
gdal_wrap.dll
geos_fw.dll
geotiff_fw.dll
hdf5dll.dll
hdf_fw.dll
jpeg12_osgeo.dll
jpeg_osgeo.dll
libcurl.dll
libeay32.dll
libexpat.dll
libmysql.dll
libpq.dll
libtiff_fw.dll
lti_dsdk_dll.dll
mfhdf_fw.dll
msvcp71.dll
msvcr71.dll
NCScnet_fw.dll
NCSEcw_fw.dll
NCSUtil_fw.dll
netcdf.dll
ogdi_32b1.dll
proj.dll
sqlite3.dll
ssleay32.dll
szlibdll.dll
xerces-c_2_7.dll
zlib1.dll
zlib_osgeo.dll
Now these don't necessarily all have to live in the output directory - as long as they are on your path somewhere (e.g., \Windows\System32) you should be fine.
I know it's an old question, but I believe my answer might help someone.
I was able to successfully compile and run examples using c# gdal by doing the following:
Downloading GDAL sdk from http://www.gisinternals.com/ (64 bit in my case)
Executing the SDKShell.bat script to set the system environment paths, etc.
Creating a project in Visual Studio. And referencing all .net dlls (the ones that names end with _csharp.dll), located in \bin\gdal\csharp\ inside downloaded SDK
Setting platform target in Visual Studio project settings to x64 to get rid og bad image format exceptions. The last step wouldn't be necessary if I'd choosse 32bit version of SDK to work with.
I did not install fwtools at all. It seems like the last build of fw_tools is relatively old, and sdk is still maintained.
I know this is a reasonably old question now, but I found this in google after researching the same problem myself, so this means that for searches on this error this is still a very relevant page to update given it's still in the top 5 from the big G when the same problem is searched.
In my case it was the answers from "DeusExMachina25" and "Grzegorz SÅ‚awecki" that struck a chord.
I'm writing some software that makes use of the current builds of "sharp map" on NUGet (as of 24th of June 2016) and my software kept throwing the same gdal_wrap message as the OP originally reported, even though I'm using the GDAL package provided by the Sharpmap team.
I didn't realize that the NUGet installer for the package had installed a configuration class for me, but after reading through this thread and finding out that it does I went looking for it.
Sure enough I found the file 'GdalConfiguration.cs' in my project and added a call to it in an appropriate place in my project, expecting GDAL to be initialized correctly.
However, after I did this, I still had the same problem.
So, I set a break point on the beginning of the GDAL routine that had been added, and waited until the break point was hit.
I then traced through the method, and eventually found the following line:
var gdalPath = Path.Combine(executingDirectory, "gdal");
at around line 64 in the file.
Tracing through this, I noticed that the path being built was:
d:\geodata\maptest\maptest\bin\debug\gdal
but the NUGet installer had installed all the dependent assemblies in
d:\geodata\maptest\maptest\bin\debug
Exactly where I expected them to be.
I changed line 64 so that it now read:
var gdalPath = Path.Combine(executingDirectory, "");
and voila, the error went away and everything started to work.
I could have done things the other way too, and created a folder called gdal, then copied everything into that, but that then would have gotten deleted when I did a "clean" on the project.
Since the config class, set's up various environment variables based on this path, quickly changing that one line also fixes up the path for the GDAL data files , plugins and a few other things too.
You could try using Dependency Walker to see if there are any dlls that gdal_csharp is trying to grab but cannot.
Have you added the path to your GDAL libraries to your PATH environment variable? I downloaded my files from http://vbkto.dyndns.org/sdk/?_sm_au_=iVVqjsHS2n46WP00 and here's my path: C:\libs\release-1600-gdal-1-9-mapserver-6-2\bin.
To use the C#-bindings of GDAL you need an installation of FWTools (from http://fwtools.maptools.org/) as well as the most current binaries that match your system (from http://vbkto.dyndns.org/sdk/). Afterwards it is important to include the bin-directory of FWTools (example for 64bit-systems: C:\Program Files (x86)\FWTools2.4.7\bin) in your PATH variable as well as the necessary dlls (gdal_csharp.dll was mentioned in the question) in your Visual Studio project references. I outlined the complete processs here.
This process works on 32 bit as well as 64 bit systems, I tested it with VS 2010 and 2012.
Remove the path to python from the system variables. Because the main gdal paths conflict with python 27
Did you forget to:
GdalConfiguration.ConfigureGdal();
GdalConfiguration.ConfigureOgr();
Gdal.AllRegister();
Ogr.RegisterAll();
In my case the issue was:
I had 2 projects in my solution: ProjectA and ProjectB
I was executing ProjectA, and ProjectA was referencing ProjectB
ProjectB is the one that contained the references to both GDAL and GDAL.Native
ProjectA tried to find GDAL.Native's files under ProjectA\bin\Debug\netcoreapp3.1\gdal ... but in reality those files are under ProjectB\bin\Debug\netcoreapp3.1\gdal
Possible solutions:
Dirty solution: just copy the files from ProjectB under ProjectA\bin\Debug\netcoreapp3.1
Okayish solution: add the GDAL.Native package to each one of your "entry projects"
I don't like either of those solutions. This stuff happens under GdalConfiguration.cs, so maybe there is a way to modify it to find the correct path.

Categories