|
Thanks in advance for all your help.
One of the programmers here, created the serial DLL I am using. In that library he has a notify delegate which I subscribe to. His delegate has a couple of parameters which allows me to retrieve the data. Because I deal with a few different communication entities, I created a class which encapsulates the serial DLL, as well as some other specific comm stuff. In my class, I have
// Callback delegate that subscribers must implement
public delegate void DataReceivedHandler();
public event DataReceivedHandler OnDataReceived;
where OnDataReceived gets called inside my subscribed function with the serial library.
Sorry for the longwinded description. So the answer to one of your questions is that
once the library receives data, it creates a "notify" thread and calls my subscribed function which is in my comm class. The code is below
private void SerialConnection_PacketReceived(object sender, ReceivedPacket pkt)
{
// If anyone is subscribed to callback, notify them
if( OnDataReceived != null )
{
m_receivedPacket = pkt;
m_dataSizeReadIn = (int)m_receivedPacket.packet.Length;
Buffer.BlockCopy( m_receivedPacket.packet, 0, m_buffer, 0, m_dataSizeReadIn );
// Call Subscriber
OnDataReceived();
}
}
The serial class (which is also a form) is a member of my main form. The ShowDialogBox() resides in my Main Form. But I could easily move it to serial class. What do you think?
Regards,
McSmack
|
|
|
|
|
McSmack,
Sorry for the late response. I'm not sure I have enough information to accurately answer your question, but let me ask you two things to clarify:
1) What symptoms cause you to think that the secondary thread is still running?
2) How is the thread created in the serial library? If you don't know, could you point me to the place on this site that has the serial library so I can check the code?
I think what may be happening is that your secondary thread is ending, but then more data is sent to the serial port, so your callback function is getting called again and probably causing another dialog box to be displayed. If this is the case, then inside your ShowMyDialogBox function (but after you marshal back to the main thread (i.e. after the InvokeRequired statement) you should check if a dialog box has already been created, and if it has, then do nothing. The best way to do this is to make your secondary dialog variable a member variable of the main form and simply check if the dialog is already created. If it is, don't open another one.
Let me know if that helps point you in the right direction. We should be able to work this out!
Sincerely,
Alexander Wiseman
|
|
|
|
|
Hey Alexander,
Hopefully I can answer these questions to the fullest
1) What symptoms cause you to think that the secondary thread is still running?
I'm most likely wrong, but it seems to be still running. My main form has a TextBox window that gives me updates of where the data control is at, and my ShowMyDialogBox() displays a transparent modal dialog over the main form. When I place the BeginInvoke(new MethodInvoker( this.ShowMyDialogBox)) line in my ShowMyDialogBox() method as you suggested, the dialog comes up and it is modal, but I can still see that the code is still running, displaying me updates in the main form's TextBox.
2) How is the thread created in the serial library? If you don't know, could you point me to the place on this site that has the serial library so I can check the code?
Here are the lines in the library that create the thread..
rcvNotifyThread = new Thread(new ThreadStart(RunRcvNotifyThread));
rcvNotifyThread.Priority = ThreadPriority.Normal;
rcvNotifyThread.Name = "Notify " + portName;
rcvNotifyThread.Start(); // Start the new thread
===========================================================
When you said that the MethodInvoker is just a delegate, it got me thinking. So I played around with it and found a good place to bring the secondary thread back to the main thread. Upon entry of my callback function, I decide to place your solution here since the method that runs all my data processing matches the MethodInvoker delegate. See below
public void ReceiveDataFromSerial(); //Just here to show you the prototype
// the method that implements the delegated funtionality
public void ProcessIncomingData( )
{
string testString = "Thread is named: " + System.Threading.Thread.CurrentThread.Name;
System.Diagnostics.Trace.WriteLine(testString);
Console.WriteLine(testString);
//If not in the main thread, move there and let old thread end
if(this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(this.ReceiveDataFromSerial));
return;
}
// Process Data
ReceiveDataFromSerial(); // This function process all
}
This seems to do the trick. I will keep testing it to make sure everything is sound.
I truly appreciate all your help Alexander.
Regards,
McSmack
|
|
|
|
|
Excellent! I'm glad you got it working.
The purpose of my second question was to make sure that the serial library was explicitly spawning a new thread and not asynchronously invoking a delegate function. I see by the code you put there that it is indeed explicitly creating the thread, so you probably don't want to kill the thread.
I think you solution is perfect, and I understand now why you had said that the thread was still running. Switching to the main thread before doing any of the data processing seems to be the best way to go.
Let me know if you run into any more problems
Sincerely,
Alexander Wiseman
|
|
|
|
|
I'm writing a short little script in Visual Web Developer where you select from a list of sites in a radio button list, then click a "Go there" button and it will take you to the site you have selected.
But for th elife of me I can't figure out what code to put behind the button so that it takes you to the webpage. Here is what I'm working with:
<br />
if (RadioButtonList1.SelectedIndex == 0){<br />
insert code to redirect here<br />
}<br />
In other words, if the first radio button is selected (index 0) then it takes you to a website when the button is clicked.
Thanks ahead of time.
EDIT: I think I'm on right track, but not working...
protected void Button1_Click(object sender, EventArgs e)<br />
{<br />
HtmlLink myHtmlLink = new HtmlLink();<br />
<br />
if (RadioButtonList1.SelectedIndex == 0)<br />
{<br />
myHtmlLink.Href = "www.mywebpage.com"; <br />
}<br />
}
-- modified at 19:23 Wednesday 28th June, 2006
|
|
|
|
|
Arkon948 wrote: I'm writing a short little script in Visual Web Developer
Wrong forum, you posted this in the C# forum, try the Web Development forum for this.
If you were asking for C#, I would say use the WebBrowser.Navigate(URL)[^] method but you didn't ask for C#...
Mike Poz
-- modified at 19:47 Wednesday 28th June, 2006
Wrong MSDN URL...
|
|
|
|
|
Hello everone
I'm about to write an SQL database program, in which I would like to add "Export to" feature, like exporting my data as Excel speardsheets, Access, or even SPSS. I really can't fully describe the idea of integrating all these programs, but I'm sure you got it.
Some points arising
1- Is it legal?? Or do I need the prior permession of SPSS -and other copyights owners- to add "export to SPSS" -or any other program- in my program?? I know this may sound as a ridiculous question, but I don't want to violate any copyrights here.
2- Do I have to write my code from the scratch, or may I use their Dlls -again the copyrights issue-?? If I can't use their DLL, how would I know their format??!
3- I'd like the export ability to work even on machine that doesn't actually have SPSS currently installed on it, also it should be version independent. -ie. I don't want to dynamically link to dlls supposed to be on the target machine. Dlls should be supplied with my program's package-
4- What would be your suggestions of the best way to do it??
5- An example is media players that support RM formats. We all know Real corp. has copyrights over RM. So how would other media players support it??
PS. SPSS is just one example of many programs I'd like to integrate together. Noting that the integration is only in exporting/importing, ie. my program will not open/edit any SPSS files
If you have ANY suggestions, ideas, or comments, I'd really appreciate it.
Thank you.
|
|
|
|
|
The (Open Source) R project contains a library called "foreign" which allows one to read data from a number of proprietary formats in common statistical usage, including SPSS files.
Read the following for details:
http://cran.r-project.org/doc/manuals/R-data.pdf
Examining the R code (written in C) will therefore help you understand the structure of the .sps file type.
Good Luck!
|
|
|
|
|
Hello and thank you for replying.
I've taken a quick glance at the pdf you kindly provided -and it was interesting I must say-, yet as I said before I'm quite concerned about copyrights of the SPSS, or anyother formats I'm going to import/export. the R team didn't do it at a commercial scale, unlike me. So any idea about the legitimacy of this action -on a commercial scale-?
And again, thank you for helping me with the SPSS format. It was my biggest problem.
|
|
|
|
|
The javascript code in the JS file residing in the wwwroot folder does not execute on postback. If I refresh the page it executes otherwise it does not.
Any helpful hints? I am using C# as the code behind scenes.
thanks
Naji
|
|
|
|
|
Do you include the Javascript file in the page?
Does the code contain any code that is not in functions, so that it would do anything without calling functions?
What has made you think that the code doesn't execute?
---
b { font-weight: normal; }
|
|
|
|
|
I have the src attribute that references the javascript file.The javascript file contains a bunch of functions. The show menu function works when the page is loaded but when I press a button on the page it does not work anymore unless I refresh. I am just concluding that the javascript file is not being seen and executed on postback, but I am not sure.
-- modified at 21:47 Wednesday 28th June, 2006
|
|
|
|
|
It's much more likely that there is something in the page that breaks the Javascript.
Have you enabled Javasript error messages in the browser?
---
b { font-weight: normal; }
|
|
|
|
|
Do you know how to enable javascript error messages in a browser? I know I have the active scripting enabled in my browser. I am guessing that this is it.
thanks
-- modified at 4:07 Friday 30th June, 2006
|
|
|
|
|
Internet Explorer: Tools > Internet Options > Advanced > Display a notification about every script error
Firefox: Tools > Javascript Console
---
b { font-weight: normal; }
|
|
|
|
|
I did check that box for the display a notification about every script error. I do not see any error messages coming up. I just see it not functioning in postback. The pop up menu for the navigation bar does not work unless I refresh the page or when the page just loads.
thanks
Naji
-- modified at 19:02 Friday 30th June, 2006
|
|
|
|
|
Then the script is working, it's just not doing what you expect it to do...
Have you examined the page that is produced to see if there is any difference that might affect the script?
---
b { font-weight: normal; }
|
|
|
|
|
What kind of differances are those? Can you give me an example. Not sure, I haven't noticed anything special.
thanks
|
|
|
|
|
Any difference that could break the code. Anything written outside the normal structure of the page. Anything that could make the header tag inoperable.
For an example anything at all written before the doctype tag would make the browser ignore it.
---
b { font-weight: normal; }
|
|
|
|
|
<%@ Page language="c#" Codebehind="ProfitDisplay.aspx.cs" AutoEventWireup="false" Inherits="GlobalNetwork.ProfitDisplay" smartNavigation="True"%>
script functions go here
mmLoadMenus();
On top Is an example of the page structure I have. As you notice I have some stuff before the doctype.I tried to put that under the doctype but did not see any differance. Do you see something special I do not see?
Naji
-- modified at 18:27 Monday 3rd July, 2006
|
|
|
|
|
No, no... The page that is produced, the html code that is sent to the browser. Use "View source" in the browser.
---
b { font-weight: normal; }
|
|
|
|
|
I see the following function being added to the page if I look at the view source:
The code on top is added to the body, but I do not see anything above doctype.
I figured it out I set smartnavigation to false and it did solve the problem!!!
Thanks Guffa
-- modified at 14:58 Tuesday 4th July, 2006
|
|
|
|
|
Hi guys,
I am a newbie in C# and I need your help please.
I have 2 windows forms and I am trying to pass a value from one form to another, in my first form I have:
m_nSessionId=551;
SessionID(m_nSessionId);
public long SessionID(long SID)
{
string test=SID.ToString();
MessageBox.Show(this, test);//This worked and did show me 551
return SID;
}
How do I get the SID value in my other class (Windows form)
I tried this in my other class but keep getting a zero value.
ProcessFile session=new ProcessFile();
session.SessionID(m_nSessionId);
Please Help!!!!!
sasa
|
|
|
|
|
SASA_1 wrote: I have 2 windows forms
No you don't. You have two classes that derive from "Form". So the actual question is "how do you pass values from one class to another"? Since you are the author of the classes you can do that any way you want. Use properties or methods or events or a combination of them, it's up to you! Isn't that cool?
|
|
|
|
|
Easy would be, if the Form1 creates the Form2.
Form1 code.
private Form2 f2;
//Constructorcode
f2 = new Form2();
f2.Show();
Than you can set every public Method or Variable (public int m_nSessionId) from your Form1.
this.f2.m_SessionId = 551;
or
this.f2.SessionID(551);
All the best,
Martin
|
|
|
|