LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ComWrt Function Problem

I am writing a command to an instrument

The instrument expects the command to be terminated with CRLF \r\n or 13 10.  Is LabWindows putting an additional byte such as the null character on the end of the buffer? For some reason this command works in HyperTerm  or MatLAB no problem but LabWIndows does not work?

thanks,

0 Kudos
Message 1 of 7
(4,757 Views)
ComWrt() sends as many bytes as you request it to send.  You can check the return value to see if all bytes have been placed in the output queue.  Any chance the com port is being closed before the bytes have actually been output from the com port UART?
0 Kudos
Message 2 of 7
(4,752 Views)
It would be very helpful to see some code that shows how and what you are writing to the port.  MVR is correct that ComWrt will write exactly the number of bytes you specify, so if you are passing the size used to dynamically allocate the buffer, you probably are writing an extra null byte.   What kind of problem are you experiencing?  Is the instrument not receiving the message or is it receiving an unrecognized/corrupt message?

Mert A.
National Instruments
0 Kudos
Message 3 of 7
(4,751 Views)
thanks for your assistance.

*
2  = STX
3  = ETX
Com port settings same in both cases 9600,7,Even, 1

MatLAB command:
fwrite(obj, [2 48 48 53 52 49 32 32 32 3 49 51 13 10])

works fine because the instrument switches from normal mode to PC REMOTE MODE and you see it on the LCD and can querry the measurement and get it back.

LabWINDOWS command
char PC_MODE_CMD[14]={2,48,48,53,52,49,32,32,32,3,49,51,13,10};
    OpenComConfig (1, "", 9600, 2, 7, 1, 512, 512);         
            bytes = ComWrt (1, PC_MODE_CMD, 14);

doesn't work because the instrument doesn't even switch into the PC REMOTE MODE!!!!!!!

So i am thinking the function ComWrt is doing something like inserting a Null at the end of the string??? If I had a serial data analyzer that would tell me for sure...

Suggestions??
Thank you.

0 Kudos
Message 4 of 7
(4,745 Views)
What you have there should work.  Any chance you need to raise the DTR or other hardware handshaking line for the instrument to accept the command?
0 Kudos
Message 5 of 7
(4,738 Views)
I don't see anything wrong with the LabWindows code you've posted.  Confirm that the return value from ComWrt (bytes) is 14.  Also, I would suggest passing -1 as the output queue size in OpenComConfig.  It causes the writes to occur synchronously, so that you know that your message has been sent to the port when the function returns.  I recommend downloading and installing the Portmon utility by Sysinternals.  It is a good, free tool that will show you exactly what bytes are being sent by the port.  This will let you see what the difference is between what is sent by Matlab and what is sent by CVI.  Also, I just want to confirm that your instrument is connected to port 1 (COM1) of your machine.  If not, that would definitely explain the problem. 😉

Let me know what you find.

Mert A.
National Instruments
Message 6 of 7
(4,737 Views)
Ok Great it works now.... -1 seemed to do the trick on the ComInit buffer size? Go figure it.

Thanks for all the help.



0 Kudos
Message 7 of 7
(4,719 Views)