我在一个基于FASTRACK至上的项目中工作,它必须通过串行RS232接收命令。这个
问题是:当我使用HyperTerm时,命令ATDxxxxxxxxx;工作正常。当我使用CVI RS232库时,没有任何反应。是否可能我的命令仍然被阻止在
串行缓冲区?下面是我的代码:
#include <ansi_c.h>
#include <cvirte.h>
#include <userint.h>
#include <rs232.h>
#include <utility.h>
#include <formatio.h>
#include <string.h>
int configurePort(void);
int sendCommand(void);
int port_open;
int error;
int main()
{
configurePort();
sendCommand ();
return 0;
}
int configurePort()
{
port_open = 0;
error = OpenComConfig (4, "COM4",115200 ,0,8,1,0, -1);
if (error)
{
printf("Error!\n");
}
if (error == 0)
{
port_open = 1;
SetXMode (4, 0);
SetCTSMode (4, 0);
SetComTime (4, 0);
}
return 0;
}
int sendCommand ()
{
char bufferWrite[100] ;
Fmt(bufferWrite,"%s","ATD0040761768027;");
ComWrt(4, bufferWrite, 18);
return 0;
}问题出在哪里?请帮帮我!谢谢。
发布于 2011-04-23 05:43:42
我试过你的代码了。我不确定你所说的“什么都没有发生”是什么意思,当我原样使用代码时(除了我不得不使用端口2),一切都运行得很好。ComWrt函数中的字符数为18个。
确保您尝试使用的com端口可用。
除了你的#includes之外,下面是我在我的PC上运行的带有次要mods的代码,WinXP运行CVI2010:
#define PORT 2
#define PORTNAME "COM2"
int configurePort(void);
int sendCommand(void);
int port_open;
int error;
int main()
{
configurePort();
sendCommand ();
return 0;
}
int configurePort()
{
port_open = 0;
error = OpenComConfig (PORT, PORTNAME,115200 ,0,8,1,0, -1);
if (error)
{
printf("Error!\n");
}
if (error == 0)
{
port_open = 1;
SetXMode (PORT, 0);
SetCTSMode (PORT, 0);
SetComTime (PORT, 0);
}
return 0;
}
int sendCommand ()
{
char bufferWrite[100] ;
Fmt(bufferWrite,"%s","ATD0040761768027;");
error = ComWrt(PORT, bufferWrite, sizeof("ATD0040761768027;"));
return 0;
}https://stackoverflow.com/questions/3088788
复制相似问题