找回密码
 立即注册
C#编程 2022-09-23 83 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
在工业控制程序开发进程中很多选用VC作为开发平台,在与PLC等外围设备通信进程核心通常都会涉及到与他们这些外围设备的模拟量通信和数字量通信,收集当时节/点状况.在进行上位机软件开发进程中可以用很多方法来表明这些收集的点的状况,比方1,0等.假如我们选用一个可以动态改动色彩的LED来显示数字量节/点,用一种数字钟来显示模拟量的话程序在人性化接口方面将会比较好.下面的程序简单的介绍一种用承继cstatic类的方法来实现一个LED控件来动态显示外围设备收集到的数字量信号.
正文
数字量节/点信号无非即是我们使用串口或许其他通信端口与外部设备通信,通过通信协议解析变成的0或许1的信号,更多的状况即是一种无状况.在通常的工业控制程序中,我们通常喜欢用赤色来表明有状况,即1,绿色为无状况,即0,黄色为无效状况,我们这儿可以定义为2.那么,假如思考到程序的控件的扩展性,我们可以定义多个布景色彩.这个控件里边我们定义4种色彩,RED,GREEN,YELLOW,BLUE,假如需要更多我们可以灵敏定义.
typedefenumtagItemCOLOR{RED,GREEN,BLUE,YELLOW};
同时我们定义一下控件的布景显示模式,通常的LED我们显示为圆圈,可是部分控件的LED为方形,我们也思考进行定义.
#defineID_SHAPE_ROUND3001
#defineID_SHAPE_SQUARE3002
首要承继一个新类命名为CStateLedCtrl承继CStatic,映射消息WM_PAINT,我们将在这儿进行布景的制作就可以简单的实现了.
voidCStateLedCtrl::OnPaint()
{
CPaintDCdc(this);//devicecontextforpainting
//TODO:Addyourmessagehandlercodehere
//DonotcallCStatic::OnPaint()forpaintingmessages
//GettheDeviceContext
//Gettherectangleofthewindowwherewearegoingtodraw
CRectrcClient;

(In the process of industrial control program development, VC is often used as the development platform. The core of the communication process with peripheral devices such as PLC usually involves analog communication and digital communication with these peripheral devices, and the current node/point status is collected. In the process of software development of the host computer, many methods can be used to indicate the status of these collected points, such as 1, 0, etc. If we choose an LED that can dynamically change color to display digital nodes/points, use a digital clock to display If the analog quantity is used, the program will be better in terms of humanized interface. The following program briefly introduces a method of inheriting the cstatic class to implement an LED control to dynamically display the digital signal collected by the peripheral device.
text
The digital node/point signal is nothing more than a signal of 0 or 1 that we use the serial port or other communication ports to communicate with external devices, and parses the communication protocol into a signal of 0 or 1. More conditions are no conditions. In the usual industrial control In the program, we usually like to use red to indicate the status, that is, 1, green for no status, that is, 0, yellow for invalid status, we can define it as 2 here. Then, if we think about the extensibility of the program's controls, we can Define multiple background colors. In this control, we define 4 colors, RED, GREEN, YELLOW, BLUE, if we need more, we can define them flexibly.
typedefenumtagItemCOLOR{RED,GREEN,BLUE,YELLOW};
At the same time, let's define the background display mode of the control. The usual LEDs are displayed as circles, but the LEDs of some controls are squares, so we also think about defining them.
#defineID_SHAPE_ROUND3001
#defineID_SHAPE_SQUARE3002
First, inherit a new class named CStateLedCtrl, inherit CStatic, and map the message WM_PAINT. We will make the scene here, which can be easily implemented.
voidCStateLedCtrl::OnPaint()
{
CPaintDCdc(this);//devicecontextforpainting
//TODO:Addyourmessagehandlercodehere
//DonotcallCStatic::OnPaint()forpaintingmessages
//GettheDeviceContext
//Gettherectangleofthewindowwherewearegoingtodraw
CRectrcClient;)

[下载]23111891438.rar




上一篇:数据库 网络通讯
下一篇:一个可用于计算Modubs协议通讯的16位CRC校验DEMO