I work on project based on a FASTRACK SUPREME which has to receive commands via a serial RS232. The
problem is: When I use HyperTerm the command ATDxxxxxxxxx; works fine. When I use the CVI RS232 library nothing happens. Is it possible that my command remains blocked in
the serial buffer? Here is my code:
#include &l开发者_运维百科t;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;
}
Where is the problem? Please help! Thanks.
I tried your code as it was. I am not sure what you mean by "nothing happens" When I used the code as it is (except I had to use port 2) everything worked well. the character count was 18 out of the ComWrt function.
Make sure the com port you are trying to use is available.
with the exception of your #includes, here is your code with minor mods that I ran on my PC, WinXP running CVI 2010:
#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;
}
精彩评论