Serial ports

Hey,
I am currently setting up an experiment in my lab.
I need to control three instruments via serial port (RS232) AT THE SAME TIME with Igor Pro, without reinitializing the ports.
I have already used the commands VDT and VDT2 to control two of them.
What can I do to control the third one?
Thanks.
You have to use VDTOperationsPort2 to designate a particular serial port as the receiver for commands being send from Igor. There is no need to use VDT, because afaIk the only difference is that VDT2 can be used in user procedures.
That means you have to invoke VDTOperationsPort2 to switch to a different port.
I recommend that you use VDT2. VDT is obsolescent. The main difference is that you can call VDT2 commands from user-defined functions. The VDT2 Help file explains other differences at the end of the file.

VDT2 can control any number of ports. As Andreas said, use VDTOperationsPort2 to set which port VDT2 commands target.
Thanks for your help guys.
Would a procedure with the following structure work without any conflict between the ports?

Proc toto()

// Communication with COM1:
VDT2 /P=COM1 baud=57600,databits=8,parity=0,stopbits=2,in=1,out=1
VDTOpenPort2 COM1
VDTOperationsPort2 COM1
VDTWrite2 "something"
VDTRead2 "something"
// Communication with COM2:
VDT2 /P=COM2 baud=57600,databits=8,parity=0,stopbits=2,in=1,out=1
VDTOpenPort2 COM2
VDTOperationsPort2 COM2
VDTWrite2 "something"
VDTRead2 "something"
// Communication with COM3:
VDT2 /P=COM3baud=57600,databits=8,parity=0,stopbits=2,in=1,out=1
VDTOpenPort2 COM3
VDTOperationsPort2 COM3
VDTWrite2 "something"
VDTRead2 "something"
// Return to communication with COM1:
VDT2 /P=COM1 baud=57600,databits=8,parity=0,stopbits=2,in=1,out=1
VDTOpenPort2 COM1
VDTOperationsPort2 COM1
VDTWrite2 "something"
VDTRead2 "something"
Etc…

End
First of all, I recommend to use functions instead of macros. I cannot think of any advantages that macros have and functions don't. That means replace 'proc' by 'function'.

I think, that VDT2 remembers the settings that you apply to an individual port. You need to setup the port only once.
The second thing is, that calling VDTOpenPort2 isn't necessary. See the help for VDTOpenPort2 in this context.

So your function could look like the following:
function toto()

// port settings:
VDT2 /P=COM1 baud=57600,databits=8,parity=0,stopbits=2,in=1,out=1
VDT2 /P=COM2 baud=57600,databits=8,parity=0,stopbits=2,in=1,out=1
VDT2 /P=COM3 baud=57600,databits=8,parity=0,stopbits=2,in=1,out=1

// Communication with COM1:
VDTOperationsPort2 COM1
VDTWrite2 "something"
VDTRead2 "something"

// Communication with COM2:
VDTOperationsPort2 COM2
VDTWrite2 "something"
VDTRead2 "something"

// etc...
end


Howard, please correct me, if I mistook something.
Both approaches are fine. Stylistically, I would create a separate InitCOMPorts function which would call VDTOpenPort2 and VDT2 to set the communications parameters for each port. It is true that you don't need to call VDTOpenPort2 but for clarity, I prefer to make it explicit.

As Andreas says, use Function rather than Proc or Macro. This gives you compile-time checking of code and many other programming features. For details:
  DisplayHelpTopic "Programming Overview"



Apropos of running 2 or more serial devices at once without having to reselect the ports

It was interesting to see that VDT and VDT2 can be used for this purpose. I have always wondered if the single operations port was a limitation at the Igor level or at the OS level.

Does that mean it would be possible to rewrite the VDT2 XOP to provide for multiple operations ports so that one could have multiple devices, each with its own operations port?

Currently, I do things like having a global "operations port in use by" string, which needs to be checked before each use of VDT2 functions by a device-specific function in case one of another device's functions is using it, and then, if operations port is not in use, calling VDTOperationsPort2 in case the other device was the last to use it.

Dr. Jamie Boyd, Ph.D.
UBC In Vivo Imaging Core
jamie wrote:
Does that mean it would be possible to rewrite the VDT2 XOP to provide for multiple operations ports so that one could have multiple devices, each with its own operations port?


Yes, it could, and should. All of the operations should have a /P=portName flag. Now it's just a matter of finding the time . . .

hrodstein wrote:
jamie wrote:
Does that mean it would be possible to rewrite the VDT2 XOP to provide for multiple operations ports so that one could have multiple devices, each with its own operations port?


Yes, it could, and should. All of the operations should have a /P=portName flag. Now it's just a matter of finding the time . . .

Dr. Jamie Boyd, Ph.D.
UBC

Just checking... Has time been found for this? I am now wanting to drive two serial port devices at once and it would simplify code to have the /P=portname flag
Quote:
Just checking... Has time been found for this?


No, this kind of thing will have to wait for after IP7 ships at least in beta. I estimate that will be about a year.

The source code for VDT2 is included in the XOP Toolkit so a C programmer could create his own version of it.