Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Hyperterminal Vs. CVI rs232 library

I have an rs232 interfaced instrument that I can control using Hyperterminal, but works erratically when I issue the same commands using Lab Windows CVI rs232 library.  Same cable, same serial port.  I thought of inter-character timing and introduced some padding, but this makes no difference.  I have seen code for this same instrument written in C++ using ComWrt and ComRd that apparently works fine.  I have tried the CVI code on two different instruments of the same model, both act the same way. 

I have the Hyperterminal timing settings both at 0, and "autodetect" terminal emulation.

Has anyone seen this type of problem?  Does anyone know how Hyperterminal implements the auto-detect emulation, could this be the difference?  Is there something peculiar to the functionality of the Hyperterminal "connect" button as opposed to the rs-232 library OpenComConfig?

Bob Hayes
0 Kudos
Message 1 of 4
(3,708 Views)
Which functions are you using in CVI?  Is this instrument plugged into the COM port on your computer or into a Serial Card?  You can also open a VISA test panel in Measurement and Automation Explorer by going to Devices and Interfaces>>Ports>>COM.  After you locate the port, right-click and open a VISA Test session or check your port settings in here.  The following link talks about using ComWrt and ComRd in CVI, so if you are having trouble with VISA commands you could try these.
0 Kudos
Message 2 of 4
(3,706 Views)

Thank you for the response! I mis-spoke (mis-typed?).  The working code doesn't use CVI at all, it uses CreateFile, WriteFile, and Readfile, which are Win32 API calls I believe.  Below is the code that opens the com port to the device.   I suspect that there's something different in the semantics of this code compared to OpenComConfig.  The DCB used to configure the com port appears to have more detail in it than what's provided by OpenComConfig and one of these settings is making a difference.

bool SerialInterface::Open(void) {
 bool rtn=false;
 int errCode=0;
 DCB commDCB;

 ResetEvent(TerminateEvent);
 if ((hComm =CreateFile(Port, GENERIC_READ | GENERIC_WRITE, 0,0, OPEN_EXISTING, 0,0))!=INVALID_HANDLE_VALUE) {
  if ( GetCommState(hComm, &commDCB)!=0){
   if (BuildCommDCB(Settings, &commDCB)!=0){
    if (SetCommState(hComm, &commDCB)!=0 ){
     if (SetCommTimeouts(hComm, &timeouts)==TRUE){
      if (InitializeComm()==true){     rtn=true;
      if (rtn!=true){.......
   return(rtn);
}

0 Kudos
Message 3 of 4
(3,695 Views)
I would try using VISA from CVI for your serial communications.  There is an example that should be on your computer at C:\VXIPNP\WinNT\NIvisa\Examples\C\Serial\RdWrtSrl_CVI.prj  You might also look at the following example:
 
As I said above, you can test your connection and VISA settings in Measurement and Automation Explorer
0 Kudos
Message 4 of 4
(3,677 Views)