Serial ports
restedumonde
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.
That means you have to invoke VDTOperationsPort2 to switch to a different port.
November 6, 2009 at 07:12 am - Permalink
VDT2 can control any number of ports. As Andreas said, use VDTOperationsPort2 to set which port VDT2 commands target.
November 6, 2009 at 03:39 pm - Permalink
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
November 7, 2009 at 07:37 am - Permalink
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:
// 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.
November 8, 2009 at 02:07 pm - Permalink
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:
November 8, 2009 at 10:22 pm - Permalink
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
September 8, 2010 at 12:38 pm - Permalink
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 . . .
September 9, 2010 at 10:13 pm - Permalink
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
August 15, 2012 at 03:54 pm - Permalink
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.
August 15, 2012 at 07:36 pm - Permalink