68 lines
2.0 KiB
C#
68 lines
2.0 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;
|
|
|
|
namespace SLC1_N
|
|
{
|
|
public partial class Form_PLC_TCP : Form
|
|
{
|
|
public Form_PLC_TCP()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form_PLC_TCP_Load(object sender, EventArgs e)
|
|
{
|
|
tb_PLC_IP.Text = Form1.f1.HCPLC_client.IPAddress;
|
|
tb_PLC_Port.Text = Form1.f1.HCPLC_client.Port.ToString();
|
|
|
|
if (Form1.f1.HCPLC_client.Connected)
|
|
bt_PLC_Connect.Enabled = false;
|
|
}
|
|
|
|
private void bt_PLC_Connect_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (Form1.f1.HCPLC_client.Connected)
|
|
Form1.f1.HCPLC_client.Disconnect();
|
|
|
|
Form1.f1.HCPLC_client.Connect(tb_PLC_IP.Text, Convert.ToInt32(tb_PLC_Port.Text));
|
|
|
|
//Form1.f1.HCPLC_client.Connect();
|
|
|
|
if (Form1.f1.HCPLC_client.Connected)
|
|
{
|
|
Form1.f1.HCPLC_client.IPAddress = tb_PLC_IP.Text;
|
|
Form1.f1.HCPLC_client.Port = Convert.ToInt32(tb_PLC_Port.Text);
|
|
|
|
var jsconfig = new JsonConfig("config.json");
|
|
|
|
jsconfig.SetValue("PLC_IP", tb_PLC_IP.Text);
|
|
jsconfig.SetValue("PLC_Port", Convert.ToInt32(tb_PLC_Port.Text));
|
|
|
|
bt_PLC_Connect.Enabled = false;
|
|
MessageBox.Show("连接成功!");
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void bt_PLC_disconnect_Click(object sender, EventArgs e)
|
|
{
|
|
if (Form1.f1.HCPLC_client.Connected)
|
|
Form1.f1.HCPLC_client.Disconnect();
|
|
bt_PLC_Connect.Enabled = true;
|
|
}
|
|
}
|
|
}
|