using LedSimple; namespace WcsMain.Business.CommonAction; public class LedUsing(int ledWidth, int ledHeight, int colorType, int nAlignment = 2, int isVCenter = 1) { private readonly int _ledWidth = ledWidth;//屏的宽度 private readonly int _ledHeight = ledHeight;//屏的高度 private readonly int _colorType = colorType;//屏的色彩——1.单色 2.双基色 3.七彩 4.全彩 private readonly int _nAlignment = nAlignment;//水平对齐样式,0.左对齐 1.右对齐 2.水平居中 (注意:只对字符串和txt文件有效) private readonly int _isVCenter = isVCenter; //是否垂直居中 0.置顶(默认) 1.垂直居中 /// /// 红色宋体字 /// private Leddll.FONTPROP _fontRed = new() { FontName = "宋体", FontSize = 9, FontColor = (int)LEDColor.Red, FontBold = 0 }; /// /// 红色宋体字 /// private Leddll.FONTPROP _fontRedBig = new() { FontName = "宋体", FontSize = 12, FontColor = (int)LEDColor.Red, FontBold = 0 }; /// /// 红色宋体字 /// private Leddll.FONTPROP _fontGreen = new() { FontName = "宋体", FontSize = 9, FontColor = (int)LEDColor.Green, FontBold = 0 }; /// /// 立即显示的节目效果 /// private Leddll.PLAYPROP _playProp = new() { InStyle = 0 }; /// /// 发送锁 /// private static readonly object SendLock = new(); /// /// 展示默认的显示内容 ---- 江西隆成立库 256*96 /// /// /// public void ShowDefaultMsg(string ip, string msg) { try { Leddll.COMMUNICATIONINFO communicationInfo = GetCommunicationInfo(ip); Leddll.DIGITALCLOCKAREAINFO date = new() { DateFormat = 0, TimeFormat = 0, IsShowDay = 1, IsShowHour = 1, IsShowMonth = 1, IsShowSecond = 1, IsShowYear = 1, IsShowMinute = 1, }; lock (SendLock) { Leddll.LV_AdjustTime(ref communicationInfo); // 校时 int nResult; //LedDll.LV_InitLed(3, 0); 当Led上显示的文字区域的颜色与下发的不一致, 请的确认Led 屏的RGB顺序,并调用此接口 nint hProgram;//节目句柄 hProgram = Leddll.LV_CreateProgramEx(_ledWidth, _ledHeight, _colorType, 0, 0);//注意此处屏宽高及颜色参数必需与设置屏参的屏宽高及颜色一致,否则发送时会提示错误 //此处可自行判断有未创建成功,hProgram返回NULL失败,非NULL成功,一般不会失败 //int nProgramId = 0; nResult = Leddll.LV_AddProgram(hProgram, 1, 0, 1);//添加一个节目,参数说明见函数声明注示 /* 添加内容 */ // ---- 公司名称 Leddll.AREARECT areaHeader = new() // 添加区域 { left = 0, top = 10, width = 256, height = 20 }; //区域坐标属性结构体变量 int addAreaHeaderResult = Leddll.LV_AddImageTextArea(hProgram, 1, 1, ref areaHeader, 0); if (addAreaHeaderResult == 0) { // 添加到显示 nResult = Leddll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 1, Leddll.ADDTYPE_STRING, "江西隆成医药", ref _fontRedBig, ref _playProp, 2, 1); } // ---- 控制方式,联机状态 Leddll.AREARECT areaMain = new() // 添加区域 { left = 0, top = 35, width = 256, height = 20 }; //区域坐标属性结构体变量 if (msg.Length > 25) { nResult = Leddll.LV_QuickAddSingleLineTextArea(hProgram, 1, 2, ref areaMain, 0, msg + " ", ref _fontRed, 10); } else { int addAreaMain = Leddll.LV_AddImageTextArea(hProgram, 1, 2, ref areaMain, 1); if (addAreaMain == 0) { // 添加到显示 nResult = Leddll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 2, Leddll.ADDTYPE_STRING, msg, ref _fontRed, ref _playProp, 2, 1); } } // ---- 时间 Leddll.AREARECT areaTime = new() // 添加区域 { left = 0, top = 60, width = 256, height = 20 }; //区域坐标属性结构体变量 int addAreaTime = Leddll.LV_AddDigitalClockArea(hProgram, 1, 3, ref areaTime, ref date); /* 发送 LED */ nResult = Leddll.LV_Send(ref communicationInfo, hProgram); //发送,见函数声明注示 Thread.Sleep(100); Leddll.LV_DeleteProgram(hProgram); //删除节目内存对象,详见函数声明注示 } } catch (Exception ex) { _ = ex; } } private Leddll.COMMUNICATIONINFO GetCommunicationInfo(string ip) { Leddll.COMMUNICATIONINFO CommunicationInfo = new() { //TCP通讯******************************************************************************** SendType = 0,//设为固定IP通讯模式,即TCP通讯 IpStr = ip,//给IpStr赋值LED控制卡的IP LedNumber = 1,//LED屏号为1,注意socket通讯和232通讯不识别屏号,默认赋1就行了,485必需根据屏的实际屏号进行赋值 //广播通讯******************************************************************************** //CommunicationInfo.SendType=1;//设为单机直连,即广播通讯无需设LED控制器的IP地址 //串口通讯******************************************************************************** //CommunicationInfo.SendType=2;//串口通讯 //CommunicationInfo.Commport=1;//串口的编号,如设备管理器里显示为 COM3 则此处赋值 3 //CommunicationInfo.Baud=9600;//波特率 //CommunicationInfo.LedNumber=1; };//定义一通讯参数结构体变量用于对设定的LED通讯,具体对此结构体元素赋值说明见COMMUNICATIONINFO结构体定义部份注示 return CommunicationInfo; } }