|
I wish to include embedded code into a C# project so that I can debug the "real" thing and so that I can graph what is going on. Here is a little about the setup. We have A/D data coming in the serial port avery 3ms. I catch the data and can graph it today, nifty. Now, I want to include the actual firmware into the C# project and call that code when the samples arrive. This way, I run the real code, not a simulation, and can see what the firmware is doing. The acutal C code would be used, therefore, by two projects: C# and the embedded compiler. I am sure this can be done, but I'm just starting the process. I need to be able to call the C functions and also see the C variables (so that I can graph them if I wish).
To understand why this would be cool, consider doing some digital filtering on an incoming signal. You could view (on a graph) the raw data, and the filtered data. While we understand how this works in theory, there is nothing like being able to literally see the data live.
Please forgive this very general request, but I have to start somewhere. I'm heavy into embedded stuff, but the power of C# will be a wonderful tool to use. The graphing ability I all ready have (on just the raw data) has paid off in a big way. Thank you for any help you can provide.
Kenny
Kenny O'Dell
Prinicpal R&D Software Eng
Mettler-Toledo Inc.
Worthington, OH
|
|
|
|
|
To use your C code in a C# project, you will have to compile your C code to a dll and export those functions you want to call from your C# code. Also, any structures and data types will have to be redefined in your C# code. I would suggest reading up on P/Invoke since this is what you will have to do. An example is as follows:
/*In my C code*/
typedef struct MyStruct<br />
{<br />
int x;<br />
int y;<br />
char buf[ 80 ];<br />
}<br />
<br />
void Foo( MyStruct* pStruct );<br />
Compile this to, say, MyDll.dll.
Your C# code would do something like this:
[
LayoutKind(LayoutKind.Sequential)]<br />
public struct MyStruct<br />
{<br />
public int x;<br />
public int y;<br />
[MarshalAs(ByValTStr), SizeConst = 80]<br />
public string buf;<br />
}<br />
[DllImport("MyDll.dll")]<br />
public static extern void Foo( ref MyStruct );
I hope this helps get you started.
Deus caritas est
|
|
|
|
|
Thanks for the tip. I'll get started today. Of course, this leads to another question: you say to compile my C code as a DLL. How do I do that? You mean make a DLL project in studio? Suck the code in that way? Forgive me, but this is new territory for me. Hey, you want to talk about talking to an I2C device via discrete I/O pins, I'm your guy. Just getting going on the .NET world. I've successfully made quite a few apps with C#, but always with 100% managed code.
Look forward to your response.
Kenny O'Dell
Prinicpal R&D Software Eng
Mettler-Toledo Inc.
Worthington, OH
|
|
|
|
|
Yeah, make a DLL project in visual studio and export your functions that you want to call from your C# code. Make this an empty project. Then, add your .h and .c code to the project. Make sure to set the project property to compile as C code vs. compiling as C++ code. To export your functions you could put something like this in your header file.
<br />
__declspec(dllexport) void Func1( void );<br />
__declspec(dllexport) void Func2( void );<br />
I hope this helps get you started. There is tons of information on the web on creating dlls and exporting functions.
Deus caritas est
|
|
|
|
|
Please help me
I need to create an Array containing 100000 in the range from 0 99999 and no duplicates
Please show me the algorithms
Thanks so much
eric
|
|
|
|
|
there are only 100000 numbers in the range 0-99999, so of course there would be no duplicates.
Just loop from 0 to 99999 adding each number as you go!
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
Random r=new Random();
for (int a=0;a<=99999;a++)
{
int b[a]=r.next(0,99999);
}
And for duplicates sorry i dont know.
nemanja
|
|
|
|
|
What I mean is for example
2, 7, 88, 33, ....
There are 100000 elements and 1 number created once , but they are random orders.
Not this: 2, 8 , 7 , 8, 7....
Sorry
Pls help
eric
|
|
|
|
|
Random r=new Random();
for(int k=0;k<=10000;k++)
{
int x=0;
int b[k]=r.next(x,10000)
x=x+1
}
Not a really good solution but it will work !?!;)
nemanja
|
|
|
|
|
Yeah,
That's true
Thanks anyway
eric
|
|
|
|
|
Like J4amieC suggested I would start by creating an array containing all your numbers sorted. Then just switch the numbers randomly in x iterations. Pick two random indices between 0 and 99999 and switch the two values in the array. If you make this long enough (probably 1 million times) than they should be ordered rather randomly.
int[] list = new int[100000];
for (int i = 0; i < list.Length; i++)
list[i] = i;
Random r = new Random();
for (int i = 0; i < 1000000; i++)
{
int i1 = r.Next(0, list.Length);
int i2 = r.Next(0, list.Length);
int temp = list[i1];
list[i1] = list[i2];
list[i2] = temp;
}
int counter = 0;
for (int i = 0; i < list.Length; i++)
if (i == list[i])
counter++;
|
|
|
|
|
Very smart solution
Thanks so much Robert
I'm fixing now
eric
|
|
|
|
|
Does any statistical wizard know exactly how much you'd need to randomly swap items like this before you had something that you could say wasn't biased by the fact that the items started in order?
I'm just curious.
BTW, what's the last for loop for?
|
|
|
|
|
I think it should be pretty simple for a statician (does this word exist?). Just calculate how likely it is that one index in the array isn't hit and multiply this with the length of the array.
Wjousts wrote: BTW, what's the last for loop for?
It was for myself trying to determine if one million switches would be enough. My tests mostly said that 0-2 elements were at its original position. Whether this was because they weren't hit by the algorithm or if they were just reswitched I don't know .
|
|
|
|
|
Robert Rohde wrote: It was for myself trying to determine if one million switches would be enough. My tests mostly said that 0-2 elements were at its original position. Whether this was because they weren't hit by the algorithm or if they were just reswitched I don't know .
That's what I thought you might be doing, but I think the logic to that might be flawed. You'd expect at least a few elements to be in the correct place just by chance. If five items just happen to end up in the correct place it doesn't mean the sequence isn't random. Even a random sequence could (in theory) end up being in exactly the right order.
|
|
|
|
|
You are absolutely rihgt. I just added it for me to check whether it is 'somehow random'. If the result would have been something like 1000 (I think the chance of having such a large number of items at their exact location should be near to zero) than I would not have posted the code .
|
|
|
|
|
That's pretty cool, but surely has the danger that numbers won't ever get hit and moved elsewhere, so you end up with a pretty random list with a few numbers exactly where they started.
Instead of swapping randomly, why don't you go through the array sequentially, and swap each number with a random one?
Regards,
Rob Philpott.
|
|
|
|
|
I've done something very similar several times (not as much as 100,000 though). The way I did it was this:
int[] myArray = new int[100000];
Random rnd = new Random();
ArrayList number = new ArrayList(100000);
for (int i=0; i<100000; i++)
{
number.Add(i);
}
for (int i=0; i<100000; i++)
{
int temp = rnd.Next(numbers.Count);
myArray[i] = numbers[temp];
numbers.RemoveAt(temp);
}
I populate an ArrayList with all the numbers and then randomly pull them out of the list and put them in my array. I don't know how efficient it'd be for 100,000 items though.
|
|
|
|
|
Hiiii,
I want to change the color of scroll bars...like u can see in Windows xp forms having a blue color scroll bar.
thanx
Anuj Kamthan
Software Developer
Solversa Technologies,
Pune - 411007, India.
http://www.solversa.com
|
|
|
|
|
Hiii,
I m Working on an c# Desktop Application i need to change the color of scroll
bars...
Anuj Kamthan
Software Developer
Solversa Technologies,
Pune - 411007, India.
http://www.solversa.com
|
|
|
|
|
The WinForms platform does not provide a way to modify the appearance of a scrollbar. There is probably some way to accomplish that via P/Invoke. If that does not tickle your fancy, you can buy third-party controls (like the Infragistics NetAdvantage) and use their customizable scrollbars.
Josh
|
|
|
|
|
I have a class property that I want to be localisable. The MSDN gives an example as:
<br />
[<br />
Description ( "The name of this section" ),<br />
Category ( "Section" ),<br />
DisplayName ( "Section name" ),<br />
Localizable ( true )<br />
]<br />
public int MyProperty {<br />
get {<br />
return 0;<br />
}<br />
set {<br />
}<br />
}<br />
The help files say
When code is generated for a component, members that are marked with the
LocalizableAttribute set to true have their property values saved in resource
files. You can localize these resource files without modifying the code.
So I would expect all the attributes to appear in the .resx file, but they don't. Is this a bug, or am I doing something wrong?
|
|
|
|
|
I think you must also set Localizable of the Form the control is placed on also to true.
|
|
|
|
|
The class isn't on a form.
It's just a holder for information that can be used by PropertyGrid.
|
|
|
|
|
I wont my app workon mobile phone who support java.
But my app is writen in c# how can i convert it!
Thanks!!
nemanja
|
|
|
|