LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Communication with Serial Port

Hi all,
Ive seen that there has been heaps of discussion on this topic, but I cannot resolve my problems. I am using Labview 6i and cant work out my problems. I have used Hyper Terminal and I can do what is required, which is, to connect to a peripheral device, at the password prompt enter the password (PASSWORD), then at the command prompt enter GETDATA, at which point the peripheral dumps all the data to the screen. I need to get it working in Labview so i can automate the whole process for multiple peripherals.
I can get the initial data (up to the password prompt), but I cant send the password through (so i dont even get the prompt to enter GETDATA)
Can anyone help me? Im pretty sure the initialisation is correct so im not s
ure where to go
Thanks
Ridge
0 Kudos
Message 1 of 16
(4,921 Views)
1. You need to control when things happen. This is called dataflow. The
stuff in the loop has dataflow because the wires connecting one operation to
the next force the second operation to occur second. The serial port read
cannot go until it receives the byte count from the bytes at port function.
You need to add dataflow for the password entry and everything else. I am
fairly certain this is your problem. Since these functions don't need
anything from the earlier function, what you can do is put a single frame
sequence around each of them and wire any output from earlier function just
onto the sequence frame.
2. I'm not sure what you are doing with a for loop with a single iteration
or a case statement with a single case. I suspect that you left out some
parts for brevity or because they haven't been implemented yet. But if you
have a for loop because you plan to query several ports then I think you
need the password and getdata inside the loop.
3. I recommend you get to amazon.com and purchase a labview textbook. It
seems like you could use some instruction in basic programming practice that
you won't really get enough of here.
Adam

"Ridge" wrote in message
news:5065000000080000003A650000-1031838699000@exchange.ni.com...
> Hi all,
> Ive seen that there has been heaps of discussion on this topic, but I
> cannot resolve my problems. I am using Labview 6i and cant work out my
> problems. I have used Hyper Terminal and I can do what is required,
> which is, to connect to a peripheral device, at the password prompt
> enter the password (PASSWORD), then at the command prompt enter
> GETDATA, at which point the peripheral dumps all the data to the
> screen. I need to get it working in Labview so i can automate the
> whole process for multiple peripherals.
> I can get the initial data (up to the password prompt), but I cant
> send the password through (so i dont even get the prompt to enter
> GETDATA)
> Can anyone help me? Im pretty sure the initialisation is correct so im
> not sure where to go
> Thanks
> Ridge
Message 2 of 16
(4,921 Views)
Adam is right on the money about dataflow. One of the big drawbacks about the old serial VIs is that they don't have error in/error out connections. Having them makes it much simpler to enforce dataflow without resorting to silly sequence structures. Just because the serial port init VI is to the left of the for loop doesn't make it execute first. In fact, LabVIEW will atempt to execute the serial port init, the for loop, and the two serial port writes in parallel. Unless there's some reason you don't want to, I'd look at using VISA for the task. With error connections and both a VISA reference and VISA reference out, datflow is easy. Look at the shipping example called LabVIEW <-> Serial.vi. You'll also need to make the program a little more robust
by doing a serial read after writing the password command to be sure the command prompt has arrived.
0 Kudos
Message 3 of 16
(4,922 Views)
All of the comments about data flow are dead-on. Also I strongly recommend using VISA over the old serial vi's. I've attached a vi that performs the tasks you identified, but there are a couple of details you may still need to add. For example, character read termination is turned on by default, read time out is left at 10 seconds, and you may need to add a CR/LF after the commands. Hopefully this will be good enough to get you started!
0 Kudos
Message 4 of 16
(4,922 Views)
Hi Chris,
I cant access the vi as im using 6i, could you please save it for version 6. I have been trying again using the old serial vi's and my initialisation is not working for com 1. When I try to initialise, it goes through it, but then it doesnt recognise reading the data at the port. When I dont initialise the port and run the program, it gets the initial data and in the string display it shows the prompt for the password. When I try to send the password to it (it is as a constant and written to the serial), i dont know whether it sends or not, but when i read the data at the port after writing to it, it displays the password i have written to it, and the same happens when i send the command, wait, and then read.
I believe my initialisation may be inc
orrect, but the specs say Data bits: 8, Baud rate: 9600, Stop bits: 1, flow control: none, parity: none. It also specifies an emulation property of VT100 and ascii sending is Local Echo. I am at a loss
Have you got any ideas? I dont understand the VISA method, so ive used sequence structures for data flow
Thanks
Ridge
0 Kudos
Message 5 of 16
(4,922 Views)
I tried to save as a previous version but could not. So instead I took a screen shot of the diagram. VISA is a single instrument interface API that allows you to write applications/drivers for instruments regardless of their connectivity (serial, GPIB, etc.). The VISA vi's are located in the Instrument I/O function palette.
0 Kudos
Message 6 of 16
(4,922 Views)
Hi Chris,
Thanks for that.
I am unsure how to use it as I dont know what the resource name is and how many bytes to read. I played around with it, but havent been able to read anything. Not sure whats going on. Am getting extremely frustrated!!
Ridge
0 Kudos
Message 7 of 16
(4,924 Views)
Hi Dennis,
I sort of followed Adams idea of sequencing the flow as I dont understand the VISA principles (ie the resource name and the number of bytes to read). I dont think that my initialisation is correct as when it is referenced to the required port (com 1), it doesnt return an error, but the rest of the vi doesnt do anything. When the initialisation isnt there (or to com 2 - which brings up error 37 as there is nothing connected to it), it reads from the port and prompts for the password. I then try to write the password (which is 'password') to it and i then read the port again and i get the password i have written to it. I then send the command 'getdata'to get the data and then read the port and 'getdata' is returned.
Flow control is r
equired to be none, and emulation is VT100 and ascii sending is Local Echo.
I tried using Chris's vi but i dont know the requirements mentioned above.
I have included a delay inbetween structures to try and give enough time for response of the peripheral.
I believe the data flow should work, but maybe the flow control settings are incorrect and port not being initialised. Can you think of why the port would not be initialising or why the system is not working?
Thanks
Ridge

I am using LV 6.0, with OS W2000
0 Kudos
Message 8 of 16
(4,924 Views)
Your initialization VI has 1 as the port but the serial writes have 0. If you look at the help for the serial VIs, you'll see that port 0 is com 1 and port 1 is com 2. Also, looking at the other postings on this thread, for the VISA resource name, just create a control or constant and click on the arrow. You should see a list of available VISA resources (i.e. COM1, COM2, LPT1. Select the one you want and off you go. You can also type the name of the resource you want. Measurement & Automation Explorer (MAX) lists all VISA resources and their aliases. If you go to the help menu and select "Search the LabVIEW Bookshelf", you'll find a manual called "LabVIEW Measurements Manual". This is a good basic introduction to VISA.
0 Kudos
Message 9 of 16
(4,924 Views)
The resource name will be the name of the COM port you are using. It is a drop down menu and you should be able to see all of the installed VISA resources (including COM ports) on your system. You can set the bytes to read to a large (meaning larger than the expected data) if you want to use read timeout or termination character.
0 Kudos
Message 10 of 16
(4,515 Views)