using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Curtain.Net.Sockets.PLC.Model.Melsec
{
///
/// SimpleSocketClientModel ASCII码
///
public class SimpleSocketClientModel : ClientModel
{
#region client
///
/// 接收超时时间(毫秒)
///
public override int ReceiveTimeout => 5000;
///
/// 发送超时时间(毫秒)
///
public override int SendTimeout => 3000;
///
/// 响应报文-头长度
///
public override int HeadLength => 4;
///
/// 根据响应报文-头,计算响应报文-文本长度
///
/// 报文
/// 响应报文-文本长度
public override int GetContentLength(PLCMessage m)
{
return 0;
}
///
/// 验证响应报文-头
///
/// 报文
/// 是否通过
public override bool CheckHead(PLCMessage m)
{
if (m == null || m.HeadBytes == null || m.HeadBytes.Length != HeadLength)
{
return false;
}
return true;
}
///
/// 命令报文转换为发送字节
///
/// 命令报文
/// 发送字节
public override byte[] ToSendFromCommand(string command)
{
if (string.IsNullOrEmpty(command))
{
return null;
}
return Encoding.ASCII.GetBytes(command);
}
///
/// 接收字节转换为响应报文
///
/// 接收字节
/// 响应报文
public override string ToResponseFromReceive(byte[] receive)
{
if (receive == null || receive.Length == 0)
{
return null;
}
return Encoding.ASCII.GetString(receive);
}
#endregion
#region Value
#endregion
#region SendMessage
///
/// 获取发送命令报文
///
///
///
public override PLCMessage GetSendMessage(string value)
{
PLCMessage plc_m = new PLCMessage(PLCMessageType.Send)
{
Value = value,
Length = 1,
};
plc_m.Command = "@" + value + "$";
plc_m.CommandBytes = ToSendFromCommand(value);
return plc_m;
}
#endregion
}
}