LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Serial reading and writing

Hello! I'm fairly new to the labview experince and whilst I think i've got the basics under wraps and gone through examples, i'm still a bit confused with a project i'm working on. I'm working on a basic train simulation where Labview interfaces with a PIC controller. The PIC tells labview when the train has arrived at the station by sending a 'A' (for arrived) to labview, once Labview has read this 'A' I then want to be able to send it a 'M' to move. The PIC itself times and sends the character but as this is a simulation I want it to flow from case to case unless told otherwise. This is the basics of what I want to do, but I have a few questions.

 

so think I have VISA W writing 'M' to the serial (not tested, but going on examples it looks right) which is great, but is there an option to be able keep the constant string 'M' unless I state it to 'J' (jump a case) or 'R' (reverse the journey)? With 'R' for reverse, can I get labview to reverse through the cases? 

 

Also, i'm having problems getting the string constant 'A' (for arrived) to be read into VISA R.

 

and one last question for now, because I want to turn a LED on each case on the simulation only (the PIC handles the actual LEDs) can I just put a true statement next to the one I want on? and will this then turn off once it goes to the next case? 

 

Many thanks!

0 Kudos
Message 1 of 4
(1,174 Views)

Does communication in a terminal program work with the PIC controller?  Serial communication can be tricky, and it is always best to get the basics worked out in your terminal program.

 

"so think I have VISA W writing 'M' to the serial (not tested, but going on examples it looks right) which is great, but is there an option to be able keep the constant string 'M' unless I state it to 'J' (jump a case) or 'R' (reverse the journey)? With 'R' for reverse, can I get labview to reverse through the cases?"

 

Yeah, sureYou can get labview to do whatever you want it to do for the most part.  You'll need to define a case a little better than you have in your paragraph.  Sounds like you want each command that has been sent to go onto a data structure (like a stack) and then pop elements off of the stack (or something like that).

 

Your question is very general at this point.  If you are looking for confirmation that LabVIEW is capable of communicating with a PIC control through a serial link, and is capable of sending and receiving strings, then yes it has that capability.  I would need to see some of your code where you can show the specific problems you are having to really provide much more assistance.

0 Kudos
Message 2 of 4
(1,168 Views)

Hello.

 

I've attatched my VI. Basically this is what i'm trying to get:

 

case 0: user sends 'S' (for start) to PIC by pressing button on Labview

case 1: PIC simulates journey, sends 'A' to Labview to read when train has arrived. Labview responds with B. First train station LED is true

case 2: PIC simulates journey, sends 'A' to Labview to read when train has arrived. Labview responds with B. first direction arrow is true, station LED is turned off.

 

this is repeated until 

case 10: PIC simulates journey, sends 'A' to Labview to read when train has arrived. Labview responds with B. User can enter 'R' for Reverse, so the whole simulation revereses to case 0. 

 

on top of that, I want to be able to enter a command 'J' to miss a station.

 

Any help would be greatly appreciated!

0 Kudos
Message 3 of 4
(1,151 Views)

Hi getox,

 

I would also mirror Nickerbockers idea of making sure that the PIC can talk OK with the COM port on the PC. For this application you may want to consider looking into a state machine architecture. I have placed some of your code into a simple state machine example. I have placed the configure serial port outside the loop, as this only needs to run once. Also the VISA close and error check is also outside the loop, as the resource only needs to be closed at the end of the program.

 

Introduction to State Machines: http://zone.ni.com/devzone/cda/tut/p/id/3024

 

Regards,

Ben B.

Applications Engineer
National Instruments UK & Ireland

"I've looked into the reset button, the science is impossible!"
Download All
0 Kudos
Message 4 of 4
(1,127 Views)