LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Escritura y lectura de un puerto serial

Que tal buen día, tengo un problema para terminar mi proyecto de estadías en una empresa y quisiera saber si alguien puede darme algún consejo. Les cuento, me pidieron que realizara una prueba para un subensamble el cual se comunica a través de un puerto serial. El funcionamiento de este ensamble funciona en base a unos comandos que ya tiene programados la tablilla, lo que debo realizar es una prueba que mueva dicho ensamble y en base a la lectura del puerto decidir si pasa o no la prueba. La prueba consiste en que desplace el subensamble con el comando A±n (n=100,200,300,...,1000) y cada vez que lee el puerto me muestra los valores que va marcando un potenciómetro (la lectura la hago en tiempo real), lo que pensé fue guardar cierta cantidad de lecturas en un array y tomar el valor mayor o menor (según sea necesario) para comparar lecturas y así decidir si la prueba falla o no, pero es necesario limpiar el puerto para hacer eso (lo cual no entiendo cómo hacer). Un ejemplo seria que cuando escribo A350 la lectura seria: Aperture=2344, Aperture=2345, Aperture=2346, Aperture=2347, Aperture=2348, Aperture=2349, Aperture=2350, Aperture=2351, etc. 

Siendo más específico, necesito crear una secuencia para escribir varios comandos (que tengan un tiempo de diferencia para poder ejecutarse en el ensamble) en el puerto serial y leer cierta cantidad de valores. Para leer el puerto uso un "feedback node", de manera que me concatena la lectura en un string, de ese string creo un array el cual me guarda valores que necesito para la prueba.

Les comparto captura del diagrama de bloques y el VI para su comprension.        

Download All
0 Kudos
Message 1 of 2
(662 Views)

Hi Juan,

 


@JuanArturoCG wrote:

Hello, good day, I have a problem finishing my stay project in a company and I would like to know if anyone can give me some advice. I tell you, they asked me to perform a test for a subassembly which communicates through a serial port. The operation of this assembly works based on some commands that the board has already programmed, what I must carry out is a test that moves said assembly and based on the port reading decide whether or not it passes the test. The test consists of moving the subassembly with the command A±n (n=100,200,300,...,1000) and each time it reads the port it shows me the values that a potentiometer is marking (I do the reading in real time) , what I thought was to save a certain amount of readings in an array and take the highest or lowest value (as necessary) to compare readings and thus decide if the test fails or not, but it is necessary to clean the port to do that (which I don't understand how to do it). An example would be that when I write A350 the reading would be: Aperture=2344, Aperture=2345, Aperture=2346, Aperture=2347, Aperture=2348, Aperture=2349, Aperture=2350, Aperture=2351, etc.

Being more specific, I need to create a sequence to write several commands (that are timed apart so they can be executed on the assembly) to the serial port and read a certain number of values. To read the port I use a "feedback node", so that it concatenates the reading into a string, from that string I create an array which stores the values that I need for the test.

I share a screenshot of the block diagram and the VI for your understanding.


Please watch this video to learn the almost anything you need to know about serial communication using VISA!

 

When you want to send several commands and read their response then you should use a loop to iterate over an array of commands. The "time apart" between the commands can be another array - or you use an array of clusters containing a command with it's delay time…

 

Other items:

  • You open the port once, but you close it twice: that doesn't sound correct to me…
  • Please learn proper array handling like using BuildArray instead of InsertIntoArray and ArraySubset instead of DeleteFromArray…
  • why are there two wait functions within one loop???

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 2
(616 Views)