LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading data from serial not working

Hello, I am doing a VI to communicate via serial with a inverter using ASCII telegrams standardized by the manufacterer. I already tried bytes at port, for loops, while loops, connecting in series and in parallel, among other solutions I saw on this forum. I was expecting a return string everytime I send a write, but my read keeps reading the previous "write" command and doesn't show any return. How can I solve this and how can I know if it is a inverter or a labview problem.

I will attach the inverter manual too so you can know the protocol (topic 8.13).

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

Hi Luigi,

 


@luigimiotti wrote:

I already tried bytes at port, for loops, while loops, connecting in series and in parallel, among other solutions I saw on this forum.


Using BytesAtPort is not recommended.

But you even did it worst: placing BytesAtPort inside a FOR loop with a wait function. Iterating 5 times and using only the value of the last iteration!? Why not wait 5*100ms and call BytesAtPort only once???

 

Before you do anything more with this VI you should carefully watch this video (even more than once)!

 

More comments on your VI:

  • You forgot to attach all those subVIs. (You should handle all VIs within a LabVIEW project, and collect all related files inside a folder. Next time just ZIP this folder…)
  • There are a lot of terminals in the blockdiagram without a label: NEVER delete the label of FP elements! You may hide them in the frontpanel, but NEVER delete them…
  • The VISA reference wire is branched several times: this is not a recommended style for handling a serial communication! (After all it's a serial communication, which is hard to parallize!)
  • There are lots of coercion dots visible: they have a meaning and can point to possible code problems…
Best regards,
GerdW


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

Thanks for your tips, I started this project from complete zero and it just became a megazord of lots of projects found. Actually I have a update, I tried both "simple serial" and "continuous serial" example vi's and on both of them my inverter returned exactally the same code I sent. This means the problem is on the inverter?

And I tried to put the exact amount of bytes I expect from read but then nothing works on my code anymore. The I put the read in a while loop with delay and one iteration but the same problem remains. How can I correctly do it?

0 Kudos
Message 3 of 7
(1,075 Views)

@luigimiotti wrote:

Hello, I am doing a VI to communicate via serial with a inverter using ASCII telegrams standardized by the manufacterer. I already tried bytes at port, for loops, while loops, connecting in series and in parallel, among other solutions I saw on this forum. I was expecting a return string everytime I send a write, but my read keeps reading the previous "write" command and doesn't show any return. How can I solve this and how can I know if it is a inverter or a labview problem.

I will attach the inverter manual too so you can know the protocol (topic 8.13).


Your inverter uses a MODBUS interface.  While MODBUS is inherently serial (one bit at a time on the physical layer) it has some specific features required to exchange information with "Coils" and "Registers" at the "Address" of the target.

 

Reading a register requires a different "command code" than writing a "Coil".  There are MODBUS libraries available to help! But, you will need to learn from reading manuals, help files and internet searches.

 

And yes, I did once Architect a DES lab with that inverter as one of many possible ones.


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 7
(1,030 Views)

@luigimiotti  ha scritto:

I was expecting a return string everytime I send a write, but my read keeps reading the previous "write" command and doesn't show any return.


This suggests that you are using a RS485 interface with ECHO enabled, that is what you send is also echoed to the serial input buffer. Usually there is a way to disable ECHO on such interfaces (this function may have a different name). In case this is not possible, your program should be aware that any answer will be prepended by the sent command.

Another option is, as already suggested, to enable the Modbus protocol and use a suitable communication library.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 7
(1,002 Views)

Please can you include a screen shot of the block diagram?

(I cannot open the VI because I am running an earlier version of LabVIEW.)
Are you using RS485? and/or an RS232 to RS422 / RS485 adapter?

 

The TX and RX lines of an RS485 bus are the same.

If the connector has separate TX and RX terminals, there is also usually some switches or jumpers that connect the TX and RX lines together.


If the TX and RX lines are connected together, you can expect to receive back the data that was sent.
You can either deactivate the receiver during transmission or perform a double read.

0 Kudos
Message 6 of 7
(996 Views)

Considering that much have been said, i would like to send 2 links from my youtube channel that i uploaded recently on how to use modbus library with LabVIEW, even though the videos are in portuguese, you may contact me from comment section that i will be happy to help.

 

Como fazer um multimedidor de energia utilizando PZEM 004T no LabVIEW comunicando Modbus RTU

https://www.youtube.com/watch?v=YhC4yg3O58Y

 

Medição de energia com LabVIEW utilizando Raspberry Pi e PZEM com rede Modbus RTU e Hobbyist toolkit
https://www.youtube.com/watch?v=ja2TWlfPCUE

regarding your code, i recommend a different architecture, maybe a producer consumer with events to read and write from your inverter.

Jorge Augusto Pessatto Mondadori, PhD
Sistema Fiep
CLAD, CLD
0 Kudos
Message 7 of 7
(985 Views)