撰寫一console程式, 讓其他應用程式呼叫使用, 功能如下

提供四組LED字串顯示, 使用者可以控制

(1) 字體大小

(2) 跑馬燈特效

(3) 跑馬燈停留時間

(4) 字體靠齊

1. 視窗左上角x,y

2. 視窗中間上緣x, y

3. 視窗中間下緣x, y

4. 視窗右下角x, y

image

image

image

加入CPS5200.cs

image

主程式加入CPower_CSharp命名空間

using CPower_CSharp;

public class LED
{

uint dwIPAddr = GetIP("192.168.1.222");
uint dwIDCode = GetIP("255.255.255.255");
int nIPPort = 5200;
int m_nTimeout = 600;

static public uint GetIP(string strIp)
{
System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(strIp);
uint lIp = (uint)ipaddress.Address;

lIp = ((lIp & 0xFF000000) >> 24) + ((lIp & 0x00FF0000) >> 8) + ((lIp & 0x0000FF00) << 8) + ((lIp & 0x000000FF) << 24);
return (lIp);
}
public void InitComm()
{
try
{
if (dwIPAddr != 0 && dwIDCode != 0)
CP5200.CP5200_Net_Init(dwIPAddr, nIPPort, dwIDCode, m_nTimeout);
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
}
}
public int SendText(int nWndNo, string text, int nFontSize, int nEffect, int nStayTime, int nAlignment)
{
int nRet;
nRet = CP5200.CP5200_Net_SendText(Convert.ToByte(1), nWndNo, Marshal.StringToHGlobalAnsi(text), 0xFF, nFontSize, 3, nEffect, nStayTime, nAlignment);
return nRet;
}
}

主程式

static void Main(string[] args)
{
int argsLen = args.Length; // 輸入參數
if (argsLen != 8)
{
Console.WriteLine("輸入參數必須為8組...");
return;
}
int nFontSize = Convert.ToInt16(args[0]);
int nEffect = Convert.ToInt16(args[1]);
int nStayTime = Convert.ToInt16(args[2]);
int nAlignment = Convert.ToInt16(args[3]);

LED ledobj = new LED();
ledobj.InitComm();
int nRet;
for (int i = 4; i < 8; i++)
{
nRet = ledobj.SendText(i - 4, args[i], nFontSize, nEffect, nStayTime, nAlignment);
Console.WriteLine(nRet);
if (nRet==0)
{
Console.WriteLine("{0}傳送成功...", i-4);
}
else
{
Console.WriteLine("{0}傳送失敗...", i-4);
}
}
}

呼叫語法:

ledsender.exe 大小 特效 停留時間 靠齊 "111" "222" "333" “444"

(1) ex1 14字大小

ledsender.exe 14 0 3 0 "0123456789123456" "abcdefghijklmnop" "Thank you       " "How about you?  "

IMG_20160131_164259

(2) ex2 12字大小

ledsender.exe 12 0 3 0 "012345678912345678901" "abcdefghijklmnopqrstu" "Thank you            " "How about you?       "

IMG_20160131_164339

(3) ex3 字靠左

ledsender.exe 14 0 3 -1 "1234" "5678" "abcd" "efgh"

IMG_20160131_164504

(4) ex4 字置中

ledsender.exe 14 0 3 1 "1234" "5678" "abcd" "efgh"

IMG_20160131_164540

(5) ex5 字靠右

ledsender.exe 14 0 3 2 "1234" "5678" "abcd" "efgh"

IMG_20160131_164618

(6) ex6 左移 停1秒

ledsender.exe 12 6 1 -1 "How are you?" "I'm fine." "Thank you." "And how about you?"

(7) ex7 左移 停5秒

ledsender.exe 12 6 5 -1 "How are you?" "I'm fine." "Thank you." "And how about you?"

(8) ex8 清空

ledsender.exe 14 0 0 0 " " " " " " " "

arrow
arrow
    全站熱搜

    me1237guy 發表在 痞客邦 留言(0) 人氣()