60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using S7.Net;
|
|
|
|
namespace Test_S7
|
|
{
|
|
public partial class TestMainForm : Form
|
|
{
|
|
public TestMainForm()
|
|
{
|
|
InitializeComponent();
|
|
|
|
myInit();
|
|
}
|
|
/// <summary>
|
|
/// inizializzo
|
|
/// </summary>
|
|
private void myInit()
|
|
{
|
|
CpuType tipoCpu = CpuType.S71200;
|
|
short slot = 0;
|
|
short rack = 0;
|
|
// leggo selezione...
|
|
try
|
|
{
|
|
tipoCpu = (CpuType)cbCpuType.SelectedValue;
|
|
short.TryParse(txtSlot.Text, out slot);
|
|
short.TryParse(txtRack.Text, out rack);
|
|
}
|
|
catch
|
|
{ }
|
|
if (txtIP.Text != "" && rack >= 0 && slot >= 0)
|
|
{
|
|
using (var plc = new Plc(tipoCpu, txtIP.Text, rack, slot))
|
|
{
|
|
plc.Open();
|
|
|
|
// test lettura area indicata... SOLO 1 elemento ATTENZIONE legge tutti U (unsigned) e poi andrebbero convertiti ushort --> convertToShort, uint --> convertToDouble/ConvertToInt
|
|
var memRead= plc.Read(txtMemArea.Text);
|
|
txtOut.Text = string.Format("-------------------------------------------{0}", Environment.NewLine);
|
|
txtOut.Text+= string.Format("- READ FIRST BLOCK{0}", Environment.NewLine);
|
|
txtOut.Text += string.Format("-------------------------------------------{0}", Environment.NewLine);
|
|
txtOut.Text += memRead.ToString();
|
|
txtOut.Text += Environment.NewLine;
|
|
txtOut.Text += string.Format("-------------------------------------------{0}", Environment.NewLine);
|
|
txtOut.Text += string.Format("{0}{0}{0}",Environment.NewLine);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|