What are the simplest streams in Infosys
Example machine with Microsoft Expression Blend in the Microsoft Windows Vista Media Center
Microsoft Expression Blend is a program for creating program interfaces for C # and Visual Basic. In this example, a user interface created with the program is connected to the example Machine and then integrated into the Vista Media Center. The programming language Visual Basic is used for this.
Target platform- Windows Vista
implementation- Visual Basic
- Microsoft .NET Framework Version 3.0, more here
- Microsoft Expression Blend, more here
- Microsoft Visual Studio 2005
- Microsoft Windows Vista Media Center
- Microsoft Windows SDK for .Net Framework 3.0, more here
- Microsoft Visual Studio 2005 extensions for .Net Framework 3.0 (November 2006 CTP), more here
- TwinCAT 2.10
- Notepad or any other text editor
The first steps ...Step by step, you will learn how to develop a program with Microsoft Visual Studio and Microsoft Expression Blend and how to integrate the TwinCAT ADS .NET component using an example and then integrate this into the Vista Media Center.
1. Create a new project:
Start Microsoft Visual Studio and create a new XAML browser application. To do this, go to the menu under 'File -> New -> Project ...'. The 'New Project' dialog box opens. First select the project type: 'Project types -> Visual Basic -> Net Framework 3.0'. The templates of the project type then appear on the right. There select 'XAML Browser Application'. You now give your project a name, in this case 'Machine' and define the location.
2. Create user interface
Now switch to Microsoft Expression Blend, where you open the project you just created in order to create the user interface there.
In the upper left area you can see the two outputs that are also output on the Bus Terminals. The variable that counts the workpieces is shown at the bottom left. On the right, you can use the 'Speed' field to change the cycle speed of the motor. The 'Steps' display corresponds to the number of cycles that are output on output 1.
If you want the user interface to constantly adjust its size, copy the top grid and then insert a viewbox instead of the grid. Now insert the grid into this viewbox. Now all you have to do is set the size of the page, the viewbox and the grid to 'Auto'. This can lead to a shift of elements. You then have to reposition them. Make sure that you do not set the size of the page, the viewbox and the grid again.
3. Add reference
After creating the interface, a reference called 'TwinCAT.Ads.dll' must first be added. This can be done in Visual Studio as well as in Expression Blend. In both cases you go through the menu under 'Project -> Add Reference'.
4. Security clearanceGo to the menu under 'Project ->
A tab will now open in which you can define the project properties. Go to 'Security' and select 'this is a full trust application'.
5. Edit the source textNow you can start creating the source code in C #.
The required namespaces 'System.IO' and 'TwinCAT.Ads' are inserted in the top line of the source text.
Imports System.IO imports TwinCAT.Ads
This is followed by the declarations.Private hEngine As Integer Private hDeviceUp As Integer Private hDeviceDown As Integer Private hSteps As Integer Private hCount As Integer Private hSwitchNotify As Integer Private hSwitchWrite As Integer Private tcClient As TwinCAT.Ads.TcAdsClient Private dataStream As TwinCAT.Ads.AdsStream Private binReader .BinaryReader
The first method is the 'Load' method. Instances of different classes are created in it and a connection to port 801 is established.Private Sub Page1_Loaded (ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded Try 'Create a new instance of the AdsStream class' Create a new instance of the AdsStream class dataStream = New AdsStream (7)' A new one Create an instance of the BinaryReader class 'Create a new instance of the BinaryReader class binReader = New BinaryReader (dataStream)' Create a new instance of the TcAdsClient class 'Create a new instance of the TcAdsClient class tcClient = New TwinCAT.Ads.TcAdsClient ()' Connect with local PLC runtime 1 - Port 801 'Connecting to local PLC - Runtime 1 - Port 801 tcClient.Connect (801) Catch MessageBox.Show ("Error while loading") End Try ...
Then the variables are linked in the 'Load' method and linked with a method (which still has to be written), which is called when a variable is changed.Try 'Initializing the monitoring of the PLC variables' Initializing the monitoring of the PLC variables hEngine = tcClient.AddDeviceNotification (". Engine", dataStream, 0, 1, AdsTransMode.OnChange, 10, 0, DBNull.Value) hDeviceUp = tcClient. AddDeviceNotification (". DeviceUp", dataStream, 1, 1, AdsTransMode.OnChange, 10, 0, DBNull.Value) hDeviceDown = tcClient.AddDeviceNotification (". DeviceDown", dataStream, 2, 1, AdsTransMode.OnChange, 10, 0, DBNull.Value) hSteps = tcClient.AddDeviceNotification (". Steps", dataStream, 0, 1, AdsTransMode.OnChange, 10, 0, DBNull.Value) hCount = tcClient.AddDeviceNotification (". Count", dataStream, 4, 2, AdsTransMode.OnChange, 10, 0, DBNull.Value) hSwitchNotify = tcClient.AddDeviceNotification (". Switch", dataStream, 6, 1, AdsTransMode.OnChange, 10, 0, DBNull.Value) 'Get the handle of "switch" - is required for writing the value 'Getting the handle for "switch" - needed for writing the value hSwitchWrite = tcClient.CreateVariableHandle (". switch") 'Creating an event for changes to the PLC variable values' Creating an event for changes of the PLC variable valuesAddHandler tcClient.AdsNotification , AddressOf tcClient_OnNotification Catch MessageBox.Show ("Error when connecting") End Try End Sub
6. DefinitionConnect PLC variables:
The AddDeviceNotification method was used to connect the variables.
public int AddDeviceNotification (string variableName, AdsStream dataStream, int offset, int length, AdsTransMode transMode, int cycleTime, int maxDelay, object userData);
- variableName: Name of the PLC variable.
- dataStream: The data stream that will receive the data.
- offset: Distance in the data stream.
- length: Length in the data stream.
- transMode: The event when the variable changes.
- cycletime: The time (in ms) after which the PLC server checks whether the variable has changed.
- maxDelay: The time (in ms) after which the event has ended at the latest.
- userData: The object that can be used to hold certain data.
The method CreateVariableHandle was used to connect the variable 'hSwitchWrite'.int TcAdsClient.CreateVariableHandle (string variableName);
- variableName: Name of the PLC variable.
7. Write method:A method has already been referred to above that does not yet exist. Therefore, this method called 'tcClient_OnNotification' is written next. This method is called when one of the PLC variables has changed.
'------------------------------------------------' is called when a PLC variable changes 'is activated when a PLC variable changes' --------------------------------- --------------- Private Sub tcClient_OnNotification (ByVal sender As Object, ByVal e As AdsNotificationEventArgs) Try 'Setting the position of e.DataStream to that of the currently required value' Setting the position of e .DataStream to the position of the current needed value e.DataStream.Position = e.Offset 'Determining which variable has changed' Detecting which variable has changedIf (e.NotificationHandle = hDeviceUp) Then'Adjust the colors of the graphics according to the variable ' Adapt colors of graphics according to the variablesIf (binReader.ReadBoolean () = True) Then DeviceUp_LED.Foreground = New SolidColorBrush (Colors.Red) Else DeviceUp_LED.Foreground = New SolidColorB rush (Colors.White) End If ElseIf (e.NotificationHandle = hDeviceDown) Then If (binReader.ReadBoolean () = True) Then DeviceDown_LED.Foreground = New SolidColorBrush (Colors.Red) Else DeviceDown_LED.Foreground = New SolidColorBrite ) End If ElseIf (e.NotificationHandle = hSteps) Then 'Setting the ProgressBar to the current step prgSteps.Value = (binReader.ReadByte () * 4) ElseIf (e.NotificationHandle = hCount) Then 'Displaying the "count" value' Displaying the "count" value lblCount.Content = binReader.ReadUInt16 (). ToString () ElseIf (e.NotificationHandle = hSwitchNotify) Then 'Marking the correct RadioButton' Checking the correct RadioButtonIf (binReader. ReadBoolean () = True) Then optSpeedFast.IsChecked = TrueElse optSpeedSlow.IsChecked = True End If End If Catch MessageBox.Show ("Error") End Try End Sub Two methods are still missing with which the speed of the machine can be set. A virtual switch is thrown in you, here a value is written into the PLC variable switch. '------------------------------------------------- ----- 'is called when the' fast 'field is marked' is activated when the 'fast' field is marked '--------------------- --------------------------------- Private Sub optSpeedFast_Click (ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs ) Handles optSpeedFast.Click Try tcClient.WriteAny (hSwitchWrite, True) Catch MessageBox.Show ("Error") End Try End Sub '---------------------- -------------------------------- 'is called when the field' slow 'is marked' is activated when the ' slow 'field is marked' -------------------------------------------- ---------- Private Sub optSpeedSlow_Click (ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles optSpeedSlow.Click Try tcClient.WriteAny (hSwitchWrite, False) Catch MessageBox.Show ("Error") End Try End Sub
8. Delete notifications and handles:In the Close event of the window, the connections are released again with the DeleteDeviceNotification () method.
// ------------------------------------------------ ------ // is called when ending the program // is activated when ending the program // -------------------------- ---------------------------- Private Sub Page1_Unloaded (ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Unloaded Try 'Deleting the Notifications and Handles' Deleting of the notifications and handles tcClient.DeleteDeviceNotification (hEngine) tcClient.DeleteDeviceNotification (hDeviceUp) tcClient.DeleteDeviceNotification (hDeviceDown) tcClient.DeleteDeviceNotification (hcClient.DeleteDeviceNotification (hcClientNotify) tcClient.DeleteVariableHandle (hSwitchWrite) Catch MessageBox.Show ("Error") End Try tcClient.Dispose () End Sub
The PLC machine program Machine_Final.pro must run on runtime system 1 and the program can be tested in Internet Explorer 7.
9. Integration into the Vista Media CenterIf you have tested your project adequately and have not found any errors, you can now integrate it into the media center.
Go back to the project properties in Visual Studio, but then go to 'Publish'. Then click on 'Publish Now'. The xbap file will now be created, which you will later call up in the media center. You must always do this step if you have changed your program and the change should also be adopted in the Media Center.
Now go to a text editor, e.g. Notepad and enter the following:
<application URL = "C:\Users\<User>\Documents\Visual Studio 2005\Projects\Machine\Machine\Publish\Machine.xbap"> </application>
Save it to: 'C: \ Users \
This is the simplest form of integration into the Windows Vista Media Center. Further information on integration into the media center can be found here.
10. Download Expression Blend example:
- When did Jainism find
- Has Hassan Nisar right to criticize Pakistan?
- What do you think of teenagers kissing
- How is Raj Thackeray personally
- Why is Mexico sparsely populated
- What does Chettathi mean in Malayalam
- What are the main causes of terrorism
- Why do some animals abandon their offspring
- Why did Modi bankrupt ONGC
- What's strange about your teacher
- Will West Bengal ever change?
- What are different areas in computer science
- Does Washington DC have any cities
- Should I study environmental science or biology?
- What are the types of movies
- What do you mean by religion Dharma
- What are some scientifically proven diet plans
- Why is Rajnikanth considered so great
- How do IAS IPS employees choose CADRE
- What are the benefits of sustainable agriculture
- The Pakistani military is more powerful than India
- Why do koi fish eat goldfish
- Why is Ireland biased against Israel
- Is NCERT books are difficult