劉德軍
摘要:LED點(diǎn)陣屏通過(guò)LED(發(fā)光二極管)組成,以燈珠亮滅來(lái)顯示文字、圖片、動(dòng)畫(huà)、視頻。LED點(diǎn)陣顯示屏有制作簡(jiǎn)單,安裝方便的優(yōu)點(diǎn),被廣泛應(yīng)用于各種公共場(chǎng)合。如何實(shí)現(xiàn)定時(shí)自動(dòng)發(fā)布動(dòng)態(tài)更新的信息是本文重點(diǎn)探討的內(nèi)容。
關(guān)鍵詞:LED點(diǎn)陣屏;定時(shí);發(fā)布;自動(dòng)
中圖分類(lèi)號(hào):TP311 文獻(xiàn)標(biāo)識(shí)碼:A 文章編號(hào):1009-3044(2016)36-0241-02
我院在門(mén)診一塊單色LED屏,專(zhuān)用于門(mén)診專(zhuān)家排班發(fā)布,考慮到手工處理每天不同排班信息較為繁瑣,故考慮通過(guò)程序控制來(lái)實(shí)現(xiàn)了LED點(diǎn)陣屏定時(shí)自動(dòng)發(fā)布字幕功能。
1 需求
該功能的需求如下:① 從數(shù)據(jù)庫(kù)中獲取每日專(zhuān)家排班信息;② 只發(fā)布當(dāng)天的專(zhuān)家排班信息;③ 發(fā)生排班調(diào)整,可手工更新;④ 能自動(dòng)定時(shí)發(fā)布。
2 方法
用C#通過(guò)調(diào)用開(kāi)發(fā)包中封裝的DLL文件,并讀取數(shù)據(jù)庫(kù)中排班信息,向屏幕區(qū)域添加,并完成發(fā)送,具體流如下圖示:
3 詳細(xì)步驟
3.1 建立C#應(yīng)用程序
建立界面如圖1,控件參數(shù)見(jiàn)下表。
3.2 編寫(xiě)代碼
//常用命名空間略
using System.Runtime.InteropServices;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{public partial class Form1 : Form
{//常數(shù)定義(略)
//調(diào)用動(dòng)態(tài)庫(kù)(略)
public Form1()
{InitializeComponent();}
private void Form1_Load(object sender, EventArgs e)
{ timer1.Enabled = true; }
//獲取掛號(hào)排班信息(GetGH_info代碼略)
//獲取當(dāng)前屏號(hào)、動(dòng)態(tài)區(qū)域
private void GetcurGrpCaption()
{ RichTextBox1.Text = FAddDynamicArea + "(屏號(hào):" + spnedt_PNo + ")";
RichTextBox1.Text = FAddDYAreaFile + "(屏號(hào):" + spnedt_PNo + ";動(dòng)態(tài)區(qū)域編號(hào):" + spnedt_DYAreaID + ")\r\n";}
//初始化動(dòng)態(tài)庫(kù)InitializeDLL()代碼略
private void AddScreen()//添加顯示屏
{ nResult = AddScreen_Dynamic(nControlType, spnedt_PNo, nSendMode,spnedt_Width, spnedt_Height, nScreenType, cbb_Pixel, cbb_Comm, cbb_Baud,edt_StaticIP_IP, spnedt_StaticIP_Port, nServerMode, Barcode, NetworkID, edt_ServerIP, edt_ServerPort,edt_User, edt_Password , edt_SaveFile);
GetErrorMessage("執(zhí)行添加顯示屏,", nResult);}
//釋放動(dòng)態(tài)庫(kù)Exp_DLL代碼略
private void AddScreenDynamicArea()//添加屏幕動(dòng)態(tài)區(qū)域
{ //添加專(zhuān)家排班信息區(qū)域
nResult = AddScreenDynamicArea(spnedt_PNo, spnedt_DYAreaID, nRunMode, spnedt_TimeOut, nAllProRelate, szProRelateList, nPlayPriority, spnedt_DYAreaX, 30, spnedt_DYAreaW, 66, nAreaFMode, nAreaFLine, spnedt_DYAreaFSingleColor, cbb_DYAreaFStunt, spnedt_DYAreaFRunSpeed, spnedt_DYAreaFMoveStep);
GetErrorMessage("執(zhí)行添加屏幕動(dòng)態(tài)區(qū)域0,", nResult);}
private void AddTxttoDynamicArea()//添加文本到當(dāng)前動(dòng)態(tài)區(qū)域
{ nResult = 0;
int nSingleLine=0;
string textContent = ShowMessage;
//添加專(zhuān)家信息
nResult = AddScreenDynamicAreaText(spnedt_PNo, spnedt_DYAreaID,textContent, nSingleLine, "黑體", 20, 0, 65535, 1,spnedt_DYAreaRunSpeed, spnedt_DYAreaShowTime+10);
GetErrorMessage("執(zhí)行添加文本到當(dāng)前動(dòng)態(tài)區(qū)域0, ", nResult);
RichTextBox1.Text = RichTextBox1.Text + textContent + "\r\n";}
private void SendDynamicAreaText()//發(fā)送信息到動(dòng)態(tài)區(qū)域。
{ int nResult;
nResult = SendDynamicAreaInfoCommand(spnedt_PNo, spnedt_DYAreaID);
GetErrorMessage("執(zhí)行發(fā)送信息0, ", nResult);}
private void button1_Click(object sender, EventArgs e)
{
InitializeDLL();
AddScreen();
AddScreenDynamicArea();
GetGH_info();
AddTxttoDynamicArea();
SendDynamicAreaText();
Exp_DLL();
Application.ExitThread();//執(zhí)行結(jié)束后退出程序}}}
3.3 生成可執(zhí)行文件
在C#編譯生成名稱(chēng)為“門(mén)診LED屏信息發(fā)布.exe”的可執(zhí)行文件,該文件位于當(dāng)前工程目錄下“日志清除工具\bin\Debug\”,注意需與引用的DLL位于同一目錄下,在“任務(wù)計(jì)劃”中添加任務(wù)計(jì)劃,定時(shí)執(zhí)行即可。
4 體會(huì)與說(shuō)明
實(shí)現(xiàn)LED點(diǎn)陣屏定時(shí)自動(dòng)發(fā)布字幕的體會(huì)如下:1)在程序執(zhí)行完成后,需由定時(shí)器觸發(fā)程序自時(shí)關(guān)閉;2)除Button1外的多出的幾個(gè)按鈕用于按順序測(cè)試;3)發(fā)生排班調(diào)整時(shí),只需手動(dòng)運(yùn)行一次即可;4)本例所用的DLL為仰邦BX5二次開(kāi)發(fā)包;5)DLL內(nèi)置函數(shù)詳見(jiàn)開(kāi)發(fā)包說(shuō)明。提供的此功能在Windows XP SP3 + Microsoft Visual Studio 2010及屏參設(shè)置正常的環(huán)境下調(diào)試通過(guò)。
參考文獻(xiàn):
[1] 宋智軍,邱仲潘.Visual C#2010從入門(mén)到精通,電子工業(yè)出版社,2011.
[2] Christian Nagel,Bill Evjen.李銘譯,黃靜審校[M]. 8版.C#高級(jí)編程,2013(10).