LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

read data from COM1

hello,
i want write and read data from COM1, But it is not working well:
 OpenCom(2,"COM1");
    Fmt(buf,"%s","Hello,World!");
ComWrt (2, buf, 100);
n = ComRd (2, buff, 100);
        printf("%s",buff);
  CloseCom (2);
thanks
 
0 Kudos
Message 1 of 11
(4,679 Views)
Do you really think that your system maps the second port to COM1 and not to COM2?
0 Kudos
Message 2 of 11
(4,678 Views)
thanks for answer,
i dont know but i tried first port(OpenCom(1,"COM1").
how i can know how port which maps to COM1
0 Kudos
Message 3 of 11
(4,674 Views)
What are you trying to write to/from?  Do you know its configuration (paity, etc.)?
You may need to be using opencomconfig so that you can set those items.
0 Kudos
Message 4 of 11
(4,670 Views)
yes i have configured the port 
OpenComConfig (2, "COM1", 9600, 0, 8, 1, 512, 512);
0 Kudos
Message 5 of 11
(4,668 Views)
You don't, necessarily.
 
Try specifying the port number and pass a null string as the device name and let Windows map it.
 
If you think you're using COM1 (port 1 on a windows system)  try OpenCom (1, ""); 
0 Kudos
Message 6 of 11
(4,666 Views)
i tried empty string but i couldn't read.
ComWrtByte (1, 179);
send value equal 1,its mean that writing is succsuful bur reading not
 
0 Kudos
Message 7 of 11
(4,663 Views)
anyone can help me
0 Kudos
Message 8 of 11
(4,649 Views)

Well, a write always succeeds if you've got a com port present.

So, you could have any one or a combination of these problems:

1.  Wrong port number.

2.  Cabling error. 

3.  Comport configuration error.

4.  Device error.

 

You might try using Hyperterminal or Terminal to help you make sure you've got things correctly configured, it's often easier than trying to work it through using CVI.

0 Kudos
Message 9 of 11
(4,648 Views)
Just a couple points:

I wanted to clarify the semantics of the first two paremeters of OpenCom/Config. The first parameter should be thought of as an arbitrary identifier/handle for the port that you open. It is the second parameter that specifies the actual port to open. That is, you could call OpenCom(22, "COM1") and you'd just be opening the system's first com port, COM1, and associating it with the number/handle 22. The function panel for this function somewhat confuses this fact by putting COM1, COM2, ... in the ring for that parameter.  However, if the second parameter is an empty string, then the function defaults to opening the same numbered port as the handle: OpenCom(1, "") opens COM1, OpenCom(5, "") opens COM5, etc.  So calling OpenCom(2, "COM1") is completely legitimate and should open COM1.

As for your problems reading values, I suspect that it may be a problem of the data not actually being transferred by the time you try to read.  After you write the bytes, add a call to ProcessSystemEvents() and see if that doesn't solve your problem. I would actually suggest that you pass -1 as your output queue length (i.e. OpenComConfig(1, "", 9600, 0, 8, 1, 512, -1)) to disable CVI's intermediary output queue. Doing so will cause bytes to be transferred immediately upon calling ComWrt (or the other write functions) instead of waiting until events are processed.

If you still have problems reading your data, make sure that both ends of the communication are configured with the same parameters (baud, parity, stop bits, etc) and are using the same handshaking scheme (if any).

Hope this helps.

Mert A.
National Instruments


Message Edited by Mert A. on 11-05-2007 03:42 PM
0 Kudos
Message 10 of 11
(4,641 Views)