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