Yorgi
Posts: 3
Joined: Sun Nov 18, 2012 2:51 pm

First Step With Raspberry And C#

Sun Nov 18, 2012 3:11 pm

Hi Everyone!

I totally new in developing on Raspberry Pi - I have to make application for project in my school on this little thing.
Because I can't access to RPi in home, I download QEMU with wheezy-raspbian and I'm trying to do anything what would work using C#.

Long story short - I just wrote couple lines of code to check how it works

Code: Select all

using System;
using System.Windows.Forms;

namespace program
{
    static class Program
    {
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }

    public partial class Form1 : Form
    {
        private System.Windows.Forms.Button button1;

        private int i = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // button1
            // 

            this.button1.Location = new System.Drawing.Point(12, 12);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "0";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.ClientSize = new System.Drawing.Size(120, 60);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            ++i;
            btn.Text = i.ToString(); ;
        }
    }
}
I build it using command:

Code: Select all

mcs -r:System.Windows.Forms,System.Drawing program.cs
which returns nothing - built without errors.
I run it by

Code: Select all

mono program.exe
and there's my problem: I'm getting an error

Code: Select all

[email protected] ~ $ mono program.exe
Stacktrace:

  at System.Drawing.Font.CreateFont (string,single,System.Drawing.FontStyle,System.Drawing.GraphicsUnit,byte,bool) <0x00143>
  at System.Drawing.Font..ctor (string,single,System.Drawing.FontStyle,System.Drawing.GraphicsUnit,byte,bool) <0x0007f>
  at System.Drawing.Font..ctor (string,single,string) <0x00057>
  at (wrapper remoting-invoke-with-check) System.Drawing.Font..ctor (string,single,string) <0xffffffff>
  at System.Drawing.SystemFonts.get_DefaultFont () <0x00073>
  at System.Windows.Forms.Theme..ctor () <0x0002f>
  at System.Windows.Forms.ThemeWin32Classic..ctor () <0x00013>
  at System.Windows.Forms.ThemeEngine..cctor () <0x0009f>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
  at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () <0x00007>
  at System.Windows.Forms.Control..ctor () <0x001f3>
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control..ctor () <0xffffffff>
  at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () <0x0002b>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
  at System.Windows.Forms.Control..ctor () <0x0004b>
  at System.Windows.Forms.ScrollableControl..ctor () <0x00013>
  at System.Windows.Forms.ContainerControl..ctor () <0x00023>
  at System.Windows.Forms.Form..ctor () <0x0006b>
  at program.Form1..ctor () <0x00013>
  at (wrapper remoting-invoke-with-check) program.Form1..ctor () <0xffffffff>
  at program.Program.Main () <0x0002b>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:


Debug info from gdb:

Cannot access memory at address 0x0
Cannot access memory at address 0x0
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
[New Thread 0x40935460 (LWP 2148)]
0x400faf30 in read () from /lib/arm-linux-gnueabihf/libpthread.so.0
  Id   Target Id         Frame 
  2    Thread 0x40935460 (LWP 2148) "mono" 0x400f9d84 in [email protected]@GLIBC_2.4 () from /lib/arm-linux-gnueabihf/libpthread.so.0
* 1    Thread 0x40059000 (LWP 2147) "mono" 0x400faf30 in read () from /lib/arm-linux-gnueabihf/libpthread.so.0

Thread 2 (Thread 0x40935460 (LWP 2148)):
#0  0x400f9d84 in [email protected]@GLIBC_2.4 () from /lib/arm-linux-gnueabihf/libpthread.so.0
#1  0x00195a40 in mono_sem_wait ()
#2  0x000ea384 in ?? ()
#3  0x000ea384 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 1 (Thread 0x40059000 (LWP 2147)):
#0  0x400faf30 in read () from /lib/arm-linux-gnueabihf/libpthread.so.0
#1  0x400fa770 in __pthread_enable_asynccancel () from /lib/arm-linux-gnueabihf/libpthread.so.0
#2  0x00000000 in ?? ()

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Aborted
What cause that? Why it won't work?
I'm tried find something in google but I can't find anything what can solve that.

And another question:
Is there possibility to build whole project, that with .sln extension? (I'm writing in Visual Studio)

3gws
Posts: 49
Joined: Sat Oct 20, 2012 10:32 am

Re: First Step With Raspberry And C#

Sun Nov 18, 2012 5:57 pm

Yorgi, you need to use the soft float very of Wheezy 08-08-12, it wont work with the hard float version.

They (Mono) home to have a hard float version before xmas(their quote).

I am using VS2010 to compile and trasferring across using to the RPi using winSCP.

Set your project to be any CPU and Dotnet 3.5.

I have managed to get the GPIO working with C# using a library from David's Blogg http://www.codehosting.net/blog/BlogEngine/?tag=/Mono.

I also have a FTP client working also.

I am very please with C# and had great help from Edwin here on the site getting up and going with Mono C#.

The best of Luck and if you need any help just ask, I might not be able to answer all of your questions !.

Regards

3gws.

Yorgi
Posts: 3
Joined: Sun Nov 18, 2012 2:51 pm

Re: First Step With Raspberry And C#

Wed Nov 21, 2012 10:39 pm

Thank You very much for Your answer.

But still don't know how to bulid whole C# project.
Should I put all .cs files in parameters of mcs or what?

Yorgi
Posts: 3
Joined: Sun Nov 18, 2012 2:51 pm

Re: First Step With Raspberry And C#

Thu Nov 22, 2012 12:34 am

Ok, nevermind.
I found out that I need to use "xbuild" command.

MattSwarbrick
Posts: 27
Joined: Thu Oct 04, 2012 3:15 pm

Re: First Step With Raspberry And C#

Fri Nov 23, 2012 1:20 pm

There is the hard float patch found here:
https://github.com/directhex/mono-1/tree/armhf-port
To clone the source and get the amhf port code do the following:

Code: Select all

git clone git://github.com/directhex/mono-1.git
cd mono-1
git checkout remotes/origin/armhf-port
This is talked about in the raspberry pi forum: http://www.raspberrypi.org/phpBB3/viewt ... no#p218815

Return to “Other programming languages”