//*********************************************************
// Labwindows/cvi8.5 RS232接收文件
// szlihongtao
// 2010-06-19
// 参照 王建新的<Labwindows/cvi测试技术及工程应用> page185
// 稍有改写
//*********************************************************
#include "toolbox.h"
#include <ansi_c.h>
#include <rs232.h>
#include <cvirte.h>
#include <userint.h>
#include "232.h"
//*********************************************************
static int bytesread;
static char filename[MAX_PATHNAME_LEN];
static char pathname[MAX_PATHNAME_LEN];
static int panelHandle;
int COM_Port;
//*********************************************************
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "232.uir", PANEL)) < 0)
return -1;
COM_Port=2;
OpenComConfig (COM_Port, "", 57600, 1, 8, 1, 32767, 32767); //打开并配置串口Com2
SetComTime (COM_Port, 5.0); //设置通信超时时间
SetXMode (COM_Port, 0); //禁止串口软件握手
SetCTSMode (COM_Port, LWRS_HWHANDSHAKE_OFF); //禁止硬件握手
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
//*********************************************************
int CVICALLBACK receivefilename (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
{
filename[0] = '\0';
SetCtrlVal (panelHandle, PANEL_STRING, "");
bytesread = ComRdTerm (COM_Port, filename, 260, 13); //读取字符串直到回车符---13 出现
filename[bytesread]= '\0'; //当出现回车符后,在其后加上结束符
SetCtrlVal (panelHandle, PANEL_STRING, filename);
break;
}
}
return 0;
}
//*********************************************************
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
{
CloseCom (COM_Port); //关闭串口Com2
QuitUserInterface (0);
break;
}
}
return 0;
}
//*********************************************************
int CVICALLBACK filesel (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int selstatus;
switch (event)
{
case EVENT_COMMIT:
{
selstatus = DirSelectPopup ("", "保存文件", 1, 1, pathname);
if (selstatus)
{
strcat (pathname, "\\");
strcat (pathname, filename);
SetCtrlVal (panelHandle, PANEL_STRING_2, pathname);
}
break;
}
}
return 0;
}
//*********************************************************
int CVICALLBACK receivefile (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int result;
int filesize;
int inputqueuelen;
FILE *stream;
switch (event)
{
case EVENT_COMMIT:
{
GetCtrlVal (panelHandle, PANEL_STRING_2, pathname);
//判断文件是否存在
result = FileExists (pathname, &filesize);
if (!result)
{
stream = fopen (pathname, "wb+"); // 创建新文件
fclose (stream);
}
//设置串口Com2调制解调器参数
XModemConfig (COM_Port, 10.0, 10, 5.0, 1024);
//设置从串口Com2接收文件数据
XModemReceive (COM_Port, pathname);
//获得串口Com2输入队列的字符串数目
inputqueuelen = GetInQLen (COM_Port);
if (inputqueuelen == 0)
MessagePopup ("文件保存", "文件保存完毕!");
break;
}
}
return 0;
}
//*********************************************************
//*********************************************************
//*********************************************************
文章评论(0条评论)
登录后参与讨论