|
Interesting. I like your set up with the idea of data sinks. One other problem that I didn't really elaborate on in my original post is that I need to trigger other things based on the data coming in, so, for example, when the data crossing a threshold I need another device to be triggered. So I really need to have at least one sink be "high-priority" because it has to identify certain conditions in the data and react as quickly as possible.
|
|
|
|
|
Wjousts wrote: The data coming from the sensor isn't particularly fast, it's about 7Hz and what I need to store is the time since the start of recording (in seconds, stored as a double) and the value from the sensor (also a double). I could easily see an hour of data being collected at one time which I (very) roughly estimate as being about 1.5 Mb of raw data. Ultimately this would need to be saved in a human readable format (or at least an Excel importable format) maybe tab delimited text, so the file size on disk would be several times bigger.
So any thoughts? Recommendations? Am I better off trying to store as much as possible in memory and then only write to disk when recording ends? Or is it better to try and write pieces as it's collected?
Where 7 Hz = 7 inputs per second?
In a 24 hour period that gives you 600,000+ rows. Exclusive of finding one value at a specific time or a range in small interval that isn't going to be human readable regardless of what you do.
Storage as text if you store only the time would be probably 12 meg for each day.
You could do one csv file per day.
If you really want to do time since start rather than time of day then you should plan on putting the time the app started either in the file name or at the beginning of the file. The date of course would be in the file name.
|
|
|
|
|
Okay, human readable is the wrong phrase, importable into Excel or something similar is what I meant. We wouldn't collect 24 hours worth of data at a time anyway. Probably not more than about 1 hour tops, and what we need to be able to do is graph that data and see how well it matches up with data coming from somewhere else.
Putting the time in the filename is a nice idea though. It eliminates the mess of letting users decide what the file should be called as well.
|
|
|
|
|
I also recommend looking at the performance of your program too. I think you're not storing huge amounts of continuous data. I use a profiler http://www.red-gate.com/products/dotnet-development/[^] to help me spot nastiness. When collecting data from devices, it pays to make sure that your program runs smoothly and doesn't accumulate extra memory.
I know it's a little off topic, but doing performance analysis has helped me quite a bit.
"Simplicity carried to the extreme becomes elegance."
-Jon Franklin
|
|
|
|
|
hi guys, i have a form that needs to call a function on his opener form. How can i do this?
ex: form1 opens form2, and form2 needs to call a method in form1.
thanks a lot!
|
|
|
|
|
Make the method public, and pass a reference to itself to the second form (in the second form's constructor).
*** In Form1 ***
Form2 form2 = new Form2(this);
*** In Form2 ***
public Form2 (Form1 form1) : this()
{
_form1 = form1;
}
private Form1 _form1;
|
|
|
|
|
i've used From2 f = new Form2(ref Form1 this); but didnt work.
|
|
|
|
|
This works for me. Two forms, one with a button and textbox (Form1), the other just a button (Form2).
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2(this);
form2.Show();
}
public void Change(string text)
{
textBox1.Text = text;
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form2(Form1 form1) : this()
{
_form1 = form1;
}
private Form1 _form1;
private void button1_Click(object sender, EventArgs e)
{
_form1.Change("Put some text in the TextBox");
}
}
|
|
|
|
|
ok, almost there... i got only one more problem... i need to pass 2 param to my form2.
ex: From2 form = new Form2(id, this);
|
|
|
|
|
Just change the constructor... Simple.
public Form2(int id, Form1 form1) : this()
{
_id = id;
_form1 = form1;
}
private int _id;
private Form1 _form1;
|
|
|
|
|
solved... just removed the : this().
anyway... thank you very much
|
|
|
|
|
The this() call makes the constuctor call the lower-level constructor overload. In this example, Form2(Form1 form1) : this() causes it to call public Form2() during its execution, which thereby causes it to call InitializeComponent(); (and anything else inside Form2() ).
If you don't have a parameter-less constructor overload of course, it will fail.
public Form2()
{
InitializeComponent();
}
public Form2(Form1 form1) : this()
{
_form1 = form1;
}
|
|
|
|
|
you can do it something like:
using(Form2 frm2 = new Form2())<br />
{<br />
frm2.myVoid();<br />
}
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
your answer is not clear at all.
If this is a third form you are creating, it is wrong as it would not share anything with the original Form it is trying to interact with.
|
|
|
|
|
Either do the way others have suggested or follow on of the following approach:
1. Create a class called Common or something similar and place the methods used by more than one forms there. Then all the forms can call methods in this class. Or
2. Have a base class that contains common methods (possibly marked virtual) and all forms in your application inherit from that class.
|
|
|
|
|
I never like solutions that include a child knowing about its parent. I question whether the UI forms should be communicating directly in the first place and if some re-architecturing needs to take place on that design.
But suffice to say, if the forms do need to communicate, I would much rather see it done where Form2 raises an event for which Form1 creates a handler when creating Form2. That way, at least the child still knows nothing about the parent.
if( eventToCall != null )
eventToCall();
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
With events instead, it could look something like this. (Probably better to pass the message in an event argument, though.)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
form2.Clicked += new EventHandler(form2_Clicked);
}
private void form2_Clicked(object sender, EventArgs e)
{
textBox1.Text = form2.Message;
}
private void button1_Click(object sender, EventArgs e)
{
form2.Show();
}
private Form2 form2 = new Form2();
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Message = "Here is some text";
if (Clicked != null) Clicked(sender, e);
}
public string Message = string.Empty;
public event EventHandler Clicked;
}
[Edit] Public to private on Form2.
modified on Wednesday, January 5, 2011 1:31 PM
|
|
|
|
|
In theory correct, but there may be a few issues.
public Form2 form2 = new Form2(); should probably be made a private member unless it it required by something outside this form.(That would likely not be a good idea)
Other than that, I think it is pretty close.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Did I say public? I meant private...
|
|
|
|
|
Hide your members whenever possible... Showing them almost always leads to embarrassment and ridicule...
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Might as well give the "event" version that passes the string as an event arg...
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
form2.Clicked += new Form2.StringEventHandler(form2_Clicked);
}
private void form2_Clicked(string message)
{
textBox1.Text = message;
}
private void button1_Click(object sender, EventArgs e)
{
form2.Show();
}
private Form2 form2 = new Form2();
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (Clicked != null) Clicked("Here is some text");
}
public event StringEventHandler Clicked;
public delegate void StringEventHandler(string message);
}
|
|
|
|
|
Ok, the question is: how to load image from resource (and then do some manipulations on it)?
In a C++ app, i am simply doing:
specifying image in file myapp.rc like:
IDR_MYPIC RCDATA "Res\\bkg.jpg"
then in file resource.h:
#define IDR_MYPIC 111
then in application i can simply access it by:
HRSRC hResInfo = FindResourceW((HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
MAKEINTRESOURCEW(IDR_MYPIC), RT_RCDATA);
I am trying to do actually the same thing in C#, but after hours of searching, experimenting - i got nothing.
This code returns resources path:
System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
string[] resources = thisExe.GetManifestResourceNames();
string list = "";
foreach (string resource in resources)list += resource + "\r\n";
MessageBox.Show(list);
which are:
ComboTest.Form1.resources
ComboTest.Properties.Resources.resources
Then i am trying do apply each path like this:
System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream file = thisExe.GetManifestResourceStream("ComboTest.Form1.resources.zzz.jpg");
this.pictureBox1.Image = Image.FromStream(file);
file always = null
Same thing with that:
IntPtr hModule = ResImage.LoadLibraryEx(Application.ExecutablePath,
IntPtr.Zero, 0x2 );
if (hModule == IntPtr.Zero) throw new Exception();
IntPtr hResource = ResImage.FindResource(hModule, "zzz.jpg", "JPEG");
hResource is always null.
My image file is "zzz.jpg" and i have imported it into a project by clicking on a main form (in a designer), clicking on BackgroundImage in Properties tab, then selecting "Project resource file" radio button and clicking "Import" button.
Image now appears in "Resources" folder in Solution Explorer tab.
So, how can i access it from code?
thanks
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
To access Image from Resource you can use
this.pictureBox1.Image = WindowsApplication1.Properties.Resources.zzz;
modified on Wednesday, January 5, 2011 7:57 AM
|
|
|
|
|
Hi,
I've just tried the following code that works for me:
ResourceManager resourceManager = new ResourceManager("WindowsFormsApplication1.Properties.Resources", this.GetType().Assembly);
Bitmap image = (Bitmap)resourceManager.GetObject("snapshot1");
image.Save("C:\\Temp\\Test123.bmp");
This code works if you add a bitmap called "snapshot.bmp" to your resources. Please make sure that the assembly string does match you project. You will find both strings in the "Resources.Designer.cs" file.
Have a look here for a more detailed explanation:
http://www.mysuperiorgames.com/resources.html[^]
|
|
|
|
|
Thanks guys, that clarified a few things.
Most important thing here for me is to make this work:
IntPtr hResource = ResImage.FindResource(hModule, "zzz.jpg", "JPEG");
I am trying to implement custom background image drawing from memory (cached image) in C# so the app will not flicker when its 2000 X 1000 px bkg image plus 100 of controls on a form. The only method i know is the only by using win32 API (already implemented in c++ project) but here i need a valid "hResource" parameter to pass to my native dll to do the job.
IS it possible to achieve? Maybe you know some ways? thanks in advance
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|