using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using static RFIDReaderJilin.Common.LedDll;
namespace RFIDReaderJilin.Common
{
class LEDHelper
{
///
/// 刷新任务信息
///
/// 串口编号,如设备管理器里显示为 COM3 则此处赋值 3
/// 标签数量
///
public static string RefreshCount(string Commport,string taskName,string code)
{
LedDll.COMMUNICATIONINFO CommunicationInfo = GetCommunicationInfo(Commport);
int nResult = LedDll.LV_RefreshNeiMaArea(ref CommunicationInfo, GetTagsCountRefreshString(taskName,code));//发送,见函数声明注示
if (nResult != 0)//如果失败则可以调用LV_GetError获取中文错误信息
{
string ErrStr;
ErrStr = LedDll.LS_GetError(nResult);
return ErrStr;
}
else
{
return "刷新成功(Refresh successfully)";
}
}
///
/// 获取连接信息
///
/// 串口编号,如设备管理器里显示为 COM3 则此处赋值 3
///
public static LedDll.COMMUNICATIONINFO GetCommunicationInfo(string LedIp)
{
LedDll.COMMUNICATIONINFO CommunicationInfo = new LedDll.COMMUNICATIONINFO();//定义一通讯参数结构体变量用于对设定的LED通讯,具体对此结构体元素赋值说明见COMMUNICATIONINFO结构体定义部份注示
CommunicationInfo.LEDType = 0;
//TCP通讯********************************************************************************
CommunicationInfo.SendType = 0;//设为固定IP通讯模式,即TCP通讯
CommunicationInfo.IpStr = LedIp;//给IpStr赋值LED控制卡的IP
CommunicationInfo.LedNumber = 1;//LED屏号为1,注意socket通讯和232通讯不识别屏号,默认赋1就行了,485必需根据屏的实际屏号进行赋值
//广播通讯********************************************************************************
//CommunicationInfo.SendType=1;//设为单机直连,即广播通讯无需设LED控制器的IP地址
//串口通讯********************************************************************************
//CommunicationInfo.SendType = 2;//串口通讯
//CommunicationInfo.Commport = Commport;//串口的编号,如设备管理器里显示为 COM3 则此处赋值 3
//CommunicationInfo.Baud = 57600;//波特率
//CommunicationInfo.LedNumber = 1;
return CommunicationInfo;
}
///
/// 获取标签数量刷新内码
///
/// 标签数量
///
public static string GetTagsCountRefreshString(string taskName,string code)
{
StringBuilder sbNeiMa = new StringBuilder();
//按照顺序从0开始刷 可以查看pdf文档<<002 内码区域局部更新协议V1.6>> 的2.2节
string strNeiMa1 = string.Format($"%disp0:0任务类型:{taskName}");
string strNeiMa2 = string.Format($"%disp1:0储位号:{code}");
//可以任选需要刷新的区域进行刷新
sbNeiMa.Append(strNeiMa1);
sbNeiMa.Append(strNeiMa2);
return sbNeiMa.ToString();
}
}
}