⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arrayfile.c

📁 labwindows 利用I/O读写文件。
💻 C
字号:
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* FILE:    arrayfile.c                                                      */
/*                                                                           */
/* PURPOSE: This example illustrates how to use the Formatting and IO        */
/*          functions ArrayToFile and fileToArray to write/read a data file. */
/*                                                                           */
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
/* Include files                                                             */
/*---------------------------------------------------------------------------*/
#include <cvirte.h>
#include <userint.h>
#include <formatio.h>
#include <utility.h>
#include <stdlib.h>
#include "arrayfile.h"
#include "EasyUSB214x.h"
//#include "USB.h"
//#include "SiUSBXp.h"
/*---------------------------------------------------------------------------*/
/* Defines                                                                   */
/*---------------------------------------------------------------------------*/
#define COUNT 100

/*---------------------------------------------------------------------------*/
/* Module-globals                                                            */
/*---------------------------------------------------------------------------*/
static char proj_dir[MAX_PATHNAME_LEN];
static char file_name[MAX_PATHNAME_LEN];
static double wave[100];
static int handle;
static int err;
static char temp[40];
static unsigned char *Mainrecbuffer;//caiyaozhong
static unsigned char iMain;//caiyaozhong 
/*---------------------------------------------------------------------------*/
/* This is the application's entry-point.                                    */
/*---------------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;
    GetProjectDir (proj_dir);
    if ((handle = LoadPanel (0, "arrayfile.uir", Examp1)) < 0)
        return -1;
    SetPanelAttribute(handle, ATTR_TITLE, "Example - Write to Ascii File");
    DisplayPanel (handle);
    RunUserInterface ();
    DiscardPanel (handle);
    CloseCVIRTE ();
    return 0;
}

/*---------------------------------------------------------------------------*/
/* Plot some data to the Graph control.                                      */
/*---------------------------------------------------------------------------*/
int CVICALLBACK Plot (int panel, int control, int event, void *callbackData,
                      int eventData1, int eventData2)
{
    int i;

    if (event == EVENT_COMMIT)
        {
        for (i=0;i<COUNT;i++)
            wave[i] = (double)(rand() % 32768);
        DeleteGraphPlot (handle, Examp1_Graph, -1, 1);
        PlotY (handle, Examp1_Graph, wave, COUNT, VAL_DOUBLE, VAL_THIN_LINE,
               VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
        SetCtrlAttribute (handle, Examp1_Save, ATTR_DIMMED, 0);
		iMain=ReadData214x(0,Mainrecbuffer,16,1);
		iMain=ReadData214x(0,Mainrecbuffer,16,1); 
        }
    return 0;
}

/*---------------------------------------------------------------------------*/
/* This function brings up a File Selection dialog and allows you to enter a */
/* file name with a .dat extension.  After the file name is entered or       */
/* selected, that file is opened and assigned a file handle.                 */
/* This file handle is used anytime action is performed on the file.  The    */
/* file is written using the ArrayToFile function, then closed.              */
/*---------------------------------------------------------------------------*/
int CVICALLBACK Save (int panel, int control, int event, void *callbackData,
                      int eventData1, int eventData2)
{

    int i;
    int fileType;

    if (event == EVENT_COMMIT)
        {
        if (FileSelectPopup (proj_dir, "*.dat", "*.dat",
                             "Name of File to Save", VAL_OK_BUTTON, 0, 1, 1,
                             0, file_name) > 0)
        {
            GetCtrlVal (handle, Examp1_OutputType, &fileType);
            ArrayToFile (file_name, wave, VAL_DOUBLE, COUNT, 1,
                         VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS,
                         VAL_CONST_WIDTH, 10, fileType, VAL_TRUNCATE);
            SetCtrlAttribute (handle, Examp1_Save, ATTR_DIMMED, 1);
            SetCtrlAttribute (handle, Examp1_Read, ATTR_DIMMED, 0);
        }
    }
    return 0;
}

/*---------------------------------------------------------------------------*/
/* Read data from the file into our array, then plot it.                     */
/*---------------------------------------------------------------------------*/
int CVICALLBACK Read (int panel, int control, int event, void *callbackData,
                      int eventData1, int eventData2)
{
    int i;
    int status;
    int fileType;

    if (event == EVENT_COMMIT)
        {
        if (FileSelectPopup ("", "*.dat", "*.dat", "Name of File to Read",
              VAL_OK_BUTTON, 0, 1, 1, 0, file_name) > 0)
            {
            GetCtrlVal (handle, Examp1_InputType, &fileType);
            FileToArray (file_name, wave, VAL_DOUBLE, COUNT, 1,
                         VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS, fileType);
            DeleteGraphPlot (handle, Examp1_Graph2, -1, 1);
            PlotY (handle, Examp1_Graph2, wave, COUNT, VAL_DOUBLE,
                   VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1,VAL_RED);
            }
        }
    return 0;
}

/*---------------------------------------------------------------------------*/
/* Quit the application                                                      */
/*---------------------------------------------------------------------------*/
int CVICALLBACK Quit (int panel, int control, int event, void *callbackData,
                      int eventData1, int eventData2)
{
    if (event == EVENT_COMMIT)
        QuitUserInterface (0);
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -