Test
This commit is contained in:
@@ -12,17 +12,47 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using S7.Net;
|
||||
|
||||
namespace C__WPF_Test_Siemens
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private Plc _plc;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Verbindung zur SPS aufbauen
|
||||
_plc = new Plc(CpuType.S71500, "192.168.0.1", 0, 1); // IP, Rack, Slot
|
||||
}
|
||||
|
||||
private void StartButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_plc.Open();
|
||||
|
||||
if (_plc.IsConnected)
|
||||
{
|
||||
// Beispiel: schreibe die Ganzzahl 1 in Datenbaustein 1, DBW 0
|
||||
_plc.Write("DB1.DBW0", (short)1);
|
||||
|
||||
MessageBox.Show("Wert wurde erfolgreich geschrieben!", "Erfolg", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Verbindung fehlgeschlagen!", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Fehler: " + ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_plc.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user