using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Runtime.InteropServices; using System.Text; using LedSDKDemo_CSharp; using System.Threading; using IOT.Show.SqlBase; using IOT.Show.Common; using IOT.Show.Model; namespace IOT.Show { /// /// led服务操作 /// public class LedServer { private static SqlSugarBase dbSql = new SqlSugarBase(); public static void init(string title) { while (true) { try { List ledInfo = dbSql.getLedInfo(title); DataTable dt = dbSql.getLedData(title); List _Datas = dbSql.ConvertDataTableToList(dt); DataTable dataTable = dbSql.ListToTable(_Datas); if (dataTable != null) { T_Led_Info item = ledInfo.Where(x => x.title == title).FirstOrDefault(); if (item != null) { LogHelper.Info($"{title}冷却循环水温度"); byte[] ip = Encoding.GetEncoding("GBK").GetBytes(item.ip); bx_sdk_dual2.InitSdk();//初始化 bool result = dynamicArea_6(ip, item.title, item.font, item.ip, dataTable); if (result) { LogHelper.Info(item.title + "Led刷新成功,地址为:" + item.ip); } bx_sdk_dual2.ReleaseSdk(); } else { Console.WriteLine("item == null"); } } else { Console.WriteLine("DataTable为空"); } System.Threading.Thread.Sleep(1000 * 1); } catch (Exception ex) { LogHelper.Error("init异常", ex); } } } /// /// 动态区域更新 /// /// /// /// public static bool dynamicArea_6(byte[] ip, string title, string fonts, string ipStr, DataTable dataTable) { bool result = false; if (dataTable == null) { return false; } try { StringBuilder text = new StringBuilder(); int intPadRight = 1; int fontSize = 10; byte[] font = Encoding.Default.GetBytes(fonts); //DataTable dataTable = dbSql.getLedData(title); int rows = dataTable.Rows.Count; text.Append(" " + title + "冷却循环水温度 \n"); text.Append("位置 " + " 进水温度 " + " 出水温度 " + " 温差 \n"); for (int i = 0; i < rows; i++) { if (dataTable.Rows[i]["monitorName"].ToString().Contains("-")) { dataTable.Rows[i]["monitorName"] = dataTable.Rows[i]["monitorName"].ToString().Substring(4, dataTable.Rows[i]["monitorName"].ToString().Length - 4); } else { dataTable.Rows[i]["monitorName"] = dataTable.Rows[i]["monitorName"].ToString().Substring(3, dataTable.Rows[i]["monitorName"].ToString().Length - 3); } if (dataTable.Rows[i]["monitorName"].ToString().Length == 3) { dataTable.Rows[i]["monitorName"] = dataTable.Rows[i]["monitorName"].ToString() + " "; } if (Convert.ToDecimal(dataTable.Rows[i]["tempreture"]) < 1) { text.Append((dataTable.Rows[i]["monitorName"].ToString().PadRight(dataTable.Rows[0]["monitorName"].ToString().Length, ' ') + " " + "00.00").PadRight(intPadRight + 3, ' ') + "℃ "); } else { text.Append((dataTable.Rows[i]["monitorName"].ToString().PadRight(dataTable.Rows[0]["monitorName"].ToString().Length, ' ') + " " + dataTable.Rows[i]["tempreture"]).PadRight(intPadRight + 3, ' ') + "℃ "); } if (Convert.ToDecimal(dataTable.Rows[i]["humidity"].ToString()) < 1) { text.Append(("00.00").PadRight(intPadRight + 3, ' ') + "℃"); } else { text.Append((dataTable.Rows[i]["humidity"].ToString()).PadRight(intPadRight + 3, ' ') + "℃"); } text.Append(" "); if (dataTable.Rows[i]["illuminance"].ToString() == "") { text.Append(("00.00").PadRight(intPadRight + 3, ' ') + "℃"); } else { text.Append((dataTable.Rows[i]["illuminance"].ToString()).PadRight(intPadRight + 3, ' ') + "℃"); } text.Append("\n"); if (i + 1 == 5 || i + 1 == 10 || i + 1 == 15 || i + 1 == 20) { test(text, ip, font, fontSize); Thread.Sleep(1000 * 6); text = new StringBuilder(); text.Append(" " + title + "冷却循环水温度 \n"); text.Append("位置 " + " 进水温度 " + " 出水温度 " + " 温差 \n"); } else if (i == rows - 1) { test(text, ip, font, fontSize); Thread.Sleep(1000 * 6); text = new StringBuilder(); text.Append(" " + title + "冷却循环水温度 \n"); text.Append("位置 " + "进水温度 " + " 出水温度 " + " 温差 \n"); } } return true; } catch (Exception ex) { LogHelper.Error("dynamicArea_6程序异常" + ex.Message); return result; } } private static void test(StringBuilder text, byte[] ip, byte[] font, int fontSize) { string textT = text.ToString().Substring(0, text.ToString().Length - 1) + '\0'; Console.WriteLine(textT); bx_sdk_dual2.EQareaHeader_G6 aheader; aheader.AreaType = 0x10; aheader.AreaX = 0; aheader.AreaY = 0; aheader.AreaWidth = 256; aheader.AreaHeight = 96; aheader.BackGroundFlag = 0x00; aheader.Transparency = 101; aheader.AreaEqual = 0x00; bx_sdk_dual2.EQSound_6G stSoundData = new bx_sdk_dual2.EQSound_6G(); byte[] strSoundTxt = Encoding.GetEncoding("GB2312").GetBytes("插入ab34测试语音"); stSoundData.SoundFlag = 0x00; stSoundData.SoundPerson = 0x01; stSoundData.SoundVolum = 6; stSoundData.SoundSpeed = 0x2; stSoundData.SoundDataMode = 0x00; stSoundData.SoundReplayTimes = 0x01; stSoundData.SoundReplayDelay = 200; stSoundData.SoundReservedParaLen = 0x03; stSoundData.Soundnumdeal = 0x00; stSoundData.Soundlanguages = 0x00; stSoundData.Soundwordstyle = 0x00; stSoundData.SoundDataLen = strSoundTxt.Length; stSoundData.SoundData = TypeCast.BytesToIntptr(strSoundTxt); aheader.stSoundData = stSoundData; bx_sdk_dual2.EQpageHeader_G6 pheader; pheader.PageStyle = 0x00; pheader.DisplayMode = 1; pheader.ClearMode = 0x00; pheader.Speed = 15; pheader.StayTime = 500; pheader.RepeatTime = 1; pheader.ValidLen = 0; pheader.CartoonFrameRate = 0x00; pheader.BackNotValidFlag = 0x00; pheader.arrMode = bx_sdk_dual2.E_arrMode.eMULTILINE; pheader.fontSize = Convert.ToUInt16(fontSize); pheader.color = (uint)0x01; pheader.fontBold = 0; pheader.fontItalic = 0; pheader.tdirection = bx_sdk_dual2.E_txtDirection.pNORMAL; pheader.txtSpace = 0; pheader.Valign = 1; pheader.Halign = 2; IntPtr aa1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual2.EQareaHeader_G6))); Marshal.StructureToPtr(aheader, aa1, false); IntPtr bb1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual2.EQpageHeader_G6))); Marshal.StructureToPtr(pheader, bb1, false); //LogHelper.Info("LED数据上传地址:" + System.Text.Encoding.UTF8.GetString(ip)+ ":5005"); //更新动态区,可设置属性 zc int info = bx_sdk_dual2.dynamicArea_AddAreaTxtDetails_6G(ip, 5005, bx_sdk_dual2.E_ScreenColor_G56.eSCREEN_COLOR_SINGLE, 0, ref aheader, ref pheader, font, Encoding.Default.GetBytes(textT)); } } }