实例介绍
【实例简介】
【实例截图】
【核心代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string s1;
string s2;
string s3;
string s4;
string s5;
string s6;
private void button5_Click(object sender, EventArgs e)
{
int nResult;
LedDll.COMMUNICATIONINFO CommunicationInfo = new LedDll.COMMUNICATIONINFO();//定义一通讯参数结构体变量用于对设定的LED通讯,具体对此结构体元素赋值说明见COMMUNICATIONINFO结构体定义部份注示
//ZeroMemory(&CommunicationInfo,sizeof(COMMUNICATIONINFO));
//TCP通讯********************************************************************************
CommunicationInfo.SendType = 0;//设为固定IP通讯模式,即TCP通讯
CommunicationInfo.IpStr = "192.168.1.99";//给IpStr赋值LED控制卡的IP
CommunicationInfo.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;
int hProgram;//节目句柄
hProgram = LedDll.LV_CreateProgram(128, 128, 2);//根据传的参数创建节目句柄,64是屏宽点数,32是屏高点数,2是屏的颜色,注意此处屏宽高及颜色参数必需与设置屏参的屏宽高及颜色一致,否则发送时会提示错误
//此处可自行判断有未创建成功,hProgram返回NULL失败,非NULL成功,一般不会失败
nResult = LedDll.LV_AddProgram(hProgram, 1, 0, 1);//添加一个节目,参数说明见函数声明注示
if (nResult != 0)
{
string ErrStr;
ErrStr = LedDll.LS_GetError(nResult);
MessageBox.Show(ErrStr);
return;
}
//添加一个文本1
LedDll.AREARECT AreaRect = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect.left = 0;
AreaRect.top = 32;
AreaRect.width = 64;
AreaRect.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 1, ref AreaRect, 0);
LedDll.FONTPROP FontProp = new LedDll.FONTPROP();//文字属性
FontProp.FontName = "宋体";
FontProp.FontSize = 12;
FontProp.FontColor = LedDll.COLOR_GREEN;
FontProp.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp = new LedDll.PLAYPROP();
PlayProp.InStyle = 0;
PlayProp.DelayTime = 3;
PlayProp.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 1, LedDll.ADDTYPE_STRING, textBox1.Text "g", ref FontProp, ref PlayProp, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本2
LedDll.AREARECT AreaRect1 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect1.left = 0;
AreaRect1.top = 64;
AreaRect1.width = 64;
AreaRect1.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 2, ref AreaRect1, 0);
LedDll.FONTPROP FontProp1 = new LedDll.FONTPROP();//文字属性
FontProp1.FontName = "宋体";
FontProp1.FontSize = 12;
FontProp1.FontColor = LedDll.COLOR_GREEN;
FontProp1.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp1 = new LedDll.PLAYPROP();
PlayProp1.InStyle = 0;
PlayProp1.DelayTime = 3;
PlayProp1.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 2, LedDll.ADDTYPE_STRING,textBox2.Text "g", ref FontProp1, ref PlayProp1, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本3
LedDll.AREARECT AreaRect2 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect2.left = 0;
AreaRect2.top = 96;
AreaRect2.width = 64;
AreaRect2.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 3, ref AreaRect2, 0);
LedDll.FONTPROP FontProp2 = new LedDll.FONTPROP();//文字属性
FontProp2.FontName = "宋体";
FontProp2.FontSize = 12;
FontProp2.FontColor = LedDll.COLOR_GREEN;
FontProp2.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp2 = new LedDll.PLAYPROP();
PlayProp2.InStyle = 0;
PlayProp2.DelayTime = 3;
PlayProp2.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 3, LedDll.ADDTYPE_STRING, textBox3.Text "g", ref FontProp2, ref PlayProp2, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本4
LedDll.AREARECT AreaRect3 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect3.left = 64;
AreaRect3.top = 32;
AreaRect3.width = 64;
AreaRect3.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 4, ref AreaRect3, 0);
LedDll.FONTPROP FontProp3 = new LedDll.FONTPROP();//文字属性
FontProp3.FontName = "宋体";
FontProp3.FontSize = 12;
FontProp3.FontColor = LedDll.COLOR_GREEN;
FontProp3.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp3 = new LedDll.PLAYPROP();
PlayProp3.InStyle = 0;
PlayProp3.DelayTime = 3;
PlayProp3.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 4, LedDll.ADDTYPE_STRING, textBox4.Text "g", ref FontProp3, ref PlayProp3, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本5
LedDll.AREARECT AreaRect4 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect4.left = 64;
AreaRect4.top = 64;
AreaRect4.width = 64;
AreaRect4.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 5, ref AreaRect4, 0);
LedDll.FONTPROP FontProp4 = new LedDll.FONTPROP();//文字属性
FontProp4.FontName = "宋体";
FontProp4.FontSize = 12;
FontProp4.FontColor = LedDll.COLOR_GREEN;
FontProp4.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp4 = new LedDll.PLAYPROP();
PlayProp4.InStyle = 0;
PlayProp4.DelayTime = 3;
PlayProp4.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 5, LedDll.ADDTYPE_STRING, textBox5.Text "g", ref FontProp4, ref PlayProp4, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本6
LedDll.AREARECT AreaRect5 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect5.left = 64;
AreaRect5.top = 96;
AreaRect5.width = 64;
AreaRect5.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 6, ref AreaRect5, 0);
LedDll.FONTPROP FontProp5 = new LedDll.FONTPROP();//文字属性
FontProp5.FontName = "宋体";
FontProp5.FontSize = 12;
FontProp5.FontColor = LedDll.COLOR_GREEN;
FontProp5.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp5 = new LedDll.PLAYPROP();
PlayProp5.InStyle = 0;
PlayProp5.DelayTime = 3;
PlayProp5.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 6, LedDll.ADDTYPE_STRING, textBox6.Text "g", ref FontProp5, ref PlayProp5, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本7
LedDll.AREARECT AreaRect6 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect6.left = 0;
AreaRect6.top = 0;
AreaRect6.width = 128;
AreaRect6.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 7, ref AreaRect6, 0);
LedDll.FONTPROP FontProp6 = new LedDll.FONTPROP();//文字属性
FontProp6.FontName = "宋体";
FontProp6.FontSize = 12;
FontProp6.FontColor = LedDll.COLOR_GREEN;
FontProp6.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp6 = new LedDll.PLAYPROP();
PlayProp6.InStyle = 0;
PlayProp6.DelayTime = 3;
PlayProp6.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 7, LedDll.ADDTYPE_STRING, "重量显示", ref FontProp6, ref PlayProp6, 2, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
nResult = LedDll.LV_Send(ref CommunicationInfo, hProgram);//发送,见函数声明注示
LedDll.LV_DeleteProgram(hProgram);//删除节目内存对象,详见函数声明注示
if (nResult != 0)//如果失败则可以调用LV_GetError获取中文错误信息
{
string ErrStr;
ErrStr = LedDll.LS_GetError(nResult);
MessageBox.Show(ErrStr);
}
else
{
MessageBox.Show("发送成功");
}
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
if (s1 != textBox1.Text || s2 != textBox2.Text || s3 != textBox3.Text || s4 != textBox4.Text || s5 != textBox5.Text || s6 != textBox6.Text)
{
s1 = textBox1.Text;
s2 = textBox2.Text;
s3 = textBox3.Text;
s4 = textBox4.Text;
s5 = textBox5.Text;
s6 = textBox6.Text;
int nResult;
LedDll.COMMUNICATIONINFO CommunicationInfo = new LedDll.COMMUNICATIONINFO();//定义一通讯参数结构体变量用于对设定的LED通讯,具体对此结构体元素赋值说明见COMMUNICATIONINFO结构体定义部份注示
//ZeroMemory(&CommunicationInfo,sizeof(COMMUNICATIONINFO));
//TCP通讯********************************************************************************
CommunicationInfo.SendType = 0;//设为固定IP通讯模式,即TCP通讯
CommunicationInfo.IpStr = "192.168.1.99";//给IpStr赋值LED控制卡的IP
CommunicationInfo.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;
int hProgram;//节目句柄
hProgram = LedDll.LV_CreateProgram(128, 128, 2);//根据传的参数创建节目句柄,64是屏宽点数,32是屏高点数,2是屏的颜色,注意此处屏宽高及颜色参数必需与设置屏参的屏宽高及颜色一致,否则发送时会提示错误
//此处可自行判断有未创建成功,hProgram返回NULL失败,非NULL成功,一般不会失败
nResult = LedDll.LV_AddProgram(hProgram, 1, 0, 1);//添加一个节目,参数说明见函数声明注示
if (nResult != 0)
{
string ErrStr;
ErrStr = LedDll.LS_GetError(nResult);
MessageBox.Show(ErrStr);
return;
}
//添加一个文本1
LedDll.AREARECT AreaRect = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect.left = 0;
AreaRect.top = 32;
AreaRect.width = 64;
AreaRect.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 1, ref AreaRect, 0);
LedDll.FONTPROP FontProp = new LedDll.FONTPROP();//文字属性
FontProp.FontName = "宋体";
FontProp.FontSize = 12;
FontProp.FontColor = LedDll.COLOR_GREEN;
FontProp.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp = new LedDll.PLAYPROP();
PlayProp.InStyle = 0;
PlayProp.DelayTime = 3;
PlayProp.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 1, LedDll.ADDTYPE_STRING, textBox1.Text "g", ref FontProp, ref PlayProp, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本2
LedDll.AREARECT AreaRect1 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect1.left = 0;
AreaRect1.top = 64;
AreaRect1.width = 64;
AreaRect1.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 2, ref AreaRect1, 0);
LedDll.FONTPROP FontProp1 = new LedDll.FONTPROP();//文字属性
FontProp1.FontName = "宋体";
FontProp1.FontSize = 12;
FontProp1.FontColor = LedDll.COLOR_GREEN;
FontProp1.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp1 = new LedDll.PLAYPROP();
PlayProp1.InStyle = 0;
PlayProp1.DelayTime = 3;
PlayProp1.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 2, LedDll.ADDTYPE_STRING, textBox2.Text "g", ref FontProp1, ref PlayProp1, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本3
LedDll.AREARECT AreaRect2 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect2.left = 0;
AreaRect2.top = 96;
AreaRect2.width = 64;
AreaRect2.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 3, ref AreaRect2, 0);
LedDll.FONTPROP FontProp2 = new LedDll.FONTPROP();//文字属性
FontProp2.FontName = "宋体";
FontProp2.FontSize = 12;
FontProp2.FontColor = LedDll.COLOR_GREEN;
FontProp2.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp2 = new LedDll.PLAYPROP();
PlayProp2.InStyle = 0;
PlayProp2.DelayTime = 3;
PlayProp2.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 3, LedDll.ADDTYPE_STRING, textBox3.Text "g", ref FontProp2, ref PlayProp2, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本4
LedDll.AREARECT AreaRect3 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect3.left = 64;
AreaRect3.top = 32;
AreaRect3.width = 64;
AreaRect3.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 4, ref AreaRect3, 0);
LedDll.FONTPROP FontProp3 = new LedDll.FONTPROP();//文字属性
FontProp3.FontName = "宋体";
FontProp3.FontSize = 12;
FontProp3.FontColor = LedDll.COLOR_GREEN;
FontProp3.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp3 = new LedDll.PLAYPROP();
PlayProp3.InStyle = 0;
PlayProp3.DelayTime = 3;
PlayProp3.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 4, LedDll.ADDTYPE_STRING, textBox4.Text "g", ref FontProp3, ref PlayProp3, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本5
LedDll.AREARECT AreaRect4 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect4.left = 64;
AreaRect4.top = 64;
AreaRect4.width = 64;
AreaRect4.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 5, ref AreaRect4, 0);
LedDll.FONTPROP FontProp4 = new LedDll.FONTPROP();//文字属性
FontProp4.FontName = "宋体";
FontProp4.FontSize = 12;
FontProp4.FontColor = LedDll.COLOR_GREEN;
FontProp4.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp4 = new LedDll.PLAYPROP();
PlayProp4.InStyle = 0;
PlayProp4.DelayTime = 3;
PlayProp4.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 5, LedDll.ADDTYPE_STRING, textBox5.Text "g", ref FontProp4, ref PlayProp4, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本6
LedDll.AREARECT AreaRect5 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect5.left = 64;
AreaRect5.top = 96;
AreaRect5.width = 64;
AreaRect5.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 6, ref AreaRect5, 0);
LedDll.FONTPROP FontProp5 = new LedDll.FONTPROP();//文字属性
FontProp5.FontName = "宋体";
FontProp5.FontSize = 12;
FontProp5.FontColor = LedDll.COLOR_GREEN;
FontProp5.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp5 = new LedDll.PLAYPROP();
PlayProp5.InStyle = 0;
PlayProp5.DelayTime = 3;
PlayProp5.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 6, LedDll.ADDTYPE_STRING, textBox6.Text "g", ref FontProp5, ref PlayProp5, 1, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
//添加一个文本7
LedDll.AREARECT AreaRect6 = new LedDll.AREARECT();//区域坐标属性结构体变量
AreaRect6.left = 0;
AreaRect6.top = 0;
AreaRect6.width = 128;
AreaRect6.height = 32;
LedDll.LV_AddImageTextArea(hProgram, 1, 7, ref AreaRect6, 0);
LedDll.FONTPROP FontProp6 = new LedDll.FONTPROP();//文字属性
FontProp6.FontName = "宋体";
FontProp6.FontSize = 12;
FontProp6.FontColor = LedDll.COLOR_GREEN;
FontProp6.FontBold = 0;
//int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
LedDll.PLAYPROP PlayProp6 = new LedDll.PLAYPROP();
PlayProp6.InStyle = 0;
PlayProp6.DelayTime = 3;
PlayProp6.Speed = 4;
nResult = LedDll.LV_AddMultiLineTextToImageTextArea(hProgram, 1, 7, LedDll.ADDTYPE_STRING, "重量显示", ref FontProp6, ref PlayProp6, 2, 1);//通过字符串添加一个多行文本到图文区,参数说明见声明注示
nResult = LedDll.LV_Send(ref CommunicationInfo, hProgram);//发送,见函数声明注示
LedDll.LV_DeleteProgram(hProgram);//删除节目内存对象,详见函数声明注示
if (nResult != 0)//如果失败则可以调用LV_GetError获取中文错误信息
{
string ErrStr;
ErrStr = LedDll.LS_GetError(nResult);
MessageBox.Show(ErrStr);
}
}
timer1.Enabled = true;
}
}
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论