|
We are building a WPF project to control a machine. The machine is controlled by a PLC, and link to the PLC is with OPC.
The update from the PLC is done via reflexion, so the 'set' is called, but the disadvantage of this is that the value is written to the PLC again via 'SetValueToPlc()' see example.
The easy solution would be to copy all properties with a Write to PLC variant, but since our project already contains more than 2000 properties this is not the prefered solution.
The way I'm thinking is to make use of a template like the Nullable, and create 2 separate 'setters'. One which is coupled to the ViewModel for updates from the View and business-logic. And the other can be use by the OPC updates (reflection). The implementation from the last would be without writing the value back to the PLC.
So my question is how to make such a template, or are there other sugestions?
Example property:
[OpcItem("Simulate")]
public Boolean Simulate
{
get { return _simulate; }
set
{
_simulate = value;
SetValueToPlc(MethodBase.GetCurrentMethod().MethodHandle, value);
RaisePropertyChanged();
}
}
|
|
|
|
|
If you're worried about "redundant updates to the PLC", you should start by checking for a "value change" in the setter instead of blindly using the value.
|
|
|
|
|
The problem is when a value is only changed shortly in the plc. Eg a reset, goes to True, and the next cyclus is reset to false. The value true is set to the OPC point (old value was false, so this is updated to true, en send to the PLC again. But the plc already handled this True, so it will get an other reset (was already false and is reset to true). So one reset will lead to a second reset.
The update rate of OPC is slower than the PLC so this will stop after the second.
|
|
|
|
|
If I'm dealing with devices / services / threads that operate at different speeds but need to be "synchronized" somehow, I may use a "queue".
One "device" adds to the queue; the "other" takes from the queue.
If the queue may "overflow", then a method is formulated to remove "redundant" queue entries without processing them; e.g. false -> true -> false.
With "temperature" PLC's for example, I only need to be aware of when the temperature "changes" (as when plotting over time).
|
|
|
|
|
Hi Gerry,
Thank you for thinking with me here. Your solution works fine for keeping the right last value, i agree with that. But since it's a 2 way channel, I need to prevent the write back. So in my excample, when the PC 'Reset' is set to true, the plc -> true (after proccessing goed to false), this false is set to the PC. And all is fine.
But is the PLC internal set to True (internally is reset to false), -> PC receives True, and set's the reset to True again in the PLC. This last set is the one I try to prevent, The set is done via OPC reflection, so I should be able to distiguage this from an update from the ViewModel.
|
|
|
|
|
Yes; you can probably determine who called the setter by accessing the previous StackFrame(s) in the setter. Add the check to the "property changed" delegate; e.g.
StackFrame stackFrame = new StackFrame( 2, false );
MethodBase methodBase = stackFrame.GetMethod();
string source = string.Format( "{0}.{1}()", methodBase.DeclaringType.Name, methodBase.Name );
|
|
|
|
|
Never use the StackFrame like this. It has a disturbing habit of behaving differently between debug and release mode. It also behaves erratically if you have yield or await above the in the call chain.
This space for rent
|
|
|
|
|
It's a sample call.
I actually "walk" the stack; but including the code for that would cloud the original question; like your comment.
|
|
|
|
|
Thanks Gerry and Pete,
This might work, but requeres a lot of code in all my properties. Thats why I prefeur a solution with a second set methode. Analog to the get/set implementation of a Nullable.
|
|
|
|
|
Why does it require "a lot of code in all my properties"?
You're calling "Property Changed" anyway; add any "extra" code in there.
Then there's reflection; you've already used it in one instance.
|
|
|
|
|
He Gerry,
I misread your proposal. I think this could work as we. I'll try this and let you know.
Thanks for your aid!
|
|
|
|
|
I have an WPF XAML application where I need to capture a portion of the page and send it to the printer. I have gone through the Microsoft print dialog control reference and see how I can save an xps formatted document then load it into the print dialog and send it to the printer. Now I have read an article indicating that all I have to do is create a FixedDocument and bind my values to it's datacontext and then save the completed FixedDocument, reload it and send it to the pring dialog as an xps file which is what I want. The fixed page XAML is shown below:
<FixedDocument
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xml:lang="en-au">
<FixedDocument.Resources>
<BooleanToVisibilityConverter x:Key="visConverter"/>
</FixedDocument.Resources>
<PageContent>
<FixedPage Width="793.76" Height="1122.56">
<!-- Page 1 Begins Here -->
<StackPanel Margin="50">
<Border BorderThickness="5" BorderBrush="Gray" CornerRadius="10"
Padding="20" Width="690">
<StackPanel Orientation="Horizontal" Margin="0 0 0 0">
<Image Source="truck.jpg" HorizontalAlignment="Left"/>
<TextBlock Margin="30 0 0 0" FontSize="50"
Text="{Binding Path=Heading}" VerticalAlignment="Center"/>
</StackPanel>
</Border>
<TextBlock Margin="0 30 0 0"
Text="{Binding Path=CurrentDate, StringFormat='{}{0:d MMMM yyyy}'}"/>
<TextBlock Margin="0 30 0 0"
Text="{Binding Path=Name, StringFormat='Dear {0},'}" />
<ItemsControl Margin="30 20 0 0" ItemsSource="{Binding Path=DotPoints}"
HorizontalAlignment="Left">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,8,0,0" Orientation="Horizontal" >
<TextBlock Text="• " />
<TextBlock Text="{Binding}" TextWrapping="Wrap" Width="400"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Margin="0 30 0 0"
Text="Congratulations, you are entitled to a 50% discount!"
Visibility="{Binding Path=GiveDiscount,
Converter={StaticResource visConverter}}"/>
</StackPanel>
</FixedPage>
</PageContent>
<PageContent>
<FixedPage Width="793.76" Height="1122.56">
<!-- Page 2 Begins Here -->
<TextBlock Margin="50" Text="Nothing to see here."/>
</FixedPage>
</PageContent>
</FixedDocument>
Now when I try to add XAML to the page I get an error: Property 'pages' does no support a value of type 'PageContent.
Now I tried a different approach. Now to resolve this I have reviewed many articles until I came to one that looks like it will do the trick but it gives me an error as well. What error I get is it can not convert a FixedPage to an UIElement. The code is below:
<Window
x:Class="ODIN.DataSheetFixedDocument"
WindowStartupLocation="CenterScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:ODIN.View"
xmlns:local="clr-namespace:ODIN"
local:WindowCustomizer.CanMaximize="False"
local:WindowCustomizer.CanMinimize="False"
Title="Administrated Master View"
Width="1024"
Height="768"
>
<Grid Name="MainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="97*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="115*" />
</Grid.RowDefinitions>
<FixedPage Width="1024" Height="768" x:Name="theFixedPage">
<StackPanel Background="Green" Width="200" Height="30" HorizontalAlignment="Left" Margin="0,100,0,0" Grid.Column="0" Grid.Row="0">
<TextBlock Width="465" HorizontalAlignment="Left" Height="92" Foreground="Black" Margin="0,0,-265,0">Hello</TextBlock>
</StackPanel>
</FixedPage>
<DocumentViewer>
<FixedDocument x:Name="uiFixedDocument">
</FixedDocument>
</DocumentViewer>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace ODIN
{
public partial class DataSheetFixedDocument : Window
{
public DataSheetFixedDocument()
{
InitializeComponent();
Grid grid = new Grid();
grid = (Grid)this.theFixedPage.Parent;
grid.Children.Remove(this.theFixedPage);
PageContent pageContent = new PageContent();
pageContent.Child = theFixedPage;
FixedDocument.Pages.Add(pageContent);
uiFixedDocument.Pages.Add(pageContent);
grid.Children.Add((UIElement) uiFixedDocument);
}
}
}
Now if I don't try to add it to the Grid it runs but my FixedPage does not display.
If anyone can see what I'm doing wrong help would be great.
modified 5-Oct-16 14:18pm.
|
|
|
|
|
I came up with an easy solution. Because I am only printing the XAML page that is being displayed, except for a few areas that I can collapse, here is what I did. On the XAML page it has a print stackpanel with the print button and header text I need to remove. After collapsing these elements I just use the PrintDialog PrintVisual(MainPageGrid, "Title"); method.
|
|
|
|
|
Hi,
That's really frustrating, some days ago I felt on a tutorial page on how to animate grids (or contentcontrol...I don't remember).
...and now that I need this page I can't find it again
There was an illustration like this (light blue squares)
http://i.imgur.com/PzcdoVs.png[^]
The principle being to animate scale in/out for centered object and opacity in/out for first and last object
Would you by chance see the page I'm referring to? (or at least lead me to a similar article!)
Thanks a lot!!
|
|
|
|
|
Try searching your browser history.
|
|
|
|
|
I don't have access anymore to the computer (school) I used at the time!
|
|
|
|
|
Then you will need to search the articles section for yourself.
|
|
|
|
|
Hi All,
I have created the Virtual Directory on the Server and copied all .exe, xbap and manifest files, when trying to access the xbap application, I'm getting the following error. Please help me what steps am I missing in deploying the application.
Here is the Error log message
PLATFORM VERSION INFO
Windows : 6.1.7601.65536 (Win32NT)
Common Language Runtime : 4.0.30319.42000
System.Deployment.dll : 4.6.118.0 built by: NETFXREL3STAGE
clr.dll : 4.6.1076.0 built by: NETFXREL3STAGE
dfdll.dll : 4.6.118.0 built by: NETFXREL3STAGE
dfshim.dll : 4.0.41209.0 (Main.041209-0000)
SOURCES
Deployment url : <a href="http://localhost/WPFBrowserApplication/WpfBrowserApplication12015.xbap">http:
Application url : <a href="http://localhost/WPFBrowserApplication/WpfBrowserApplication12015.exe.manifest">http:
IDENTITIES
Deployment Identity : WpfBrowserApplication12015.xbap, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c836e075e9e59aa1, processorArchitecture=msil
Application Identity : WpfBrowserApplication12015.exe, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c836e075e9e59aa1, processorArchitecture=msil, type=win32
APPLICATION SUMMARY
* Online only application.
* Browser-hosted application.
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* An exception occurred while downloading the application. Following failure messages were detected:
+ Downloading <a href="http://localhost/WPFBrowserApplication/WpfBrowserApplication12015.exe.deploy">http:
+ The remote server returned an error: (404) Not Found.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
No phase information is available.
ERROR DETAILS
Following errors were detected during this operation.
* [9/18/2016 8:02:15 PM] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
- Downloading <a href="http://localhost/WPFBrowserApplication/WpfBrowserApplication12015.exe.deploy">http:
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
at System.Deployment.Application.DownloadManager.DownloadDependencies(SubscriptionState subState, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, String targetDirectory, String group, IDownloadNotification notification, DownloadOptions options)
at System.Deployment.Application.DeploymentManager.SynchronizeCore(Boolean blocking)
at System.Deployment.Application.DeploymentManager.SynchronizeAsyncWorker()
- Inner Exception -
System.Net.WebException
- The remote server returned an error: (404) Not Found.
- Source: System
- Stack trace:
at System.Net.HttpWebRequest.GetResponse()
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.
I am searching and asking with friends and colleagues, any type of help is appreciated maybe a code snippet, a link or even a suggestions help. Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
indian143 wrote: The remote server returned an error: (404) Not Found.
Either your files do not exist on your server, or you haven't configured the MIME type for them.
MIME Types for ClickOnce deployment | RobinDotNet's Blog[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I tried but I don't know how to install mime types on a Virtual Directory or Web Application, I found some vbs code I saved and ran it to install Mime types, it gave me error.
So far I couldn't find how to install MIME types, can you please help me with that?
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Did you read the blog post I linked to? It has links to Microsoft's instructions for setting up MIME types in IIS.
Instructions for setting up MIME types in IIS6:
Configure MIME Types (IIS 6.0)[^]
Instructions for setting up MIME types in IIS7 (or later):
Configuring MIME Types in IIS 7[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I installed all those Mime types on my Server, still I am getting the same error, can you please give me some suggestion about it?
I have copied .exe file, .manifest file and .xbap file from bin directory of the application into Virtual Directory, am I missing anything here? Do I need to have .deploy file etc?
I followed all the steps that are provided here : GADS Open Source[^]
If I'm missing something please let me know, any help is greatly appreciated. Thanks my friend .
Still I am getting the following Error:
PLATFORM VERSION INFO
Windows : 6.1.7601.65536 (Win32NT)
Common Language Runtime : 4.0.30319.42000
System.Deployment.dll : 4.6.1055.0 built by: NETFXREL2
clr.dll : 4.6.1076.0 built by: NETFXREL3STAGE
dfdll.dll : 4.6.1055.0 built by: NETFXREL2
dfshim.dll : 4.0.41209.0 (Main.041209-0000)
SOURCES
Deployment url : http://localhost/WpfBrowserApplication12015/WpfBrowserApplication12015.xbap
Application url : http://localhost/WpfBrowserApplication12015/WpfBrowserApplication12015.exe.manifest
IDENTITIES
Deployment Identity : WpfBrowserApplication12015.xbap, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c836e075e9e59aa1, processorArchitecture=msil
Application Identity : WpfBrowserApplication12015.exe, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c836e075e9e59aa1, processorArchitecture=msil, type=win32
APPLICATION SUMMARY
* Online only application.
* Browser-hosted application.
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* An exception occurred while downloading the application. Following failure messages were detected:
+ Downloading http://localhost/WpfBrowserApplication12015/WpfBrowserApplication12015.exe.deploy did not succeed.
+ The remote server returned an error: (404) Not Found.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
No phase information is available.
ERROR DETAILS
Following errors were detected during this operation.
* [9/20/2016 2:25:44 PM] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
- Downloading http://localhost/WpfBrowserApplication12015/WpfBrowserApplication12015.exe.deploy did not succeed.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
at System.Deployment.Application.DownloadManager.DownloadDependencies(SubscriptionState subState, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, String targetDirectory, String group, IDownloadNotification notification, DownloadOptions options)
at System.Deployment.Application.DeploymentManager.SynchronizeCore(Boolean blocking)
at System.Deployment.Application.DeploymentManager.SynchronizeAsyncWorker()
- Inner Exception -
System.Net.WebException
- The remote server returned an error: (404) Not Found.
- Source: System
- Stack trace:
at System.Net.HttpWebRequest.GetResponse()
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified 20-Sep-16 17:32pm.
|
|
|
|
|
indian143 wrote: Downloading http://localhost/WpfBrowserApplication12015/WpfBrowserApplication12015.exe.deploy did not succeed.
- The remote server returned an error: (404) Not Found.
Either the .deploy file does not exist in that path on your server, or you didn't configure the MIME type for .deploy files.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I configured .deploy mime type on the IIS Rick not able figure it out my friend, still checking, Silverlight Application is working on the same IIS, only WPF browser app is not working.
Do I need to set up anything in the App Config file any properties etc.? Do I need to put some Certificate related information on the Config file? I am not sure - I have been searching my friend. That one little thing can keep my Work going - thanks for coming up to help me my friend.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
If you request http://localhost/WpfBrowserApplication12015/WpfBrowserApplication12015.exe.deploy in your web browser, do you get the file, or do you get an error?
If you get an error, try using failed request tracing[^] to diagnose the problem.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|