From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ComWrt Problem

Hi all,

I am developing an application that to sent some string to the com
port.
I send the string by the function ComWrt of library RS232. However, I
noticed that only partial of my string string is sent to com port by
using some "port monitoring" software. There are about 250 characters
in my string, but there are only about 20 characters is sent to the
com port. I have already set the com port output queue size as -1 to
use synchronous transmisssion.

What is the reason for this?

Any suggestion will be greatly appreicated!
Thanks in advance
Ivan
0 Kudos
Message 1 of 4
(3,235 Views)
Hi,
exactly what is the string?
You might find that you have a null "/0" in the string you're sending, so ComWrt is only seeing the text before this. (In this case, use ComWrtByte instead, but you have to send each character separately to do this).
What value does the ComWrt return to you? i.e.

char buf[100];
Fmt(buf,"%s","Hello, World!");
if (ComWrt (2, buf, 13) != 13)
/* Operation was unsuccessful. */;

ComWrt sends bytes from the output queue to the serial device under interrupt control without program intervention. If you close the port before all bytes are sent, you lose the bytes that remain in the queue. To guarantee that all bytes are removed from the output queue before you close the port, call GetOutQLen. GetOutQLen returns the number of bytes
that remain in the output queue.

try putting a breakpoint just after the ComWrt, and see how many characters you get out then.

Your port monitoring software might also be having a problem with white spaces etc. You could try connecting pins 2 and 3 (Tx and Rx) with a paper clip, and then you could read back on the same port to check the data is really sent in your software. (You need to turn off the handshaking if these are the only two pins you're connecting.

Hope that helps

Thanks

Sacha Emery
National Instruments (UK)
// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 2 of 4
(3,235 Views)
SachaE,

Thanks for help.

The string I want to sent to com port is actually some numbers of type
'short'. The following code fragment may illustrate what I am doing.

typedef UINT16 unsigned short
UINT16 buffer[265];
..
..//fill in data to buffer[]
..
ComWrt(2, (char *)buffer, 265);
do{
remain=GetOutLen(2);
}while (remain>0)



I think there is no "/0" in the numbers, and it is always stopped
sending at the 21st number. But it okay for me to use comWrtByte


Thanks,
Ivan

SachaE wrote in message news:<5065000000050000004C840100-1079395200000@exchange.ni.com>...
> Hi,
> exactly what is the string?
> You might find that you have a null "/0" in the string you're sending,
> so ComWrt is only seeing the text before this. (In this case, use
> ComW
rtByte instead, but you have to send each character separately to
> do this).
> What value does the ComWrt return to you? i.e.
>
> char buf[100];
> Fmt(buf,"%s","Hello, World!");
> if (ComWrt (2, buf, 13) != 13)
> /* Operation was unsuccessful. */;
>
> ComWrt sends bytes from the output queue to the serial device under
> interrupt control without program intervention. If you close the port
> before all bytes are sent, you lose the bytes that remain in the
> queue. To guarantee that all bytes are removed from the output queue
> before you close the port, call GetOutQLen. GetOutQLen returns the
> number of bytes that remain in the output queue.
>
> try putting a breakpoint just after the ComWrt, and see how many
> characters you get out then.
>
> Your port monitoring software might also be having a problem with
> white spaces etc. You could try connecting pins 2 and 3 (Tx and Rx)
> with a paper clip, and then you could read back on the same port to
> check the data is really sent in
your software. (You need to turn off
> the handshaking if these are the only two pins you're connecting.
>
> Hope that helps
>
> Thanks
>
> Sacha Emery
> National Instruments (UK)
0 Kudos
Message 3 of 4
(3,235 Views)
SachaE,

Thanks for help.

The string I want to sent to com port is actually some numbers of type
'short'. The following code fragment may illustrate what I am doing.

typedef UINT16 unsigned short
UINT16 buffer[265];
..
..//fill in data to buffer[]
..
ComWrt(2, (char *)buffer, 265);
do{
remain=GetOutLen(2);
}while (remain>0)



I think there is no "/0" in the numbers, and it is always stopped
sending at the 21st number. But it okay for me to use comWrtByte


Thanks,
Ivan

SachaE wrote in message news:<5065000000050000004C840100-1079395200000@exchange.ni.com>...
> Hi,
> exactly what is the string?
> You might find that you have a null "/0" in the string you're sending,
> so ComWrt is only seeing the text before this. (In this case, use
> ComW
rtByte instead, but you have to send each character separately to
> do this).
> What value does the ComWrt return to you? i.e.
>
> char buf[100];
> Fmt(buf,"%s","Hello, World!");
> if (ComWrt (2, buf, 13) != 13)
> /* Operation was unsuccessful. */;
>
> ComWrt sends bytes from the output queue to the serial device under
> interrupt control without program intervention. If you close the port
> before all bytes are sent, you lose the bytes that remain in the
> queue. To guarantee that all bytes are removed from the output queue
> before you close the port, call GetOutQLen. GetOutQLen returns the
> number of bytes that remain in the output queue.
>
> try putting a breakpoint just after the ComWrt, and see how many
> characters you get out then.
>
> Your port monitoring software might also be having a problem with
> white spaces etc. You could try connecting pins 2 and 3 (Tx and Rx)
> with a paper clip, and then you could read back on the same port to
> check the data is really sent in
your software. (You need to turn off
> the handshaking if these are the only two pins you're connecting.
>
> Hope that helps
>
> Thanks
>
> Sacha Emery
> National Instruments (UK)
0 Kudos
Message 4 of 4
(3,235 Views)