2010-06-21 100 views
0

我在基於FASTRACK SUPREME的項目上工作,該程序必須通過串行RS232接收命令。通過LabWindows/CVI中的RS232通過RS232發送ATD命令到Fastrack Supreme

問題是: 當我使用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; 
} 

問題出在哪裏?請幫忙! 謝謝。

回答

0

我試過你的代碼,因爲它是。我不確定你的意思是什麼「沒有任何反應」當我使用代碼時(除了必須使用端口2),一切運行良好。 ComWrt函數中的字符數爲18。

確保您嘗試使用的端口可用。

與你的#includes外,這裏是你的代碼,我在我的電腦上運行輕微MODS,WINXP運行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; 
    }