WinCE5.0 平台下的 Moxa DA66x 设备应用开发提示
...
public class LCMKEY
{
private mxdevice mxdevice1;
private Thread trdKeypadlisten;
private bool bStop;
public static int Key = 0; //按键信息
public LCMKEY()
{
}
public void Init()
{
mxdevice1 = new mxdevice("LCM1:");
mxdevice1.Open();
this.bStop = false;
this.trdKeypadlisten = new Thread(new ThreadStart(this.ThreadTask));
this.trdKeypadlisten.Priority = ThreadPriority.Normal;
this.trdKeypadlisten.Start();
}
public void Exit()
{
mxdevice1.Close();
try
{
if (!this.bStop)
{
this.bStop = true;
}
this.trdKeypadlisten = null;
}
catch
{
return;
}
}
~LCMKEY()
{
Exit();
}
//光标控制
public void Cursor(bool bFlag)
{
byte num = 0;
mxdevice1.IoControl(bFlag ? mxdevice.IOCTL_LCM_CURSOR_ON : mxdevice.IOCTL_LCM_CURSOR_OFF, ref num); //mxdevice.IOCTL_LCM_BLINK_ON
}
//清屏
public void Clear()
{
byte num = 0;
mxdevice1.IoControl(mxdevice.IOCTL_LCM_CLEAR, ref num);
}
//光标定位
public void GotoXY(byte x, byte y)
{
mxdevice.LCM_POS pos = new mxdevice.LCM_POS();
pos.x = x;
pos.y = y;
IntPtr lpPos = Marshal.AllocHGlobal(Marshal.SizeOf(pos));
Marshal.StructureToPtr(pos, lpPos, false);
mxdevice1.IoControl(mxdevice.IOCTL_LCM_GOTO_XY, lpPos);
}
//文本显示
public void Show(string text, byte x, byte y)
{
int num = 0;
GotoXY(x, y);
mxdevice1.WriteDev(Encoding.Default.GetBytes(text), text.Length, out num);
}
//文本显示
public void Show(string text1, string text2)
{
//清屏
Clear();
//写第一行
Show(text1, 0, 0);
//写第二行
Show(text2, 0, 1);
}
//按钮控制
protected virtual void OnKeyClick(int e)
{
if (this.KeyClick != null)
{
this.KeyClick(this, e);
Key = e;
}
}
//按钮监控
private void ThreadTask()
{
byte pTemp = 0, pKey = 0;
do
{
if (mxdevice1.IoControl(mxdevice.IOCTL_KEYPAD_GET_MENU_STATE, ref pTemp, ref pKey))
{
if (pKey == 1)
{
OnKeyClick(1);
}
}
if (mxdevice1.IoControl(mxdevice.IOCTL_KEYPAD_GET_UP_STATE, ref pTemp, ref pKey))
{
if (pKey == 1)
{
OnKeyClick(2);
}
}
if (mxdevice1.IoControl(mxdevice.IOCTL_KEYPAD_GET_DOWN_STATE, ref pTemp, ref pKey))
{
if (pKey == 1)
{
OnKeyClick(3);
}
}
if (mxdevice1.IoControl(mxdevice.IOCTL_KEYPAD_GET_SELE_STATE, ref pTemp, ref pKey))
{
if (pKey == 1)
{
OnKeyClick(4);
}
}
Thread.Sleep(100);
}
while (!this.bStop);
}
// Events
public event KeyClickEventHandler KeyClick;