SCLS/SSWCS_JXDL(2019)/ControlSystem/LEDHelper.cs
2025-05-19 09:45:29 +08:00

82 lines
3.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
{
/// <summary>
/// 刷新任务信息
/// </summary>
/// <param name="Commport">串口编号,如设备管理器里显示为 COM3 则此处赋值 3</param>
/// <param name="TagsCount">标签数量</param>
/// <returns></returns>
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)";
}
}
/// <summary>
/// 获取连接信息
/// </summary>
/// <param name="Commport">串口编号,如设备管理器里显示为 COM3 则此处赋值 3</param>
/// <returns></returns>
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;
}
/// <summary>
/// 获取标签数量刷新内码
/// </summary>
/// <param name="tagsCount">标签数量</param>
/// <returns></returns>
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();
}
}
}