01-12-2009 09:17 AM
Hello,
I am trying to install a VISA IO event handler in my code that will read data from the TCPIP socket. The data is being pulsed in from the attached device. I have done the following successfully:
Opened the default resource manager,
Opened the ethernet device,
Set the attribute for TCPIP NODELAY
Set the timeout for 5000
Installed my handler
Enabled the IO event
I am now expecting this event to kick off every time the data pulses in from the device. Am I correct in this assumption?
Within my event handler, I perform a viRead for the max number of bytes I expect to get. From what I can see the event handler is not executing. I've been looking for sample code for this and I can't find anything explicit. I have read about the viAsyncRead, but I don't want to do a read until the data has come in from the device... or am I wrong here, too. This is my first real shot at using VISA with ethernet - typically, I have done serial port RS232 work with an async timer and the Windows input queue.
Any and all advice/help is appreciated.
Thanks,
Judy
Solved! Go to Solution.
01-13-2009 07:03 PM
Hello Judy,
You might consider initially treating interaction with your device as a generic TCP/IP Connection. This will allow you to specify a callback function at the time you connect, which will then fire in response to a number of events. One of these events is called TCP_DATAREADY, which sounds especially apropos for your situation. The particular event detected is specified in the xType parameter for the callback function. Within the body of the callback function you could then execute the various VISA functionality that you desire. One example that exhibits this approach on a server side is called finger.cws. You should be able to find this example by searching the CVI example finder for TCP.
01-14-2009 09:53 AM
>>>You might consider initially treating interaction with your device as a generic TCP/IP Connection. This will allow you to specify a callback function at the time you connect, which will then fire in response to a number of events. One of these events is called TCP_DATAREADY, which sounds especially apropos for your situation. The particular event detected is specified in the xType parameter for the callback function. Within the body of the callback function you could then execute the various VISA functionality that you desire. One example that exhibits this approach on a server side is called finger.cws. You should be able to find this example by searching the CVI example finder for TCP<<<
Hi Matt,
Thanks for the response. I appreciate the information, but isn't VISA supposed to handle the whole communications issue? That's the reason I'm using it. I think I just need information on how to use it properly. Am I not setting attributes for the event somehow? Should I be using viAsyncRead somewhere?
Thanks,
Judy
01-14-2009 10:21 AM
Hello Judy,
VISA will indeed handle the communication of the data from the device to your application: Calls to the VISA library should be placed inside the callback function that we have discussed in order to actually retrieve data, not just detect its presence.
01-16-2009 01:30 PM
Hi Matt,
I'm sorry, but I don't think this issue is resolved. I am trying to handle data pulsing in from a device. This device has a number of connection interfaces (RS232, USB, and Ethernet) which is why we selected VISA for the communications basis. I believed that there was an event available that would trigger a callback when data came from the device - there is one in CVI that will do this for RS232 communications. I would then read in the data from the input buffer and parse it in the event handler function that I installed upon connection.
I thought that the VI_EVENT_IO_COMPLETION event would suit my purposes. I expected that it would trigger on the receipt of a pulse of data, and the handler I installed would then execute. It appears from reading the documentation (VisaEvents.pdf) that I downloaded, however, that this event only gets sent when a response to viReadAsync is returned from the device. This makes the mechanism less of an event handling mechanism and more of a polling mechanism. Is it true that I must poll the device with viReadAsync, and the VI_EVENT_IO_COMPLETION kicks off when the response is received, THEN I can parse my data?
Thanks,
Judy
01-16-2009 02:47 PM
Hello Judy,
No reason to be sorry. You are correct in determining that the VI_EVENT_IO_COMPLETION is a software driven event rather than one originating in hardware. You have mentioned that you want to use VISA to communicate with your device several times, and I will reiterate that you can use VISA to facilitate the communication of data. The real question you have is whether you use VISA to detect a hardware event and I have not found any resources to indicate that you can. This might be a great question for the VISA discussion forum. However, as an alternative solution, I brought up first using TCP/IP to detect the presence of data and subsequently using VISA to facilitate the data transfer.
04-01-2009 10:54 AM
Hi Matt,
I want to try your suggestion but I cannot seem to find the finger.cws example you describe. Is it on the web site or part of the cvi install?
Thanks,
Judy
04-01-2009 11:01 AM
Judy,
This example installs with LabWindows/CVI. Use the NI Example Finder to search for TCP. That is, select Help >> Find Examples..., followed by the search tab, and type in TCP. The results should contain finger.cws along with a few other TCP/IP examples.