LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ComWrt randomly send twice the same string

Dear all,

 

I have recently ported to a Windows 7 machine an old program which communicates with an Arduino board through (virtual) serial port; the problem is that sometimes (once every about 10 times) the ComWrt function sends the same command to the Arduino board twice; I repeat: in debug mode I "step over" to a call to ComWrt once and I see on the serial line that the string is sent twice! I tried many combination of computers/cvi versions and it seems that the culprit is Windows 7, in fact the exact same program running in two different old xp machines does not show this behaviour and ComWrt seems to run smoothly. Any ideas?

 

Thanks and best regards!

 

Nicola

0 Kudos
Message 1 of 5
(4,946 Views)

Dear Nicola,

 

did you try even with a serial loopback test?

 

Did you call only one time the ComWrt function, or it's called in a loop?

 

Take a look to this document hoping you'll find something helpful.

 

Kind regards.

 

Cla_CUP

0 Kudos
Message 2 of 5
(4,928 Views)

Hi! Thanks for your answer; from what you write I understand that you suspect some kind of timing problem so that it happens that during the i cycle of a for loop the ComWrt command does nothing but the i+1 cycle the second ComWrt triggers also the previous one and it seems that the second ComWrt sends two strings. Well, this is not the case; my program is not a simple for loop but anyway it acts in a similar manner, i.e. during one run it sends a sequence of 2 commands to the arduino board every 1 second: CMD1, CMD2, 1 sec, CMD1, CMD2, 1 sec .... Ok, now sometimes Arduino receive CMD1, CMD1, CMD2, 1 sec, CMD1, CMD2, 1 sec... and so on. In other words I call ComWrt let's say 10 times and Arduino receive 11 strings! I understand that it sounds crazy but this is what happens and I really don't know what can I do....

A last remark about the loopback suggestion: I didn't tried this trick but I have verified the problem in a very direct way, looking to the serial line with an oscilloscope 🙂

 

Thanks again for your help and best regards!

 

Nicola

0 Kudos
Message 3 of 5
(4,924 Views)

You said (virtual) serial port. Does that mean , that the Arduino is connected using an USB-port and an USB-to-serial converter ?

Did you allready look for newer drivers for that USB-to-serial converter ?

0 Kudos
Message 4 of 5
(4,884 Views)

Hi all, now I can update about my problem and its unexpected solution; in the same time I will answer to the last question.

 

In order to simplify the problem, and following the first suggestion, I put the Arduino board in loopback configuration (no program running in the board, hardware shortcut of RX-TX pin on the borad) and I run the following code:

 

int main (int argc, char *argv[])
{
char buffer[30];
int i;
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
OpenComConfig(3,"",9600,0,8,1,0,0);
for (i=0; i<1000; i++)
{
DebugPrintf("Run no. %i\n", i);
ComWrt(3, "\r", 1);
ComRdTerm(3, buffer, 20, '\r');
Delay(.1);
if (GetInQLen(3)>0)
{
DebugPrintf("Fail!\n");
return 1;
}
}
return 0;
}

 

I connected the Arduino board by means of its USB port (which is seen by the computer as a virtual serial port), and it fails. I took also a USB-serial adapter, with pin 2-3 shotcut, and in this case the program runs smoothly: so I can state that it is a problem in Arduino serial port driver (note: I have tried both the last driver 1.6.0 and an old one 1.0.0, but nothing). I tried than to do the same thing with LabView but I used instead the VISA system (because I think it is the only way to use serial port in LW, I'm not expert) and it works! So I can also state that the problem is in the way that ComWrt interacts with the arduino driver in Win7. Than I have also tried using VISA system in LabWindows with the following code:

 

int main (int argc, char *argv[])
{
ViStatus status;
ViSession defaultRM, instr;
ViUInt32 retCount;
ViChar buffer[MAX_CNT];
int i;

if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */

status = viOpenDefaultRM(&defaultRM);
status = viOpen(defaultRM, "COM3", VI_NULL, VI_NULL, &instr);

for (i=0; i<10000; i++) {
DebugPrintf("Run no %i\n", i);
status = viWrite(instr, "Test\n", 5, &retCount);
Delay(0.100);
status = viRead(instr, buffer, MAX_CNT, &retCount);
if (retCount>5) {
DebugPrintf("Fail!\n");
break;
}

}


status = viClose(instr);
status = viClose(defaultRM);
return 0;
}

 

And, surprise!, it works also with the arduino board. So I understand that VISA and ComWrt use the serial port in a very different way!

 

To conclude, the initial problem remains unsolved and it seems that the combination LabWindows(ComWrt)+Win7+Arduino is bad; good solutions are: (1) XP instead of 7, (2) USB-serial adapter instead of direct USB connection with Arduino, (3) VISA system instead of direct ComWrt function. The latter seems to me the best alternative.

 

Best regards,

 

Nicola

0 Kudos
Message 5 of 5
(4,866 Views)