| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 610 人关注过本帖
标题:C++新人求教(关于LED测试程序)
只看楼主 加入收藏
a57126247
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-2-22
收藏
 问题点数:0 回复次数:0 
C++新人求教(关于LED测试程序)
新入公司不久,要求写一个“控制大的LED屏”程序的测试程序,要求是界面包括需要显示的内容,同时程序可以控制LED,可是在下一点头绪都没有,完全没有做过,哪位大侠可以指点一下步骤或者思路啊?万分感谢!!!程序如下:// Demo_VCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Demo_VC.h"
#include "Demo_VCDlg.h"
#include <stdio.h>
#include <string.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDemo_VCDlg dialog

CDemo_VCDlg::CDemo_VCDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CDemo_VCDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CDemo_VCDlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDemo_VCDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CDemo_VCDlg)
    DDX_Control(pDX, IDC_BUTTON1, m_Btn);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDemo_VCDlg, CDialog)
    //{{AFX_MSG_MAP(CDemo_VCDlg)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_WM_CLOSE()
    ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
    ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDemo_VCDlg message handlers

BOOL CDemo_VCDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
   
    // TODO: Add extra initialization here
    // 导入动态链接库
    // Load DLL
    #if (LIBRARY_CALL_MODE==MODE_STDCALL)
    hSCL_Dll = LoadLibrary("SCL_API_stdcall.Dll");
    #else
    #if  (LIBRARY_CALL_MODE==MODE_CDECL)
    hSCL_Dll = LoadLibrary("SCL_API_cdecl.Dll");
    #else hSCL_Dll=NULL;
    #endif
    #endif

    // 获取可调用的函数的指针
    // Get pointer of these functions in the DLL
    if (hSCL_Dll!=NULL)
    {
        SCL_NetInitial     = (_SCL_NetInitial    )GetProcAddress(hSCL_Dll,"SCL_NetInitial"    );
        SCL_ComInitial     = (_SCL_ComInitial    )GetProcAddress(hSCL_Dll,"SCL_ComInitial"    );
        SCL_Close          = (_SCL_Close         )GetProcAddress(hSCL_Dll,"SCL_Close"         );
        SCL_SetRemoteIP    = (_SCL_SetRemoteIP   )GetProcAddress(hSCL_Dll,"SCL_SetRemoteIP"   );
        SCL_SetLEDNum      = (_SCL_SetLEDNum     )GetProcAddress(hSCL_Dll,"SCL_SetLEDNum"     );
        SCL_TargetSCL2008  = (_SCL_TargetSCL2008 )GetProcAddress(hSCL_Dll,"SCL_TargetSCL2008" );
        SCL_GetLastResult  = (_SCL_GetLastResult )GetProcAddress(hSCL_Dll,"SCL_GetLastResult" );

        SCL_InitForPackage = (_SCL_InitForPackage)GetProcAddress(hSCL_Dll,"SCL_InitForPackage");
        SCL_GetPackage     = (_SCL_GetPackage    )GetProcAddress(hSCL_Dll,"SCL_GetPackage"    );
        SCL_CheckAnswer    = (_SCL_CheckAnswer   )GetProcAddress(hSCL_Dll,"SCL_CheckAnswer"   );

        SCL_FormatDisk     = (_SCL_FormatDisk    )GetProcAddress(hSCL_Dll,"SCL_FormatDisk"    );
        SCL_FreeSpace      = (_SCL_FreeSpace     )GetProcAddress(hSCL_Dll,"SCL_FreeSpace"     );
        SCL_DirItemCount   = (_SCL_DirItemCount  )GetProcAddress(hSCL_Dll,"SCL_DirItemCount"  );
        SCL_GetDirItem     = (_SCL_GetDirItem    )GetProcAddress(hSCL_Dll,"SCL_GetDirItem"    );
        SCL_SendFile       = (_SCL_SendFile      )GetProcAddress(hSCL_Dll,"SCL_SendFile"      );
        SCL_ReceiveFile    = (_SCL_ReceiveFile   )GetProcAddress(hSCL_Dll,"SCL_ReceiveFile"   );
        SCL_RemoveFile     = (_SCL_RemoveFile    )GetProcAddress(hSCL_Dll,"SCL_RemoveFile"    );
        SCL_MD             = (_SCL_MD            )GetProcAddress(hSCL_Dll,"SCL_MD"            );
        SCL_RD             = (_SCL_RD            )GetProcAddress(hSCL_Dll,"SCL_RD"            );
        SCL_SaveFile       = (_SCL_SaveFile      )GetProcAddress(hSCL_Dll,"SCL_SaveFile"      );
        SCL_LoadFile       = (_SCL_LoadFile      )GetProcAddress(hSCL_Dll,"SCL_LoadFile"      );
        SCL_SendData       = (_SCL_SendData      )GetProcAddress(hSCL_Dll,"SCL_SendData"      );
        SCL_ReceiveData    = (_SCL_ReceiveData   )GetProcAddress(hSCL_Dll,"SCL_ReceiveData"   );
        SCL_ShowString     = (_SCL_ShowString    )GetProcAddress(hSCL_Dll,"SCL_ShowString"    );

        SCL_Reset          = (_SCL_Reset         )GetProcAddress(hSCL_Dll,"SCL_Reset"         );
        SCL_Replay         = (_SCL_Replay        )GetProcAddress(hSCL_Dll,"SCL_Replay"        );
        SCL_SetTimer       = (_SCL_SetTimer      )GetProcAddress(hSCL_Dll,"SCL_SetTimer"      );
        SCL_SetBright      = (_SCL_SetBright     )GetProcAddress(hSCL_Dll,"SCL_SetBright"     );
        SCL_SetOnOffTime   = (_SCL_SetOnOffTime  )GetProcAddress(hSCL_Dll,"SCL_SetOnOffTime"  );
        SCL_SetTempOffset  = (_SCL_SetTempOffset )GetProcAddress(hSCL_Dll,"SCL_SetTempOffset" );
        SCL_SetPowerMode   = (_SCL_SetPowerMode  )GetProcAddress(hSCL_Dll,"SCL_SetPowerMode"  );
        SCL_GetRunTimeInfo = (_SCL_GetRunTimeInfo)GetProcAddress(hSCL_Dll,"SCL_GetRunTimeInfo");
        SCL_LedShow        = (_SCL_LedShow       )GetProcAddress(hSCL_Dll,"SCL_LedShow"       );
        SCL_SetExtSW       = (_SCL_SetExtSW      )GetProcAddress(hSCL_Dll,"SCL_SetExtSW"      );
        SCL_GetPlayInfo    = (_SCL_GetPlayInfo   )GetProcAddress(hSCL_Dll,"SCL_GetPlayInfo"   );

        SCL_PictToXMPFile  = (_SCL_PictToXMPFile )GetProcAddress(hSCL_Dll,"SCL_PictToXMPFile" );
        SCL_GetMaxFileSize = (_SCL_GetMaxFileSize)GetProcAddress(hSCL_Dll,"SCL_GetMaxFileSize");
        SCL_AddXMPToXMP    = (_SCL_AddXMPToXMP   )GetProcAddress(hSCL_Dll,"SCL_AddXMPToXMP"   );
        SCL_GetFileDosDateTime = (_SCL_GetFileDosDateTime)GetProcAddress(hSCL_Dll,"SCL_GetFileDosDateTime");
    }

    // 判断函数指针获取成功否
    // Check these pointer
    if ((!hSCL_Dll          )||
        (!SCL_NetInitial    )||
        (!SCL_ComInitial    )||
        (!SCL_Close         )||
        (!SCL_SetLEDNum     )||
        (!SCL_SetRemoteIP   )||
        (!SCL_TargetSCL2008 )||
        (!SCL_GetLastResult )||

        (!SCL_InitForPackage)||
        (!SCL_GetPackage    )||
        (!SCL_CheckAnswer   )||

        (!SCL_FormatDisk    )||
        (!SCL_FreeSpace     )||
        (!SCL_DirItemCount  )||
        (!SCL_GetDirItem    )||
        (!SCL_SendFile      )||
        (!SCL_ReceiveFile   )||
        (!SCL_RemoveFile    )||
        (!SCL_MD            )||
        (!SCL_RD            )||
        (!SCL_SaveFile      )||
        (!SCL_LoadFile      )||
        (!SCL_SendData      )||
        (!SCL_ReceiveData   )||
        (!SCL_ShowString    )||

        (!SCL_Reset         )||
        (!SCL_Replay        )||
        (!SCL_SetTimer      )||
        (!SCL_SetBright     )||
        (!SCL_SetOnOffTime  )||
        (!SCL_SetTempOffset )||
        (!SCL_SetPowerMode  )||
        (!SCL_GetRunTimeInfo)||
        (!SCL_GetPlayInfo   )||
        (!SCL_LedShow       )||
        (!SCL_SetExtSW      )||

        (!SCL_PictToXMPFile )||
        (!SCL_GetMaxFileSize)||
        (!SCL_AddXMPToXMP   )||
        (!SCL_GetFileDosDateTime)        
       )
    {
        FreeLibrary(hSCL_Dll);
        hSCL_Dll = NULL;
        MessageBox("动态链接库初始化失败","SCAPI",MB_OK);
        SendMessage(WM_CLOSE,0,0L);
    }
    return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CDemo_VCDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialog::OnPaint();
    }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDemo_VCDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

void CDemo_VCDlg::OnClose()
{
    if (hSCL_Dll!=NULL) FreeLibrary(hSCL_Dll);
   
    CDialog::OnClose();
}

#define bOnlyShowStatic     FALSE           // TRUE: 只静止输出,不带移动效果, FALSE:试验发文件的方式
#define bSendFile           FALSE           // TRUE: 用 SendFile 发送文件, FALSE:用SendData,SaveFile发送文件
#define bNet                TRUE            // TRUE: 使用网络收发, FALSE: 使用串口收发
#define mDevID              13              // 通讯设备编号, 任意的2字节数
#define bSCL2008            TRUE            // 控制器类型, TRUE:SCL2008, FALSE: SuperComm
#define IPAddr              "10.1.1.100"    // 控制器 IP 地址
#define LEDNum              0               // 控制器编号
#define UDPPort             12345           // 网络通讯的 UDP 端口号
#define ComPort             1               // 串口通讯的 COM 口
#define Baudrate            38400           // 串口通讯的速率
#define TimeOut             2               // 超时上限
#define RetryTimes          2               // 重试次数
#define LEDWidth            128             // 区域宽
#define LEDHeight           32              // 区域高
#define FileName            "Test.Txt"      // 文本文件名

void CDemo_VCDlg::OnButton1()
{
char    S[1024];
BOOL    bOK;
FILE    *F;
int     Da,Ti;

    // Clear LED
    if (bSCL2008) sprintf(S,"`R00000000%04d%04d",LEDWidth,LEDHeight);
    else          sprintf(S,"`R000000%03d%03d"  ,LEDWidth,LEDHeight);

    // Use 6x12,12x12 fonts
    strcat(S,"   `A1`H2`C0000FF红色12点显示");
    strcat(S,"\n\r");

    // Use 8x16,16x16 fonts
    strcat(S,"`A3`H4`C00FF00绿色16点显示AB");

    // Use 12x24,24x24 fonts
    strcat(S,"`A5`H6`C00FFFF黄色24点显示CD`Y000");

    // Use 16x32,32x32 fonts
    strcat(S,"`M3`A7`H8`C00FFFF反白32点显示EF");

    // 保存为文本文件
    F= fopen(FileName,"w+t");
    fprintf(F,"%s",S);
    fclose(F);

    // 通讯初始化
    if (bNet) bOK = SCL_NetInitial(mDevID,"",IPAddr,TimeOut,RetryTimes,UDPPort,bSCL2008);
    else      bOK = SCL_ComInitial(mDevID,ComPort,Baudrate,LEDNum,TimeOut,RetryTimes,bSCL2008);

    if (!bOK) MessageBox("初始化失败","",MB_OK);

    // 发送文件
    if (bOK)
    {
        if (bSendFile) bOK = SCL_SendFile(mDevID,2,"",FileName);
        else
        {
            // 拆分的发送文本文件
            SCL_GetFileDosDateTime(FileName,&Da,&Ti);
            bOK = SCL_SendData(mDevID,0,strlen(S),(BYTE*)S);
            if (bOK) bOK=SCL_SaveFile(mDevID,2,FileName,strlen(S),Da,Ti);
        }
        if (!bOK) MessageBox("发送文件失败","",MB_OK);
    }
    // 通知控制器重新播放节目
    if (bOK)
    {
        if (bSCL2008) bOK = SCL_Replay(mDevID,0,0);
        else          bOK = SCL_Replay(mDevID,1,0);
        if (!bOK) MessageBox("重启节目表失败","",MB_OK);
    }

    SCL_Close(mDevID);
}

void CDemo_VCDlg::OnButton2()
{
TEXTINFO    Info;
char        S[1024];
BOOL        bOK;
    if (bSCL2008) Info.Left = 4096-LEDWidth;
    else          Info.Left =  960-LEDWidth;
    Info.Top    =  0;
    Info.Width  = LEDWidth;
    Info.Height = LEDHeight;
    Info.Color  = 0x80FF;
    Info.ASCFont= 1;   // This Font index is related with the load order of the fonts.
    Info.HZFont = 2;   // This Font index is related with the load order of the fonts.
    Info.XPos   = 0;
    Info.YPos   = 0;

    // Clear LED
    if (bSCL2008) sprintf(S,"`R00000000%04d%04d",LEDWidth,LEDHeight);
    else          sprintf(S,"`R000000%03d%03d"  ,LEDWidth,LEDHeight);

    // Use 6x12,12x12 fonts
    strcat(S,"  `A1`H2`C0000FF红色12点显示");

    // Use 8x16,16x16 fonts
    strcat(S,"`A3`H4`C00FF00绿色16点显示AB");

    // Use 12x24,24x24 fonts
    strcat(S,"`A5`H6`C00FFFF黄色24点显示CD`Y000");

    // Use 16x32,32x32 fonts
    strcat(S,"`M3`A7`H8`C00FFFF反白32点显示EF");

    // 通讯初始化
    if (bNet) bOK = SCL_NetInitial(mDevID,"",IPAddr,TimeOut,RetryTimes,UDPPort,bSCL2008);
    else      bOK = SCL_ComInitial(mDevID,ComPort,Baudrate,LEDNum,TimeOut,RetryTimes,bSCL2008);

    if (!bOK) MessageBox("初始化失败","",MB_OK);

    if (!bOnlyShowStatic)
    {
        // 删除移动播出的文本文件
        // 仅实现静止显示则可不调用这个函数
        if (bOK)
        {
            bOK = SCL_RemoveFile(mDevID,2,FileName);
            if (!bOK) MessageBox("删除文件失败","",MB_OK);
        }

        // 重启节目表,使屏幕静止(因为节目表中的文本文件不存在了)
        // 仅实现静止显示则可不调用这个函数
        if (bOK)
        {
            if (bSCL2008) bOK = SCL_Replay(mDevID,0,0);
            else          bOK = SCL_Replay(mDevID,1,0);
            if (!bOK) MessageBox("重启节目表失败","",MB_OK);
            Sleep(1000);
        }
    }

    // 显示文字串,自动排版,超出部分自动截断
    if (bOK)
    {
        bOK = SCL_ShowString(mDevID,(short*)&Info.Left,S);
        if (!bOK) MessageBox("文字直接输出失败","",MB_OK);
    }
    SCL_Close(mDevID);
}

搜索更多相关主题的帖子: 测试 公司 include file 
2012-03-09 13:56
快速回复:C++新人求教(关于LED测试程序)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032410 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved