cpubbs论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

LabVIEW+单片机学习套件全套教程资料下载[免费]LabVIEW论坛精华列表贴USB0816数据采集卡《LabVIEW宝典》
LabWindows/CVI论坛精华贴NET0816以太网数据采集卡RC0210远程设备授权系统 关闭关停锁定打开设备 户外分布式数据采集
NET1624低速高精度以太网数据采集卡WIFI0824SD无线WIFI网络数据采集卡脱机运行 SD存储 小尺寸微型 串口采集远程采集 安卓 手持移动采集 纪录仪
查看: 1147|回复: 1

求助 这个程序不知道哪里错了 抓狂

[复制链接]
发表于 2011-3-6 16:36:50 | 显示全部楼层 |阅读模式
#include <ansi_c.h>
#include <cvirte.h>  
#include <userint.h>
#include "rs232.h"
#include <rs232.h>  
#include <formatio.h>  
static int panelHandle;
    int comselect;
    int status;
    char info[20],readBuf[20];
   
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
  return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "rs232.uir", PANEL)) < 0)
  return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}

int CVICALLBACK Config (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
int btlselect,jhselect,longselect,stopselect;
int comvalue,btlvalue,longvalue,stopvalue,jhvalue;
switch (event)
  {
  case EVENT_COMMIT:
  GetCtrlVal (PANEL, PANEL_COMSELECT, &comvalue);    /* 获取端口号 */   
  switch (comvalue)
   {
   case 1:
    comselect=1;
    break;
   case 2:
    comselect=2;  
    break;
   case 3:
    comselect=3;  
    break;
   case 4:
    comselect=4;  
    break;
   }
   GetCtrlVal (PANEL, PANEL_BTLSELECT, &btlvalue);     /* 波特率*/   
   switch (btlvalue)
    {
    case 1:
     btlselect=1200;
     break;
    case 2:
     btlselect=2400;
     break;
    case 3:
     btlselect=4800;
     break;
    case 4:
     btlselect=9600;
     break;
    case 5:
     btlselect=19200;
     break;
    }
     GetCtrlVal (PANEL, PANEL_JYSELECT, &jhvalue);      /* 奇偶校验*/   
       switch (jhvalue)
    {
      case 1:
    jhselect=0;
     break;
      case 2:
    jhselect=1;   
     break;
      case 3:
    jhselect=2;   
     break;
    }
     GetCtrlVal (PANEL, PANEL_LONGSELECT, &longvalue);     /* 字长 */   
     switch (longvalue)
      {
      case 1:
       longselect=7;
       break;
      case 2:
       longselect=8;  
       break;
      case 3:
       longselect=9;
       break;
      }
   GetCtrlVal (PANEL, PANEL_STOPSELECT, &stopvalue);       /* 停止位*/   
       switch (stopvalue)
        {
        case 1:
         stopselect=1;
         break;
        case 2:
         stopselect=2;
         break;
        }
    status=OpenComConfig(comselect,"",btlselect,jhselect,longselect,stopselect,512,512);     /* 打开串口*/   
    if(status!=0)
       {
       MessagePopup("Error","config failed!");
       return 0;
       }
     SetCTSMode(comselect,LWRS_HWHANDSHAKE_OFF);      /*禁止硬件握手 */   
   break;
  }
return 0;
}
int CVICALLBACK Send (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
switch (event)
  {
  case EVENT_COMMIT:
  FlushInQ(comselect);      /* 清空串口输入队列 */   
  FlushOutQ(comselect);    /* 清空串口输出队列 */   
  GetCtrlVal (PANEL, PANEL_SENDTEXT, info);
  status=ComWrt(comselect,info,strlen(info));
  if(status!=strlen(info))
    MessagePopup("Error","Send data failed!");
   break;
  }
return 0;
}
int CVICALLBACK Receive (int panel, int control, int event,    /* 接收数据函数 */   
  void *callbackData, int eventData1, int eventData2)
{
switch (event)
  {
  case EVENT_COMMIT:
   status=ComRd(comselect,readBuf,strlen(info));
   if(status!=strlen(info))
      {
     MessagePopup("Error","Read data failed!");
     break;
      }
   SetCtrlVal (PANEL, PANEL_RECEIVETEXT, readBuf);
   SetActiveCtrl (PANEL, PANEL_RECEIVETEXT);
   break;
  }
return 0;
}
int CVICALLBACK Clearsend (int panel, int control, int event,    /* 清空发送框 */   
  void *callbackData, int eventData1, int eventData2)
{
switch (event)
  {
  case EVENT_COMMIT:
  ResetTextBox(PANEL,PANEL_SENDTEXT,"\0");
   break;
  }
return 0;
}
int CVICALLBACK Clearreceive (int panel, int control, int event,    /* 清空接收框 */   
  void *callbackData, int eventData1, int eventData2)
{
switch (event)
  {
  case EVENT_COMMIT:
  ResetTextBox(PANEL,PANEL_RECEIVETEXT,"\0");
   break;
  }
return 0;
}
int CVICALLBACK Quit (int panel, int control, int event,       /* 退出 */   
  void *callbackData, int eventData1, int eventData2)
{
switch (event)
  {
  case EVENT_COMMIT:
  
   QuitUserInterface (0);
   break;
  }
return 0;
}

 楼主| 发表于 2011-3-6 16:38:46 | 显示全部楼层
如题  我想写一个简单的rs232数据传输,但是  系统第一次是可以正确运行的  还生成了可执行文件  后来 就不行了  总是报错  似乎是数据传输的函数出了什么问题  不清楚   求教 ~~~~~谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|cpubbs论坛. ( 粤ICP备09171248号 )

GMT+8, 2025-4-4 13:59 , Processed in 1.427746 second(s), 7 queries , Gzip On, File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表