LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Control a device with serial communication

Highlighted

Hello,

 

I'm working in a project that consist of controlling 2 axis with serial communication (RS 232). I already did the control of one axis : I put a distance in mm and with my program I calculate the correct frame to send to the device that control my axis.

 

131072 point is a displacement of 2,5 mm.

For the moment, I just want to control 1 axis.

 

But now, I want the program to send by itself several coordinates which are in a txt file (. We need to respect :

- at least 500 ms to send from the program to the device cause of the serial communication.

- If the first coordinate is 0, the second 20 and the third 15, that means the axis should go from 0 to +20 and after 15-20 = -5.

 

The encoder need to communicate the position of the axis all the time (in point), so when the axis is going from 20 to 15, it needs to communicate so the program know if it can send the next position. I put in the Vi "Response of the displacement from device" that will simulate the displacement. If the current displacement is egal to 2, so it means that the axis has arrived at the position (I will change this later with the correct value cause you don't have the device) otherwise the motor turn until it arrives.

 

The problem is that my program stop working when the value of Response of the displacement from device is not egal to 2 and when it's egal to 2 it send all coordinates but that's not what I want ...

 

I hope you understand, sorry for my bad english. You need to download all of 5 files to work :

 

- Projet.vi is the program.

- calcul_checksum.vi is a VI that calcul the checksum.

- displacement.txt is the txt file that contains coordinates.

- XY. is the the program that found X and Y coordinates begin with the G1 lines and put them in array.

 

thank you, best regards.

Download All
0 Kudos
Message 1 of 7
(1,301 Views)
Highlighted

Two problems I see.

 

1.  You are writing something to the serial port and using Bytes at Port immediately after that to determine how many bytes to read.  This is the wrong thing to do about 99% of the time.  That number is probably 0 bytes because you didn't give any time for the other device to give a response.

2.  You are autoindexing in the while loop for your X values.  Every iteration of the while loop uses an element of the array, even if you aren't doing anything like you are in idle mode waiting for the booleans to be pressed.

 

You need a proper state machine architecture.

0 Kudos
Message 2 of 7
(1,284 Views)
Highlighted

So, what do you suggest ? I'm in trouble ...

0 Kudos
Message 3 of 7
(1,269 Views)
Highlighted

A state machine.

 

Look in the templates for a new LabVIEW VI.  Search the forums and ni.com for examples.

0 Kudos
Message 4 of 7
(1,242 Views)
Highlighted

The fact is that I don't know the size of my array, it depends on the txt file created by a CAO. I don't understand in what I can use a state machine ?

0 Kudos
Message 5 of 7
(1,224 Views)
Highlighted

I'd suggest using a package on the toolks network called AutoSerial. It will take care of low-level details of reading data from the serial device. You wont need to know exactly when does the data become available or how many bytes to read and it has a subVI that can expect certain data to become availbale, so it can force your LabVIEW program to wait until the expected data becomes available before moving on or sending comamnds to the device.

Certified LabVIEW Architect (CLA), LabVIEW 2015.
0 Kudos
Message 6 of 7
(1,196 Views)
Highlighted

And if you are not familiar with state machines, I'd suggest you to take LabVIEW core 2 from www.ni.com/self-paced-training 

Certified LabVIEW Architect (CLA), LabVIEW 2015.
0 Kudos
Message 7 of 7
(1,193 Views)