|
actually we have a bus-like serial port which means that we use the serial port in share with lots of microController
and as the protocol is implemented before, we have not any mean to find out which device is sending a message (it is not expected before in protocol)
so that I think this is a multithreading problem
if someone have useful info help me please
|
|
|
|
|
Hi,
I think I understand your problem I take it you are using interrupts with your serial comms as in my article:Serial Communication using WPF, RS232 and PIC Communication[^] . I'm an electrical engineer so I do a lot of work with micro-controllers and programming on UI levels.
From my understanding at the moment the you can not determine which micro-controller has sent the data of which the interrupt loads and displays. There are a few solutions to you problem which depend on your ability to reprogram the micro-controllers.
1st I will assume this is not an option:
If you can ensure that the micro-controllers respond one after each other the you could try the older approach of creating another thread and reading all the data into a buffer this more common in C# applications. I can provide an example of this if required however it's not used that often any more. This will attempt to read the data in a let you deal with it a bit at a time however is less efficient than interrupts and your likely to to loose data.
The best option to ensure data integrity is simply to wait after polling each micro-controller until data is received however I understand this may not be possible if at time the micro-controller does not respond with data. If this is true you will have to introduce a timer to continue after if no data is received.
2nd If you can reprogram the micro-controllers:
This is far easier, 1st simply ensure each micro-controller sends and ID tag before sending any data this way you can determine the start of each package and the device.
An alternative which is the bus standard norm is a busy line. It requires an extra connection between your micro-controllers when a controller receives a request for data it will set this line high. Before any other micro-controller can send it's data it must wait for this line to go low. This method again relies on data always being sent on request and has inherent problems such as if one micro-controller takes a considerable time to transmit for example it has a long string of data to send you could find yourself polling for data from micro-controllers before they have had time to send there previous data. This timing issues are important to deal with and I would recommend the first option for ease as you could still end up with the same problem.
I hope this helps however I do have question if you haven't designed the micro-controllers yourself. If you have your micro-controllers configure on one comms line i.e. one TX and RX line in a bus configuration a busy line should have already been employed else there is nothing to stop your micro-controllers sending data over the top of each other. I would unfortunately expect that this is true in which you could still have the problem you described. Your easiest solution would be to wait to receive data from a micro controller before requesting more. This can still be done extremely fast.
Feel free to ask further questions
Cheers
Chris
|
|
|
|
|
I am collecting the data through serial port and storing it continuously in MYSQL DataBase.
I need to get the data from it and draw the real time graph on WPF applicaiton.
Kindly help me out as i am very new to it.Kindly help me with any samples or examples.
|
|
|
|
|
Hi everybody.
I've created a TreeViewItem in WPF via C# :
TreeView1.Items.Clear();
Image imageHistory = new Image();
imageHistory.Source = new BitmapImage(new Uri(@"/passwordManager;component/images/TreeView/history.png", UriKind.Relative));
imageHistory.Width = imageHistory.Height = 16;
Label labelHistory = new Label();
labelHistory.Content = "History";
StackPanel stackPanelHistory = new StackPanel();
stackPanelHistory.Orientation = Orientation.Horizontal;
stackPanelHistory.Children.Add(imageHistory);
stackPanelHistory.Children.Add(labelHistory);
TreeViewItem treeViewHistory = new TreeViewItem();
treeViewHistory.Name = "TreeViewItemHistory";
treeViewHistory.Header = stackPanelHistory;
TreeView1.Items.Add(treeViewHistory);
The result of above codes :
<TreeView x:Name="TreeView1" FontSize="13" Grid.Column="0" BorderBrush="Transparent" Padding="0">
<TreeViewItem Name="TreeViewItemHistory">
<TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<Image Source="images/TreeView/history.png" Width="16" Height="16"></Image>
<Label Content="History"/>
</StackPanel>
</TreeViewItem.Header>
</TreeViewItem>
</TreeView>
After that, I'm gonna add some TreeViewItems within TreeViewItemHistory ,
For doing it , I've written the following C# codes :
private void MenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
{
for (int i = 0; i < 10; i++)
{
Image img1 = new Image();
img1.Source = new BitmapImage(new Uri(@"/passwordManager;component/images/TreeView/empty-bookmark.png", UriKind.Relative));
img1.Width = img1.Height = 16;
Label label = new Label();
label.Content = "Test " + i;
StackPanel sp = new StackPanel();
sp.Orientation = Orientation.Horizontal;
sp.Children.Add(img1);
sp.Children.Add(label);
TreeViewItem treeViewItem = new TreeViewItem();
treeViewItem.Name = "TreeViewItem" + i;
treeViewItem.Header = sp;
TreeViewItemHistory.Items.Add(treeViewItem);
}
}
The above method runs without any Exceptions , but nothing happen and no TreeViewItem doesn't add to TreeViewItemHistory .
I don't know what wrong is with it!
Could you please guide me ?
Editing : I added the XAML code of TreeViewItemHistory within TreeView1 at first. Then, in a method I have cleared all TreeView's TreeVewItems with TreeView1.Items.Clear(); . finally I've added TreeViewItemHistory via C# again.
Thanks.
|
|
|
|
|
The Items property doesn't hold TreeViewItem objects, it holds your business (or viewmodel) objects, and a TreeViewItem object is generated behind the scenes for each of them.
Your way of handling the TreeView is not how things are meant to be done in WPF... You should read more about DataTemplate ItemTemplate etc...
|
|
|
|
|
|
Try reading this[^] article instead.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
You can take advantage of the new Silverlight 4 training course on Channel 9 Learning Center [^] where you will learn about the latest features of the Silverlight 4 Beta, announced at the Professional Developers Conference 2009.
Some of the new and highly anticipated features include Printing, Webcam and Microphone support, custom right-click, rich text, HTML support and access to local files with trusted applications.
The course contains a video and a technical feature overview that allows you to drill down into lessons that address three topics: Enabling Business Application Development, Empowering Richer Experiences and Moving Beyond the Browser.
Each lesson includes detailed guidance and code samples.
|
|
|
|
|
Nice - thanks .
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
Hi, I created WPF as C# dll.
And i loaded that dll in one of my VC++ dailog.
Now the control apperas in dialog from the half and other place look fully black.Whats my mistake.How can i do that.
Pls help me.
Anu
|
|
|
|
|
This is my service code
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Threading;<br />
using System.ServiceModel;<br />
using System.ServiceModel.Description;<br />
using System.Collections;<br />
<br />
namespace ServerConsole<br />
<br />
{<br />
<br />
[ServiceContract ]<br />
<br />
public interface IService1<br />
{<br />
<br />
[OperationContract]<br />
String GetMessage(String name);<br />
<br />
[OperationContract]<br />
string GetData(int value);<br />
<br />
<br />
<br />
}<br />
<br />
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
public class Service1 : IService1<br />
<br />
{<br />
<br />
<br />
Int32 someNumber;<br />
<br />
<br />
<br />
Service1()<br />
<br />
{<br />
<br />
Console.WriteLine("{0} : Created new instance ", System.DateTime.Now);<br />
<br />
}<br />
<br />
<br />
<br />
public string GetData(int value)<br />
<br />
{<br />
<br />
<br />
<br />
<br />
<br />
someNumber = value;<br />
<br />
<br />
<br />
<br />
Random rand = new Random();<br />
<br />
<br />
<br />
Thread.Sleep(rand.Next(1000));<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Console.WriteLine("parameter = {0}, somenumber = {1}, thread = {2}\n",<br />
<br />
<br />
<br />
value.ToString(),<br />
<br />
<br />
<br />
someNumber.ToString(),<br />
<br />
<br />
<br />
Thread.CurrentThread.ManagedThreadId);<br />
<br />
<br />
return string.Format("You entered: {0}", value);<br />
<br />
<br />
<br />
}<br />
<br />
<br />
public String GetMessage(String name)<br />
<br />
{<br />
<br />
Console.WriteLine("{0} : Get Message called on thread {1}", System.DateTime.Now, Thread.CurrentThread.ManagedThreadId);<br />
<br />
return "Hello world from " + name + "!";<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
class Program<br />
<br />
{<br />
<br />
static void Main(string[] args)<br />
<br />
{<br />
<br />
ServiceHost serviceHost = new ServiceHost(typeof(Service1), new Uri("http://localhost:8001/ServerConsole"));<br />
<br />
serviceHost.AddServiceEndpoint(typeof(IService1), new WSHttpBinding(), "");<br />
<br />
<br />
<br />
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();<br />
<br />
smb.HttpGetEnabled = true;<br />
<br />
serviceHost.Description.Behaviors.Add(smb);<br />
<br />
<br />
<br />
serviceHost.Open();<br />
<br />
<br />
<br />
<br />
<br />
Console.ReadKey();<br />
<br />
<br />
<br />
serviceHost.Close();<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
but through this code i cannot understand properly the concurrency mode,<br />
<br />
do any one have code to under stand concurrency mode clearly.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
|
|
|
|
|
Single: Requests are queued, so only one can be processed at a time. No threading issues.
Multiple: Multiple requests can happen at the same time. You have to deal with it just like you would with a normal multi-threaded program.
That's pretty much it.
|
|
|
|
|
that i know and read in many books but i want some concrete examples. please help me.
|
|
|
|
|
Can any body tell me the what code i write in client to check the concurrency.
|
|
|
|
|
You don't "check" the concurrency from the client... The server is in charge of that. The client doesn't need to know.
|
|
|
|
|
It's the same thing as multi-threaded programming. Generally, you want to use "Multiple" as long as your class is thread-safe.
If you're not familiar with thread safety, I would suggest teaching yourself about that before trying to learn it alongside network communication.
|
|
|
|
|
I knew about thread safety, but i don't have any clear examples to understand concurrency modes , i run this code as client but it always goes sequentially.
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
<br />
<br />
namespace ConsoleApplication1<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
ServiceReference2.Service1Client c1 = new ConsoleApplication1.ServiceReference2.Service1Client();<br />
<br />
for (int i = 0; i < 5; i++)<br />
{<br />
<br />
<br />
Console.WriteLine(String.Format("Call {0} Start: {1}",<br />
i.ToString(), DateTime.Now.ToLongTimeString()));<br />
Console.WriteLine(String.Format("Call {0} : {1}",<br />
i.ToString(), c1.GetData(i)));<br />
Console.WriteLine(String.Format("Call {0} End: {1}",<br />
i.ToString(), DateTime.Now.ToLongTimeString()));<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
c1.Close();<br />
<br />
Console.ReadKey();<br />
}<br />
}<br />
}<br />
<br />
|
|
|
|
|
If you want to test concurrency, you need to have more than one thing attempting to hit the same code at the same time. Simply having one instance of a single threaded application running isn't going to do it I'm afraid. While the code at the far end may have multi-instance or single instance capability, you are calling it from a sequential loop.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
so do i have to execute my client.exe 5 times by double clicking on it . Please can u help me in checking the concurrency
Pete O'Hanlon wrote: you need to have more than one thing attempting to hit the same code at the same time
Above how can i do ??
|
|
|
|
|
When a request is send to service , then it means it comes in the form of thread . for ex
suppose,
MyService ser=new Myservice()
for(int i=0;i<5;i++)
{
ser.callMethod();
}
then do the above code comes as 5 seperate threads to service or if i click on client.exe 5 times then it comes as 5 thread ?
|
|
|
|
|
After working in Visual Studio 2008 with SP1 on my application, everything works sweet with visifire charts.
I then create an install for my application and deploy it to a seperate machine. Charts do not work, and we get system.exception with Eventype:clr20r3
Can visifire be run without VS 2008? I don't expect to install VS 2008 SP1 on every install instance of my app with visifire.
I'm using WPF, and am creating the chart dynamically through code. I'm using the latest stable/non-beta version of visifire, v2.1
|
|
|
|
|
|
Hi,
I have install the Microsoft .NET Framework 3.5 in the client machine but the application have a same error (system.exception).
Please i really need your help to fix this problem.
Regards
CUTUDI Didier
|
|
|
|
|
Do you have .NET 3.5 SP1 installed on that machine? Is it a different targettype than yours, e.g. you're running 32 bit and it's 64 bit?
What's the full event message?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
The error generate by Windows is :
The Eventype is clr20r3 P4:wpfvisfire.charts P5: 2.3.5.0
The error is system.exception. I run the application in 32bits processor. And i have make my software for 32bits processor.
modified on Wednesday, December 16, 2009 10:07 AM
|
|
|
|