LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Communication works randomly

Hey Guys,

At the moment we are developing a software for an automised testbed of a satellite. For this task, we are using LabWindows 2015.
We are trying to communicate via COM-Port.

Actually we are using the following C-Code, recreated from one of your examples:

----------------------------------------------

/*****The connect-function*****/

    DisableBreakOnLibraryErrors();
    ComNumber = 3;
    //Connecting the Sensor - ComNumer = 3
    ErrorCode = OpenComConfig(ComNumber, "" , 9600, 0, 8, 1, 512, 512);
    
    EnableBreakOnLibraryErrors ();
                                       
        if(ErrorCode == 0){
        SetCtrlVal(maintabHandle, Humidity_HumidityStatusString, "Successfully connected");
        SetCtrlVal(maintabHandle, Humidity_HumidityState, 1);
        SetXMode (ComNumber, 0);
        SetCTSMode (ComNumber, 0);
        SetComTime (ComNumber, 5);
    }else{
        SetCtrlVal(maintabHandle, Humidity_HumidityStatusString, "Can not connect to Sensor");
        SetCtrlVal(maintabHandle, Humidity_HumidityState, 0);
    }

/*****The Send-function*****/

    
    int send_byte;
    GetCtrlVal (maintabHandle, Humidity_HumidityByte1, &send_byte);
        ErrorCode = ComWrtByte (ComNumber, send_byte);
    printf("Send Bytes: %d", ErrorCode);
    Delay(0.1);
            
    GetCtrlVal (maintabHandle, Humidity_HumidityByte2, &send_byte);
        ErrorCode = ComWrtByte (ComNumber, send_byte);
    printf("Send Bytes: %d", ErrorCode);
    Delay(0.1);
            
    GetCtrlVal (maintabHandle, Humidity_HumidityByte3, &send_byte);
        ErrorCode = ComWrtByte (ComNumber, send_byte);
    printf("Send Bytes: %d", ErrorCode);
    Delay(0.1); 
            
    GetCtrlVal (maintabHandle, Humidity_HumidityByte4, &send_byte);
        ErrorCode = ComWrtByte (ComNumber, send_byte);
    printf("Send Bytes: %d", ErrorCode);
    Delay(0.1);
            
    GetCtrlVal (maintabHandle, Humidity_HumidityByte5, &send_byte);
        ErrorCode = ComWrtByte (ComNumber, send_byte);
    printf("Send Bytes: %d", ErrorCode);
    Delay(0.1);


/*****The Read-function*****/
        
    char BufferRd[1000] = "";
    ErrorCode = ComRd(ComNumber, BufferRd, GetInQLen (ComNumber));
    SetCtrlAttribute(maintabHandle, Humidity_HumidityTempExtLbl, ATTR_CTRL_VAL, BufferRd);

/* Comment: The connect-, read- and the sendfunction are connected to buttons. Between every Sending Process the system waits for 100ms, so we can see how many
times the LED on our Devices blinks.
Most times, everthing works fine. We are connecting (ErrorCode 0), sending 5 Bytes of data (ComStat = ok, OutputQ is 0), our Devices are responding
and we can read these Data with the read-function. But sometimes it wont work at all. We are connecting (ErrorCode 0), send the Data, our Devices are blinking,
so that we thought they have received the data. But after that nothing happens... Seems like the program does not send the correct data... Iam a little
bit curious about the problem...*/


----------------------------------------------


We are facing the following Problem: We are supervising the Serial-Communication through a serial sniffer. If we send the data packet, the sniffer
shows us the correct sended ASCII-Symbols and the devices displayed a Notification, that they have received a paket. Unfortunatly it seems, that sometimes the paket does not
contain the right Symbols. Our devices are not responding correctly. If we send the same data paket with a normal Hyper Terminal like "hTerm"
our Devices are responding correctly everytime. We even tried it without the serial sniffer, so that we can excluse this cause of defect.

Do you have any idea why the behave of our Devices is different (in a positiv way), when we are using the Hyper terminal?

We are using Labwindows CVI 2015 Full Development System v. 15.0.0 (408) , Windows 7....

Thank you for you support!

Regards
A

0 Kudos
Message 1 of 2
(3,963 Views)

Have you tried disabling the output buffer?

For that, you need to type -1 as the last parameter to OpenComConfig.

This makes the ComWrite action more deterministic.

Otherwise, Windows transmits buffer content whenever it think is convenient.

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 2
(3,879 Views)