Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble scanning/detecting serial devices at different baud rates

Hi,

 

I have a system with a number of serial ports.  I want to be able to scan each port at different baud rates to detect what devices (if any) are at each port.

 

It would be easier for me to just post my code, but unfortunatly I can't easily move the code to this computer, so here is a description of what I have been working on: 

 

I'm using "VISA Find Resource" to auto-index a for loop, then I use "VISA Open" on each resource along with the "Property: Interface Information: Interface Description" to determine if the resource is a COM port.  Then I use "VISA Close" to close each resource.

 

If the resource is a COM port I auto-index another for loop with a 6 different baud rates using the resource name and "VISA Open" to re-open the port, set the baud rate using "VISA Configure Serial Port"

I then send a "*IDN?" with an end of line constant using "VISA Write", wait 100ms, then check for "Bytes at Port", if there are bytes I read them.

Finally I use "VISA Flush I/O Buffer" and then "VISA Close"

Then the loop repeats with the next baud rate but the same resource.

 

After all this is finished, It doesn't detect any devices...there are never any bytes at the port to read.  Right now I am testing with 2 devices, both of which I can detect using another VI to open each one at thier specified baud rates, but it doesn't work when I loop through different baud rates.

 

If I start the loop using the baud rate that I know will work for one of the devices, then the device returns bytes, but if I start looping with a wrong baud rate, I don't get anything in return.

 

Am I missing something here? Do I need to do something else to ensure that the port is closed and not in use? I tried adding delays in between Open and Close, and before/after parts of the serial commands to see if maybe i was just trying to process it too fast, but nothing seems to work.

 

Any ideas? 

 

Thanks, 

~Jonathan 

-----
LV 8.2/8.5/8.6 - WinXP
0 Kudos
Message 1 of 8
(6,054 Views)

Have you checked to see whether the instruments are in an error state? There are instruments that when they receive an incorrect command, will not respond expect to an error query that will also clear the error.

 

Is all of this really necessary though? Why would the instrument's settings change?

0 Kudos
Message 2 of 8
(6,038 Views)

Dennis Knutson wrote:

Have you checked to see whether the instruments are in an error state? There are instruments that when they receive an incorrect command, will not respond expect to an error query that will also clear the error.

 

Is all of this really necessary though? Why would the instrument's settings change?


 
Hi Dennis, 
As far as I know they aren't in an error state. I can run the same code (outside of a loop with only 1 baud rate) to send the message and it works.  Unless there is an error timeout in the instrument before it will accept a new message...thought I put it some 3-4 seconds delays... Actually one of them gets in an error state, the command prompt changes, thought it doesn't inhibit new commands.
The reason I'm doing this is to have the software "Auto-configure" all the attached devices.  This way if a new device is added, or if the devices are physically moved to a different COM port, then the software will automatically recognise the move and reconfigure itself.  Right now the user needs to setup each of the devices, and I'd like to make it as easy as possible for the user.
The reason for different baud rates, is that some of our devices run 9600 and others at 19200.  Also, the user might not setup the baud rate or even know how to set it up in an instrument, so if a replacement is used, it might be at a different setting.
Thanks,
Jonathan 

 

-----
LV 8.2/8.5/8.6 - WinXP
0 Kudos
Message 3 of 8
(6,032 Views)
Well, I have no other ideas other maybe one of the VISA functions is generating an error that you aren't trapping. I would hope that in your loop that you are using the error clusters wired to shift register and an error indicator.
0 Kudos
Message 4 of 8
(6,011 Views)

Dennis Knutson wrote:
Well, I have no other ideas other maybe one of the VISA functions is generating an error that you aren't trapping. I would hope that in your loop that you are using the error clusters wired to shift register and an error indicator.
I have the error clusters wired together with an auto indexed error array outside of the loop and an indicator on the front panel, but i didn't use shift registers, I'll check again to see maybe I'm overlooking an error.  I'll try and get my code posted tomorrow, that might be of more help.

 

-----
LV 8.2/8.5/8.6 - WinXP
0 Kudos
Message 5 of 8
(6,007 Views)

Ok, so here is what I have now....the VI indexes a baud rate array, then tries that baud rate at each COM port.  Though now I'm running in to some resources in use issues, still trying to figure that out...but I still can't seem to get any data from any of the ports....I have two devices attached to a PXI8432/4 which both work when i query them in hyperterminal.  And I also receive bytes when i start the array at the baud rate the device is set at, but if its not the first one to connect, then i get nothing.....

 

I'm starting to think that maybe this won't work because of the way the devices work...Its possible that the devices are getting in an error state as Dennis said and maybe there is a timeout/watchdog in the device that resets it after sometime....I'll check the manual again...

 

Attached are the two parts of my VI

The first part finds the COM ports:

scan ports 1

The second part opens/writes/reads/closes the COM ports at different rates:

 scan ports 2

 

~Jonathan
Message Edited by malkier on 02-23-2009 03:40 PM
-----
LV 8.2/8.5/8.6 - WinXP
Download All
0 Kudos
Message 6 of 8
(5,986 Views)

malkier,

 

The device entering an error state is a deffinit possibility, let us know what you find in the manuals.  Also, do you have any more details on the resources in use issues?

 

Eric K

Applications Engineering

National Instruments

0 Kudos
Message 7 of 8
(5,969 Views)

Hi Eric,

    Thanks for the response, I can run the loop once and detect two of the three devices I have hooked up, but then when I try to run it again, something goes haywire and either 1 or none of the devices are recognised.  I'm pretty sure this is something the devices are getting confused with when I try to send in the commands at an incorrect baud rate.  I tried adding some endline characters to clear out any characters that were in the device buffer (the instrument doesn't process the characters unless an endline is sent).  Also tried using the flush I/O buffer, but that didn't seem to help either.

 

The devices I'm trying to use are the Stanford Research Systems SR620 Time Interval Counter and an HP5071A Cesium Frequency Standard (now Symmetricom)... I can usually query the SR620's, but the 5071 doesn't seem to work at all when scanning.  All devices work just fine through hyperterminal.

 

The "resources in use issue" seemed to disappear, not sure why that was happening, I might have had hyperterminal running at the time...no more issues encountered with that. 

 

I already have a user interface to configure these devices, this was just an added extra to see if it would work.  Right now I don't have the time to keep working on this, but I may come back to it in the future.

 

Thanks for the help,

Jonathan

-----
LV 8.2/8.5/8.6 - WinXP
0 Kudos
Message 8 of 8
(5,865 Views)