|
Hi again,
since you now have a thread reading a SerialPort you don't need the DataReceived event anymore, instead just call one of the Read methods and either collect or process the data, then read more.
This may or may not be complex depending on the protocol, the communication conventions, on your serial connection. The easiest one works like this:
- all information is structured in messages
- each message is encoded as text, and ends on a special character or short string (say an ASCII carriage return)
- the reading thread now can perform a ReadLine() which will collect and return data up to the first NewLine string (a CR)
As a result all your app is getting is complete messages.
All other schemes (binary data, no single message termination character, etc) may result in your app receiving fractions or multiples of messages, which forces you to add code to collect such data and split it in individual messages.
Anyway, once you have the code in place to accept one message, just process it before reading more data. One problem that might arise is your data coming in faster than your app can process; if so you need to either speed up your app, or slow down your data source, one way of doing that is by applying "dataflow control"
(see the HandShake property).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
i use thread.join for waiting the message in a particular port. So when number of message come at same time one by one will execute using single thread. At the same time other two port will free to recive message. so all the three port do work concurrently.
3 ports and 3 threads, each thread for each port. 3 DataReceived event for each port.
will this concept work well?
Thankyou
YPKI
|
|
|
|
|
ypki wrote:
will this concept work well?
I am afraid not. When you join the thread that got the data from a port, the thread is dead. Are you saying you start a thread for every single message you receive? that is very expensive. If you want all messages of all ports being serviced sequentially, set up a Queue, let your SerialPort threads receive messages (in a loop) and put them in the queue, and let another thread process all messages it can find in the queue.
That would be a typical producer-consumer configuration, with three producers and one consumer.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I've already done every article it's seem to be useful but can't fulfill my request.
I've just wanted to print all of my data from my datagrid. I have code it can run but this result is far from my thinking
here is code
private void button3_Click(object sender, EventArgs e)
{
printDocument1.Print();
}
public void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
PaintEventArgs myPaintArgs = new PaintEventArgs(e.Graphics, new Rectangle(new Point(0, 0), this.Size));
this.InvokePaint(dataGridView1, myPaintArgs);
when i click on button3 it can print but show just only i can see from datagrid not all of datagrid
Thank in advance !!!!
|
|
|
|
|
Hi,
printing is a rather complex issue. The overall picture is your app has to do the pagination, it has to decide how much data fits on a page (PrintPage event will fire once for every page), and you should set PrintEventArgs.HasMorePages true for all but the last page. Furthermore, you have to keep track of the printing progress and implement the PrintPage handler such that it delivers the data belonging on the page currently being printed.
I don't have a simple example available, but there are lots of them on google. Maybe this one[^] can help you.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thank you very much for helping ^^
It's useful and I'm having a problem with datagridview right but I gonna deal with it.
Although it's so hurt ,I still choose love.
|
|
|
|
|
I have a C1FlexGrid component, to which I am binding a datasource, the following:
A collection of 'View' type objects (code below) which expose their properties for viewing by the grid.
The problem is the ordering of the columns of the C1FlexGrid component. I manually set them to be Number, Attach, Detach, but as soon as a DataSource is set, the column order for some reason changes to Attach, Number, Detach.
Is there a way to forcefully set the columns to appear in a certain order once a datasource has been set?
I was thinking perhaps there's an attribute (component model) to specify with each property but hours of googling and searching MS help has produced nothing!
Any help would be much appreciated!
g
<br />
class TrancheView<br />
{ <br />
private uint number;<br />
<br />
public TrancheView(BespokeTranche _tranche, uint _number)<br />
{<br />
this.tranche = _tranche;<br />
tranche.TrancheNumber = _number;<br />
this.number = _number;<br />
}<br />
<br />
public uint Number <br />
{<br />
get { return tranche.TrancheNumber; } <br />
}<br />
<br />
public decimal Attach<br />
{<br />
get { return tranche.Attach; }<br />
set {<br />
log.Info("setting Attach value");<br />
tranche.Attach = value;<br />
}<br />
}<br />
<br />
public decimal Detach<br />
{<br />
get { return tranche.Detach; }<br />
set<br />
{<br />
log.Info("setting Detach value");<br />
tranche.Detach = value;<br />
}<br />
} <br />
}<br />
<br />
|
|
|
|
|
Stuff like that is why I don't use data binding!
You might get more help if you ask this in the Component One Forums[^]
|
|
|
|
|
cheers yeah i dont have issue with databinding generally and think its quite a cool concept (saving time and ensuring robustness).
what i do have a problem with is when the order of columns are randomly shuffled for no reason!!!!!!
|
|
|
|
|
Hi all,
Does anyone know how to post messages to a message queue associated with the thread that created the specified window?
I am porting some cpde from VC++ to VC# and have stumbled acroos the VC++ function PostMessage, but i cant find a VC# equivalent or at the very least a way to accomplish what that function does.
Anyone got any pointers or ideas?
|
|
|
|
|
There are two Windows API functions PostMessage and SendMessage . In order to utilize them you will need to research a technique called P/Invoke.
Either Google for P/Invoke C#, or PostMessage C# or SendMessage C#
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Good People,
So, my software installs a file that is read/write while the application is running. During debug, it works fine - read/write no problem. So, I created an MSI (Windows Installer Project in Visual Studio 2008 Sp1) for the application. It installs fine.
However, now two problems have emerged:
1) It states that access to the path where the file is located has been denied (it's nested in Program Files).
2) I tried to uninstall it but it's telling me that the appropriate level of access to the registry (something about HKEY_CURRENT_USER roots, certificates, blah, blah...) is not present.
Any help you can provide would be great.
(What really irks me is that when I created the install project before, I never had this issue. I bet it's some setting I missed. Oh well.)
Thanks,
Blitz
|
|
|
|
|
Hi,
for 1) I am not surprised; you probably needed admin privileges to get your app installed (so all users can use it), however a regular user cannot write to Program Files and its descendents.
Furthermore, one could make the whole app folder (or even Program Files) read-only for added protection, so the user trying to write files there is no good.
I suggest you use one of the preferred file locations using the Environment.GetFolderPath() method, probably with the SpecialFolder.ApplicationData or .CommonApplicationData parameter. You can creaye subfolders and files in there as much as you need to or want to.
Mind you, the actual path returned by GetFolderPath will depend on the specific Windows version, and some admin choices made while installing Windows; however the method takes care of all that.
for 2) I have no idea.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks Luc,
I will use the strategy you suggest.
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I am interested in sending an image I have in memory out through the VGA/DVI port, to a projector connected to the port. Something similar to what you do with PowerPoint. But I want to do it within my own application. Is there a way to access the VGA/DVI in the .NET framework?
|
|
|
|
|
Hi,
welcome to CodeProject.
Haven't done this before, but this is what I would try:
- use the Control Panel "Display Settings" to extend the desktop to your "second monitor" and choose its position
- use Screen.AllScreens to find the location and size of your second monitor
- open a borderless Form with those location and size values
- then paint your image to that Form
WARNING: extending the desktop also extends the range you can mouse over, so your mouse cursor now may wander of the primary screen and become invisible.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thank you for your response, I will look into that.
|
|
|
|
|
Thank you again for your reply, but it is not quite what I was for. I should be a little more specific. Within a C# forms application I would like to give the user the ability to select an image, and then send that image out to the projector which then projects it on a screen. But only that image nothing more. Is there a way to do that in the .NET framework? I am going to try your suggestion next week when I finally get the projector, but have been thinking about the problem since then.
I was hoping for something like the SerialPort class where you can open, write and close the port. But in my case the port would be the second DVI. But I'm not sure that exists. Does it?
Thank you for your help and suggestions.
|
|
|
|
|
Hi,
that was how I understood your question before.
No, you can't deal with a monitor, projector or DVI plug yourself; it needs a lot of data, some sync signals and all that at a very precise and high frequency. That is what the video drivers and video hardware are for.
Try my suggestion. I would start with a second monitor connector rather than the projector, just to separate the issues, although I don't think a projector is any different from a monitor. The "Display Settings" control panel would tell you pretty soon. Only when that is happy does it make sense to start writing some code.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I tried your suggestion yesterday and everything is working. Thank you again. There are a couple things to look out for with this setup. One is what you had mentioned, the mouse being allowed into the projector monitor. The other is the two "monitors" need to be the same resolution, so if the projector has a resolution of 1280x1024, then your 24 inch monitor must run on 1280x1024.
I think I can use Cursor.Clip to solve the mouse problem and I think if I use two video cards then I can run the primary monitor at full resolution and the projector at its resolution. Does that sound reasonable?
|
|
|
|
|
Great.
Bobby Hang wrote: the two "monitors" need to be the same resolution
that is not how I remember it.
Bobby Hang wrote: use Cursor.Clip
haven't used it yet. may be OK within your app, I don't expect it would work for the whole system, say when Explorer has focus.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I stand corrected. After a reboot, I can have 2 separate monitors at different resolutions. The Cursor.Clip is working for me because I have a dedicated application running, so the user can't interact with the rest of the system. But you are correct, once the application loses focus, the Cursor.Clip no longer works. Everything is working just the way a want it to, so thanks again.
|
|
|
|
|
Need to time stamp the last time a file was considered good.
I was trying to use something like: last_Time = DateTime.Now;. This is used inside a decision block. The problem even if the condition to enter the particular block isn't met, it still updates.
So does DateTime.Now execute no matter what?
Now for what I really need. I need to timestamp a infopacket/file/situation as to the last time it passed inspection. In other words when was the last good infopacket/file/situation.
The following code is what I thought would work:
public static DateTime last_Time;
public void Packet_Check(int decision)
{
pass_counter++;
if (decision == 1)
{
stateIndicatorComponent2.StateIndex = 4;
pass_counter = 0;
last_Time = DateTime.Now;
TRUCK_ID_DISPLAY.BackColor = Color.White;
Performance_Log_File(this.Name, Convert.ToString(last_Time)+ " last good packet " + port_in );
}
else
{
if (pass_counter > 3)
{
stateIndicatorComponent2.StateIndex = 3;
}
if (pass_counter > 7)
{
stateIndicatorComponent2.StateIndex = 2;
}
if (pass_counter > 12)
{
Diag_Box.Text = "lastime is " + last_Time;
if (light == true)
{
stateIndicatorComponent2.StateIndex = 3;
TRUCK_ID_DISPLAY.BackColor = Color.Red;
light = false;
}
else
{
stateIndicatorComponent2.StateIndex = 2;
TRUCK_ID_DISPLAY.BackColor = Color.Yellow;
light = true;
}
}
}
}
Thanks
modified on Thursday, May 21, 2009 10:12 AM
|
|
|
|
|
DateTime.Now is a static property that will always return a DateTime set to the current system's time.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|