est3
Posts: 12
Joined: Fri Oct 11, 2019 6:28 am

programming with c#

Fri Oct 11, 2019 6:48 am

hi
i want to build a program to raspberry zero, with raspebian, but i know only c#... i can learn python if there is no other way, but i not wanna do that because it take me a lot of time, and i don't have time...
so, there is a way that i can program with c#?
the performance is very importent to me, beacause i need to read data from some (40+-) yk-04 mudels, by shift register, and the program working with time too, so i need something that work good.

User avatar
scruss
Posts: 2582
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: programming with c#

Fri Oct 11, 2019 9:10 am

You can install a Mono (= portable .Net) development system with:

Code: Select all

sudo aptinstall mono-complete
but whether there's a good and useful GPIO library for it, I don't know.

If the YK-04s you mention are those simple 4 Channel RF Remote Control Module with four buttons, you may hit some problems. I've used these before, and they've got no security or channel functions. Press 1 on one remote, and all of your receivers will register 1. I suspect this is not what you'd want. If it is what you want, you won't need a shift register: one receiver and 4 GPIO ports will read all of your remotes, but can't tell which one was pressed.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

jahboater
Posts: 4785
Joined: Wed Feb 04, 2015 6:38 pm

Re: programming with c#

Fri Oct 11, 2019 9:44 am

Did you know that C++ is included as standard with Raspian?
There's no need to use Python or install mono etc.
C++ will be very very fast and has great support for the GPIO.

User avatar
B.Goode
Posts: 8915
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: programming with c#

Fri Oct 11, 2019 10:34 am

jahboater wrote:
Fri Oct 11, 2019 9:44 am
Did you know that C++ is included as standard with Raspian?
There's no need to use Python or install mono etc.
C++ will be very very fast and has great support for the GPIO.


OP @est3 mentions three times that they want to program in C#. Ref: https://docs.microsoft.com/en-us/dotnet ... troduction


So a genuine question: At what point of sophistication does C# diverge sufficiently from 'classic' C or C++ that it becomes impossible to compile and run code with the standard GCC compiler for Linux?

Heater
Posts: 13700
Joined: Tue Jul 17, 2012 3:02 pm

Re: programming with c#

Fri Oct 11, 2019 11:34 am

est3,

This is confusing. In your other post you ask the same question but using Python. So which is it C# or Python?

I have no idea about the speed requirements for your project but if speed "bit-banging" a hardware interface is a concern neither C# or Python are suitable.
Memory in C++ is a leaky abstraction .

Heater
Posts: 13700
Joined: Tue Jul 17, 2012 3:02 pm

Re: programming with c#

Fri Oct 11, 2019 11:44 am

B.Goode,
At what point of sophistication does C# diverge sufficiently from 'classic' C or C++ that it becomes impossible to compile and run code with the standard GCC compiler for Linux?
I'm pretty sure it's impossible to compile any C# with both a C# compiler and a C++ compiler with out modification. Perhaps one can contrive an example. C is right out.

However I recently translated a couple of thousand lines of C# to to C++. That code did a lot of bit and byte twiddling on a proprietary binary format to extract data into useful structures and hence human readable messages in JSON. I know almost nothing about C# but this went very easily and quickly.

So I imagine a C# programmer could pick up enough C++ to get started quite well. Especially if they are introduced to modern C++ features and are not started off by basically learning C first as is traditional in many places.

On the other hand, I have no idea where a C++ neophyte would find such an introduction...
Memory in C++ is a leaky abstraction .

ejolson
Posts: 3727
Joined: Tue Mar 18, 2014 11:47 am

Re: programming with c#

Sat Oct 12, 2019 5:44 pm

Heater wrote:
Fri Oct 11, 2019 11:44 am
B.Goode,
At what point of sophistication does C# diverge sufficiently from 'classic' C or C++ that it becomes impossible to compile and run code with the standard GCC compiler for Linux?
I'm pretty sure it's impossible to compile any C# with both a C# compiler and a C++ compiler with out modification. Perhaps one can contrive an example. C is right out.

However I recently translated a couple of thousand lines of C# to to C++. That code did a lot of bit and byte twiddling on a proprietary binary format to extract data into useful structures and hence human readable messages in JSON. I know almost nothing about C# but this went very easily and quickly.

So I imagine a C# programmer could pick up enough C++ to get started quite well. Especially if they are introduced to modern C++ features and are not started off by basically learning C first as is traditional in many places.

On the other hand, I have no idea where a C++ neophyte would find such an introduction...
It's much easier to translate a language that you don't know well into one that you do, even with programming languages.

My experiments with Mono and Visual Basic on a Raspberry Pi led to results that performed reasonably well. As the development of Mono is now sponsored by Microsoft, it is less likely a Java-style lawsuit will require royalty payments to Oracle for use of the API.

When it comes to very low-level GPIO interfacing, some assembler or C might be needed. That type of library code is generally quite small compared to the rest of the program; however, I would not know how to write such a library that could be used from C#. I wonder if one already exists?

Heater
Posts: 13700
Joined: Tue Jul 17, 2012 3:02 pm

Re: programming with c#

Sat Oct 12, 2019 10:54 pm

I think I would have a very hard time translating any non-trivial Forth or Smalltalk to C. Or even from class and template heavy C++ to C. I once worked for nearly two years on reimplementing an Intel x86 assembler project in C. Which was, shall we say, interesting given the total lack of documentation and the very few comments in the source being in Swedish.

That C# to C++ translation I mentioned was a walk in the park by comparison, it has similar types, similar control constructs, similar syntax etc. Just copy it into a .cpp file and massage it till it compiles properly.

I agree, better to stay away from anything Java or anything tainted by Oracle.
Memory in C++ is a leaky abstraction .

est3
Posts: 12
Joined: Fri Oct 11, 2019 6:28 am

Re: programming with c#

Sat Oct 12, 2019 11:22 pm

thanks a lot to all of you.
scruss wrote:
Fri Oct 11, 2019 9:10 am
You can install a Mono (= portable .Net) development system with:

Code: Select all

sudo aptinstall mono-complete
but whether there's a good and useful GPIO library for it, I don't know.

If the YK-04s you mention are those simple 4 Channel RF Remote Control Module with four buttons, you may hit some problems. I've used these before, and they've got no security or channel functions. Press 1 on one remote, and all of your receivers will register 1. I suspect this is not what you'd want. If it is what you want, you won't need a shift register: one receiver and 4 GPIO ports will read all of your remotes, but can't tell which one was pressed.
the mono know only build the progrem or it's can play a program that i devlop with VS?
you right, by default the yk-04 is with not address so press on button in one remote will be registe on all reciver, but this board use in the pair pt2262/72, they have tri-state pin address to pair transpition and reciver, so if i will weld (i hope this is the word for connect two object by tin in english) the same pins address in any pair remote and reciver they will be pair and press on button in one remote will register in one reciver only.

est3
Posts: 12
Joined: Fri Oct 11, 2019 6:28 am

Re: programming with c#

Sat Oct 12, 2019 11:31 pm

Heater wrote:
Fri Oct 11, 2019 11:34 am
est3,

This is confusing. In your other post you ask the same question but using Python. So which is it C# or Python?

I have no idea about the speed requirements for your project but if speed "bit-banging" a hardware interface is a concern neither C# or Python are suitable.
right now i try to working with python and because of it i asked about python, but it's hard to me, i'm not know the language, so in the while i try to find way to devlop on c#.

est3
Posts: 12
Joined: Fri Oct 11, 2019 6:28 am

Re: programming with c#

Sat Oct 12, 2019 11:41 pm

so what is the beter idea, try to convert to c++ or devlop with mono?

jahboater
Posts: 4785
Joined: Wed Feb 04, 2015 6:38 pm

Re: programming with c#

Sat Oct 12, 2019 11:49 pm

est3 wrote:
Sat Oct 12, 2019 11:31 pm
right now i try to working with python and because of it i asked about python, but it's hard to me, i'm not know the language, so in the while i try to find way to devlop on c#.
You will find C++ much more familiar!

est3
Posts: 12
Joined: Fri Oct 11, 2019 6:28 am

Re: programming with c#

Sun Oct 13, 2019 12:08 am

jahboater wrote:
Sat Oct 12, 2019 11:49 pm
est3 wrote:
Sat Oct 12, 2019 11:31 pm
right now i try to working with python and because of it i asked about python, but it's hard to me, i'm not know the language, so in the while i try to find way to devlop on c#.
You will find C++ much more familiar!
right, but i need also GUI and it's not sound easy with c++.

User avatar
scruss
Posts: 2582
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: programming with c#

Sun Oct 13, 2019 4:05 pm

jahboater wrote:
Sat Oct 12, 2019 11:49 pm
You will find C++ much more familiar!
Not if you've only used C#, as the OP stated.

I don't know of any GUI for Raspberry Pi that would replicate the Windows C# development experience.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

jahboater
Posts: 4785
Joined: Wed Feb 04, 2015 6:38 pm

Re: programming with c#

Sun Oct 13, 2019 4:29 pm

scruss wrote:
Sun Oct 13, 2019 4:05 pm
jahboater wrote:
Sat Oct 12, 2019 11:49 pm
You will find C++ much more familiar!
Not if you've only used C#, as the OP stated.
He also mentioned Python as an alternative.
I think C++ is closer in style to C# than Python is.

ejolson
Posts: 3727
Joined: Tue Mar 18, 2014 11:47 am

Re: programming with c#

Sun Oct 13, 2019 4:36 pm

scruss wrote:
Sun Oct 13, 2019 4:05 pm
jahboater wrote:
Sat Oct 12, 2019 11:49 pm
You will find C++ much more familiar!
Not if you've only used C#, as the OP stated.

I don't know of any GUI for Raspberry Pi that would replicate the Windows C# development experience.
Isn't Visual Studio Code running on the Pi similar? I understand it can even send telemetry data to Microsoft.

Heater
Posts: 13700
Joined: Tue Jul 17, 2012 3:02 pm

Re: programming with c#

Sun Oct 13, 2019 5:50 pm

ejolson,
Isn't Visual Studio Code running on the Pi similar?
From reports around here, yes.
I understand it can even send telemetry data to Microsoft
Indeed it can.

But Microsoft is my friend. They gave me a new Surface Pro 4 when my old one exploded (No really, it did) even if it was well over it's two year warranty. They gave me Windows 10 for free to run on two nice PC's salvaged from the local university throw outs. They let me use Github for free for all my source repositories. They made the editor I use almost all day everyday, open source and for free. They fixed up their crappy operating system so that I can run all my favorite programs from Linux world. They give me free food and beer when I visit their developer parties. We have such a wild time. Such nice people.

But if it bothers anyone, VS Code Telemetry can be turned off easily enough: https://code.visualstudio.com/docs/getstarted/telemetry

Anyway, what has all that got to do with choice of programming language? I'm not sure if est3 meant to say "create a GUI" but VS Code won't help much with that.
Memory in C++ is a leaky abstraction .

hippy
Posts: 6107
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: programming with c#

Mon Oct 14, 2019 11:11 am

est3 wrote:
Sat Oct 12, 2019 11:41 pm
so what is the beter idea, try to convert to c++ or devlop with mono?
Given you are familiar with C# and mono is easy to install ( and presumably to remove ); I would suggest installing mono and seeing for yourself if it is suitable for your needs.

If not then you can then consider how converting to C++ compares.

est3
Posts: 12
Joined: Fri Oct 11, 2019 6:28 am

Re: programming with c#

Tue Oct 15, 2019 7:16 pm

ok, thank you guys, you helped me a lot.

est3
Posts: 12
Joined: Fri Oct 11, 2019 6:28 am

Re: programming with c#

Wed Oct 16, 2019 7:27 am

hi, mono is just compleir that run on linux? or it compile the programso it can run on linux?

User avatar
B.Goode
Posts: 8915
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: programming with c#

Wed Oct 16, 2019 7:39 am

est3 wrote:
Wed Oct 16, 2019 7:27 am
hi, mono is just compleir that run on linux? or it compile the programso it can run on linux?



See the explanation here - https://www.mono-project.com/docs/about-mono/

est3
Posts: 12
Joined: Fri Oct 11, 2019 6:28 am

Re: programming with c#

Wed Oct 16, 2019 11:46 am

Mono, the open source development platform based on the .NET Framework, allows developers to build cross-platform applications with improved developer productivity.
It's mean that the program will be cross-platform, right? so i can develop in VS in windows (just for my convenience), compile with mono and run on raspbian, right?

User avatar
B.Goode
Posts: 8915
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: programming with c#

Wed Oct 16, 2019 11:49 am

est3 wrote:
Wed Oct 16, 2019 11:46 am
Mono, the open source development platform based on the .NET Framework, allows developers to build cross-platform applications with improved developer productivity.
It's mean that the program will be cross-platform, right? so i can develop in VS in windows (just for my convenience), compile with mono and run on raspbian, right?



It doesn't say that, but you might be right...


Why not try it and see, and report back what you find?

ejolson
Posts: 3727
Joined: Tue Mar 18, 2014 11:47 am

Re: programming with c#

Wed Oct 16, 2019 2:23 pm

est3 wrote:
Wed Oct 16, 2019 11:46 am
Mono, the open source development platform based on the .NET Framework, allows developers to build cross-platform applications with improved developer productivity.
It's mean that the program will be cross-platform, right? so i can develop in VS in windows (just for my convenience), compile with mono and run on raspbian, right?
The language is the same as are many of the support libraries; however, there are some libraries on Windows which either are missing or incomplete under Mono. For this reason one needs to be very careful when creating a cross-platform program written in C# under Windows.

An approach more likely to succeed is to write the program on the Pi and and then run it on Windows. Note that once you get familiar with what libraries work well on both platforms, developing on Windows should be pretty easy too.

est3
Posts: 12
Joined: Fri Oct 11, 2019 6:28 am

Re: programming with c#

Thu Oct 17, 2019 9:48 am

thank you to both of you (:

Return to “Other programming languages”