LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial comm issues

Solved!
Go to solution
Highlighted

I am trying to Send DI and AI states / Receive DO and AO states through a microcontroller Serial port ... the microcontroller sends data at 100ms intervals. 

 

When I run this code the AI and DI states do not update based on user inputs. It only updates once during start of run.  

 

What is wrong ? 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 13
(382 Views)
Highlighted

Here are some suggestions (partly based on missing specifications on your part or lack of understanding by me):

  • If you are simulating an FPGA, don't have an Event Loop.  Replace with a Frame Sequence whose first frame sets all of the variables to their Default value, and the second Frame has the rest of the code.
  • I'm pretty new to FPGA coding, and unfamiliar with incorporating VISA into FPGA (can you do that?).
  • Whether or not VISA belongs inside an FPGA or not, the VISA code "looks wrong".  A lot has been written in the Forums about not using Bytes at Port, but rather setting the VISA port up in its Default Mode (as you have done!) to use a Termination Character, and use the sequence "Write VISA Command, Read Many More Bytes than you expect (i.e. 1000) because you'll stop when you get the Termination Character, and then Process the Entire Response All at Once".  Instead, you give a Command, if there are any Bytes at Port, you read (only) the first 50, accumulating them in a Buffer, then pass that ever-lenghening Buffer out for processing before going back and repeating the process.  I'm not sure if this is as wrong as it seems, but I can't make sense of it.
  • Without a better understanding of the VISA device and its command and response structure, it's difficult to make better suggestions.

Bob Schor

0 Kudos
Message 2 of 13
(356 Views)
Highlighted
Solution
Accepted by MogaRaghu

I'm not sure where Bob is getting FPGA from.  I don't see anything in the post or VI that screams "FPGA".  But here are a few tips:

1. Go watch this: VIWeek 2020/Proper way to communicate over serial

2. Get rid of the Feedback Node.  That is what is keeping your outputs constant.

3. Turn your AI values into an array, do the scaling, and use Array To Spreadsheet String to form your comma delimited string.

4. Use Scan From String to parse the read data.  You can get all of your values in a single node.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 3 of 13
(330 Views)
Highlighted

@crossrulz wrote:

I'm not sure where Bob is getting FPGA from.  I don't see anything in the post or VI that screams "FPGA".


Hs!  Was fooled by the Frame Sequences.  I have only recently been introduced to FPGA code, where Sequences Rule, so that plus the reference to "Hardware Simulation" led me astray ...  I apologize for my carelessness.

 

Bob Schor

 

 

Message 4 of 13
(321 Views)
Highlighted

@crossrulz

 

Looks I have got the right answers ! 

 

Understood. So the "Bytes at port" is to LabVIEW as "Goto" is for C language. Will stay away from it.  Maybe in your linked video you explain that later why is it so ? Anyway I could see the video is almost an hour as you were responding to questions in-line.  Will see that later. 

 

In the meanwhile tried to open the Github examples but they are LV2019. I am a dinosaur stuck with LV2017..  can you please post a suitable compilation ? 

 

Thanks !!

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 5 of 13
(290 Views)
Highlighted

@MogaRaghu wrote:

In the meanwhile tried to open the Github examples but they are LV2019. I am a dinosaur stuck with LV2017..  can you please post a suitable compilation ? 

You're lucky I still have a 2016 version zipped up.  I think I used maps in one of the examples, which were new to 2019.  But here you go anyways.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 6 of 13
(255 Views)
Highlighted

@crossrulz

 

Thanks . So kind of you. 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 7 of 13
(233 Views)
Highlighted

@MogaRaghu wrote:

Understood. So the "Bytes at port" is to LabVIEW as "Goto" is for C language. Will stay away from it.  Maybe in your linked video you explain that later why is it so ? Anyway I could see the video is almost an hour as you were responding to questions in-line.  Will see that later. 


Hah! That's a very good way of putting it! Yes, Bytes at port, sequence structures and Local variables are like 'goto', they're Tools that's good in the right _rare_ circumstance.

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 13
(215 Views)
Highlighted

@Yamaeda

 

Thanks. 

 

While we agree that Bytes at Port is bad, can I know why is it bad ?  Does it end up locking up the CPU resource ( which I don't think is the case as the code is responsive normally ) or what is the harm that it actually do ? 

 

 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 9 of 13
(208 Views)
Highlighted

Hi Moga,

 


@MogaRaghu wrote:

@Yamaeda

While we agree that Bytes at Port is bad, can I know why is it bad ?


You don't need it in most cases!

  1. When your messages end with a TermChar then use that TermChar to read full messages.
  2. When your messages use a known number of bytes (or any length indication) then use this information to read the correct number of bytes (aka full messages).
  3. When you messages don't use a TermChar and don't indicate the message length in a different way then the message format is ill-formed: change the device (or its software) to use a proper message format!

 

You can use BytesAtPort to check for any messages at all, when the device sends them only very seldomly: this way you don't need to handle TimeOut errors of VISARead, but can check for ">0" bytes received…

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 10 of 13
(204 Views)