LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial port stops reading buffer after restart

Hello, I am trying to use a basic serial command to read data from the serail port, I got everything perfectly (so I thought). Until I resarted the computer and it stopped working? I have no clue what happend or why it's doing it. It's happend in the past and I had to fiddle around with changing my code until it surpsingly starts working again. All comands work perfectly throught HyperTerminal.

 

The command I'm using is : 'PRINT\sPOS\r\n' the output would orignally provide me with the angual value of the stepper motor. After I restarted, I no longer get a value returned. What am I doing wron

 

I'm a relative newb to LV so any help would be much apprecaited, my screenshots are attached...

 

Thx!

 

-Israr

Download All
0 Kudos
Message 1 of 6
(3,169 Views)

You're not setting any serial port parameters in the program as far as I can see (note:  it is easier to review a VI file attached to your message rather than a couple of screenshots), thus the serial port settings are determined either by MAX or by Windows device manager settings.  Are you sure those are correct?

 

What do you mean by it doesn't work?  Are you getting any error messages?  Exactly what are you changing in your code that allows it to start working again?

0 Kudos
Message 2 of 6
(3,162 Views)

When I say it's not working, I mean in the stepper motor rotates as it receives this command in the previous case structure, but on my front panel, where i'm reading the value, there's only a zero. Before I restarted, that value would constantly change as the motor went through it's range of motion and it was stuck in the while loop until it reached the end condition where the 'PRINT\sPOS\r\n' value would = the angular value set through the knob on the front panel.

 

On the basic serial port read and write I did notice all the parametes being set. However, checking through MAX I noticed everything was the same as my HyperTerminal which works, so I didn't bother with setting it in the VI. I will add the serial port parameters like the example to my current Vi to see if it resolves my issue.

 

Thanks...

0 Kudos
Message 3 of 6
(3,154 Views)

Just tried it, same results, still not reading value from the string...

 

attached, updated file...

0 Kudos
Message 4 of 6
(3,149 Views)

Pay close attention to how you apply your wait statements.  In some cases, I think you are okay, in others I'm not so sure.

 

In the Read Serial CW case, you have no delay between when you write the command and when you see how many bytes are at the port and try to read them.  If you only get a couple bytes of your complete message in before you read, then you are going to have an incomplete message and your subsequent code will never parse it properly.  Compare what you have in that while loop with the Basic Serial Read and Write example.  In that example, there is a distinctive wait between writing the command and check the port for the number of bytes to read.

0 Kudos
Message 5 of 6
(3,138 Views)

After a few more hours of poking and proding, I finally got it to work (aka, keeps working if i restart the computer).

 

The trick was to wire the 'termination char' port on the 'VISA serial configuration' icon. The termination code i used was 'A'.

 

Code attached...

Message 6 of 6
(3,100 Views)