using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using Views;
using System.Threading;
using Community;
using System.IO;
using System.Windows;
using System.Net.Sockets;
using System.Windows.Controls;
namespace ViewModel.Robots
{
public class QkmRobotVM : FeiYuRobotVM
{
///
/// 上报异常的委托事件
///
public override event delegeateExcep eventExcepReport;
///
/// 刷新阵列点位
///
public override event ShuaxinPoint ShuaxinPointing;
#region 机器人控制器返回信息
private string connectionStatus;
///
/// 机器人控制器返回信息
///
public string ConnectionStatus
{
get { return connectionStatus; }
set
{
connectionStatus = value;
this.RaisePropertyChanged("ConnectionStatus");
}
}
#endregion
///
/// 交互返回信息
///
public string RCVInfo { get; set; }
#region 机器人连接
private bool robotConn;
///
/// 机器人连接
///
public bool RobotConn
{
get { return robotConn; }
set
{
robotConn = value;
if (value)
{
string sendstr = string.Format("[{0}#{1}]",5, "System.Login 0");
//Encoding.Default.GetBytes(sendstr);
//SendControl(Encoding.Default.GetBytes(sendstr));
SendControl(sendstr);
}
else
{
if (RobotStart)
{
ServoOn = false;
RobotStart = false;
}
// SendControl("$Logout\r\n");
}
this.RaisePropertyChanged("RobotConn");
}
}
#endregion
#region 启动机器人开关
private bool robotStart;
///
/// 启动机器人开关
///
public bool RobotStart
{
get { return robotStart; }
set
{
robotStart = value;
if (MyThread != null)
{
if (value)
{
// SendControl("$Start,0\r\n");
string sendstr = string.Format("[{0}#{1}]", 6, "Thread.Start");
SendControl(sendstr);
}
else
{
// SendControl("$Stop\r\n");
string sendstr = string.Format("[{0}#{1}]", 7, "Thread.Abort");
SendControl(sendstr);
}
}
this.RaisePropertyChanged("RobotStart");
}
}
#endregion
#region 使能开关
private bool servoOn;
///
/// 使能开关
///
public bool ServoOn
{
get { return servoOn; }
set
{
servoOn = value;
this.RaisePropertyChanged("ServoOn");
if (RobotConn)
{
if (value)
{
string sendstr = string.Format("[{0}#{1}]", 3, "Robot.PowerEnable 1,1");
SendControl(sendstr);
ConnectionStatus = "开启工作模式";
}
else
{
string sendstr = string.Format("[{0}#{1}]", 3, "Robot.PowerEnable 1,0");
SendControl(sendstr);
ConnectionStatus = "关闭工作模式";
}
}
}
}
#endregion
#region 机器人重置
///
/// 机器人重置
///
///
public override void Reset(object obj)
{
//SendControl("$Reset\r\n");
string sendstr = string.Format("[{0}#{1}]", 9, "System.ClearVariables");
SendControl(sendstr);
}
#endregion
#region 构造函数
///
/// 构造函数
///
public QkmRobotVM(MachineModel machine)
{
MyWindow = new Robot();
MyWindow.DataContext = this;
MachineObj = machine;
ResetCommand = new DelegateCommand();
ResetCommand.ExecuteAction = new Action