Shop OBEX P1 Docs P2 Docs Learn Events
Working with the Propeller in C# — Parallax Forums

Working with the Propeller in C#

Bobb FwedBobb Fwed Posts: 1,119
edited 2010-04-29 14:01 in Propeller 1
I am very new to C# and I am attempting to make a simple program that parses SPIN code I have and and program a propeller with it.

I am using Visual Studio 2008, C# .NET 3.5 and when I try to add the propellant.dll in "Add Reference" -> "Browse" I get the attached error.
I have never used a DLL. What am I doing wrong?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!

Some of my objects:
MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
507 x 608 - 27K

Comments

  • Erik FriesenErik Friesen Posts: 1,071
    edited 2010-03-19 19:45
    For a dll to work with c# it has to be built in the dotnet framework, unless you want to call it unconventionally, which I won't get into here. I couldn't find any quick info on how it was built, but I am guessing it is not dotnet.

    social.msdn.microsoft.com/Forums/en/Vsexpressvcs/thread/c194f361-afcb-47ac-81e9-8be60cbc25a0
  • Jesse MasseyJesse Massey Posts: 39
    edited 2010-03-19 21:21
    Hello,

    Here is a code sample that I just created. It is very simple and can easily be expanded. All it does is takes a spin file and creates the binary, then it displays the data in a datagrid.

    All you have to do is past this in a form and connect the on FormLoad and on FormClose events. Also put the Propellent.dll file on your C: or change your program to reflect your location. I did not have the library which you should have to get a complex program to work.

    If you have any questions or you want me to expand this I will do my best.

    Jesse


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace Prop
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            [noparse][[/noparse]DllImport("C:\\Propellent.dll")]
            public static extern void InitPropellent(long WinHandle, bool StorePrefs, string RegPath);
    
            [noparse][[/noparse]DllImport("C:\\Propellent.dll")]
            public static extern void FinalizePropellent();
    
            [noparse][[/noparse]DllImport("C:\\Propellent.dll")]
            public static extern string GetLibraryPath();
    
            [noparse][[/noparse]DllImport("C:\\Propellent.dll")]
            public static extern void SetLibraryPath(string Path);
    
            [noparse][[/noparse]DllImport("C:\\Propellent.dll")]
            public static extern IntPtr CompileSource(string FileName, bool ShowError);
    
            [noparse][[/noparse]DllImport("C:\\Propellent.dll")]
            public static extern bool SaveImage(bool AsBinary, string FileName, bool ShowSaveAs);
    
    
            private void Form1_Load(object sender, EventArgs e)
            {
                InitPropellent((long)this.Handle, false, "");
    
                SetLibraryPath("c:\\");
    
                CompileSource("C:\\test.spin", true);
                
                SaveImage(true, Environment.CurrentDirectory+"\\output.binary", false);
    
                System.IO.FileStream file = new System.IO.FileStream(
                    Environment.CurrentDirectory + "\\output.binary", System.IO.FileMode.Open);
                
                byte[noparse][[/noparse]] buf = new byte[noparse][[/noparse]file.Length];
                file.Read(buf, 0, (int)file.Length);
    
    
                DataGridView dataGridView1 = new DataGridView();
                dataGridView1.Dock = DockStyle.Fill;
                dataGridView1.RowHeadersVisible = false;
                this.Controls.Add(dataGridView1);
    
                for (int count = 1; count < 9; count++)
                {
                    DataGridViewCell cell = new DataGridViewTextBoxCell();
                    DataGridViewColumn dCol = new DataGridViewColumn(cell);
                    dCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                    dCol.HeaderText = count.ToString();
                    dataGridView1.Columns.Add(dCol);
                }
    
                dataGridView1.Rows.Add();
                int row = 0;
                int col = 0;
                
                foreach (char data in buf)
                {
                    if (col == 8)
                    {
                        row++;
                        col = 0;
                        dataGridView1.Rows.Add();
                    }
    
                    dataGridView1[noparse][[/noparse]col, row].Value = (int)data;
    
                    col++;
                }
    
                file.Close();
                
            }
    
            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                FinalizePropellent();
            }
        }
    }
    
    
    564 x 495 - 39K
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-03-19 21:40
    @Jesse Massey: Thank you. This should get me started.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!

    Some of my objects:
    MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
    Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
    String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
    Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-03-29 18:44
    Once I send the DownloadToPropeller command. Is there any way to see if it was successful or not? That function returns nothing. Wouldn't it be simple enough for them to set it up to return a bool with success or not?
    Is there some method I am missing that would allow to see if it worked or not?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!

    Some of my objects:
    MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
    Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
    String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
    Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
  • jazzedjazzed Posts: 11,803
    edited 2010-03-29 19:13
    That's the other reason I don't use Propellent [noparse]:)[/noparse]

    I use BradC's BSTC application with System.Diagnostics.Process ....
    It compiles and downloads much much faster, but it doesn't provide a .dll .
    I parse the output for errors since BSTC also does not provide a return code.
    No return code must be a Pascal/Delphi thing [noparse]:)[/noparse]
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-03-29 22:13
    Where do I get a hold on said software?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!

    Some of my objects:
    MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
    Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
    String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
    Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
  • jazzedjazzed Posts: 11,803
    edited 2010-03-29 23:01
    Bobb Fwed said...
    Where do I get a hold on said software?
    http://www.fnarfbargle.com/bst/bstc/Latest/

    Attached is the C# class I use for build and download. I call it with this:

    bool noerr = this.builder.runProgram(path, "bstc", bstcOptStr + toolStripBuildToolOptions.Text + " " + toolStripTextBoxBstcLib.Text + " -d " + comport.PortName + " " + file, "Error", textBoxStatus, progressBar);

    // builder is an instance of Builder
    // I pass a textbox for collecting output and a progressBar for updates.
    // the 3rd parameter is the argument set to use when running bstc use options that make sense for you.

    Note that starting a program from within a C# program this way may pose a security risk. Use at your own discretion.
  • BradCBradC Posts: 2,601
    edited 2010-03-30 00:34
    jazzed said...

    I parse the output for errors since BSTC also does not provide a return code.
    No return code must be a Pascal/Delphi thing [noparse]:)[/noparse]

    Odd, it's supposed to. It certainly used to when I tested it with cygwin (./bstc.exe -blah ; echo $?)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You only ever need two tools in life. If it moves and it shouldn't use Duct Tape. If it does not move and it should use WD40.
  • jazzedjazzed Posts: 11,803
    edited 2010-03-30 00:54
    BradC said...
    Odd, it's supposed to. It certainly used to when I tested it with cygwin (./bstc.exe -blah ; echo $?)
    Oops. You're right. Sorry about that.

    There is a provision for checking the return code in Builder.cs if "searchout" is a zero length string.
    All the other stuff is there from the days when there was no return code from bstc.

    BTW, one can test return codes from windows programs as: application || echo "error"
    The "error" is only printed if the application return code is non-zero.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-04-28 16:11
    Are there any known issues with Propellant and Windows 7 or 64-bit OSs?
    My software works fine on XP and Vista (both 32-bit) computers, but I tried installing it on my friend's Win7 64-bit and it just throws unhandled exceptions. It appears the Propellant DLL can't load.

    Any ideas?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!

    Some of my objects:
    MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
    Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
    String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
    Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-04-28 23:47
    No ideas? Has anyone used propellant on either Windows 7 or on a 64-bit OS? At least help me narrow down the issue a bit.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!

    Some of my objects:
    MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
    Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
    String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
    Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
  • jazzedjazzed Posts: 11,803
    edited 2010-04-29 06:24
    Bobb, I wish I could help. Alas, I don't use Windows 7.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    May the road rise to meet you; may the sun shine on your back.
    May you create something useful, even if it's just a hack.
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2010-04-29 14:01
    @Bobb Fwed

    re:No ideas? Has anyone used propellant on either Windows 7 or on a 64-bit OS? At least help me narrow down the issue a bit.


    Bob I haven't tried it but this article may give you a few tips:

    ======================================================================================================================
    This article provides an overview of the Windows on Windows 64 (WOW64) sub-system and associated techniques that support 32 bit applications under Windows 7 / Vista 64.

    The Enterprise, Ultimate and Professional versions of 64 bit Windows 7 also support a 32 bit Windows XP virtual machine, which is available as optional download.

    The purpose of this add on, generally referred to as XPM, is to provide an environment that will support legacy hardware and software that will not work under Windows 7. Having tested XPM, I would advise that you only use it as a last resort. It will provide legacy support if you have no other options but, compared to other virtualisation products, performance is disappointing and the default configuration raises a number of security issues.
    ==========================================================================================================================

    Source: www.techsupportalert.com/content/how-windows7-vista64-support-32bit-applications.htm
Sign In or Register to comment.