06-28-2012 02:03 PM
Gurus,
I'm writing a driver for a new instrument I designed. It has an RS232 port and an internal RS232<>Wifi module from Roving Networks. I wrote the RS232 vi's using VISA. Now I'm trying to figure the best way to handle both types of comms within one vi. So far I added my TCP address into MAX, it shows up in the list of VISA's.
I put in a boolean switch on the panel (select TCPIP or RS232) and a CASE in the code to switch between initializing RS232/TCPIP. Looks sloppy though... It keeps crashing on a VISA READ ("lost comms"?) even though the init works fines with no errors, but I'll try to debug that..
I'm a HW guy creating drivers, don't know all the "fun" stuff you guys do
1 - What is the best practive way to implement a dual-comms driver?
2 - Does any PC I install this driver on have to have MAX on it (to configure the TCPIP socket?
3 - Can anyone share an init / write & get data vi's please who has done this? My device only has 4 values to read/write, so very simple.
Thanks!!!!
Streve
06-28-2012 02:29 PM
You can format the VISA resource name directly allowing you to communicate using VISA using either the RS-232 or TCP connection. The piece of your code that will need to care about this is the initialization. Everything down stream will simply use VISA read or write. If you don't know the exact size of the returned data or you don't have a delimiter for your messages a method to read unknown sizes of data is to read a single byte. This read will use a longer timeout. Once a single character is read read chunks of data (some reasonable size) but use a much shorter timeout. The logic here is that there will be a break between messages. The shorter timeout should be less than the expected interval between messages.
Since you will be using both serial and TCP communications don't use the Bytes At Port method in VISA. This only applies to the serial connection and therefore your general read/write VIs will have to have logic to differentient behavior based on the connection type. You should avoid doing this and limit that to the initialization only.
I have implemented several variotions of a generic communication interface library. The most recent is LVOOP. I am not at liberty to post these however. But it is very doable.
06-29-2012 09:47 AM
Thanks for the feedback. Indeed the bytes at port is biting me atm, can't figure out how to access the buffer to get a size. I can set the TCPIP0::... in VISA name, open it OK though.