08-20-2024 06:07 AM
Hey all!
I need some help to develop a proof of concept software for reading an energy meter.
I developed the code attached, and it works (kind of)
the problem is that sometimes, at the start of the VI, the communication does not synch however it does read the bytes out of order.
I am reading 9 bytes, if I try to read 8 or 10 they keep scrolling in the indicator array
the protocol works as follows:
1 start bit, 9 data bytes, 1 stop bit, 110 baud rate, and I am reading through a TTL-USB adapter on COM3
data is streamed every 1 second, so I get about 340ms of idle communication channel.
the picture shows VI working. once it works (gets synched correctly) it does not lose synch
The code reads serial and parses message, nothing fancy as a proof of concept.
I need help considering creativity on how to synch this binary streaming communication.
Thank you
Solved! Go to Solution.
08-20-2024 07:43 AM
1 start + 8 data + 1 stop means 10 bits per character. This amounts to 818 ms in my calculations. Idle time should then be 182 ms.
Since you open the serial port at a random time, it's no surprise that synchronization is not good.
It also seems that data have no frame nor termination, which is really bad design. All we have to separate two subsequennt packets is the idle time.
You may do the following: set a short timeout, smaller than 182 but not too much (e.g. 120 ms), then read characters one by one in a first loop. When you get a timeout error (no chars received) you can assume that you hit the idle time: leave the loop, set a longer timeout and jump to the actual acquisition loop. Not really bomb-proof but it should work.
08-20-2024 08:07 AM
worked perfectly, I used 150ms as the first timeout in case others find this topic.
this is a late 90s protocol, so yeah, it is not the best design
Thank you very much,
I will leave some keywords here if someone else develops a similar solution. So Google's SEO can find
ABNT CODI
Medidor de energia
NBR 14522 14519
saída do usuário
08-20-2024 08:29 AM
What device are you trying to communicate with? Even better, do you have a link to the manual? I have trouble believing the developer would have no data frame for their communication. I see you have something for a CRC, so there has to be something to key off of.
08-20-2024 08:45 AM
Hey crossrulz, it is based on a Brazilian standard.
Energy meter manufacturers need to follow the standard guidelines to implement this protocol.
The link for a standard PDF is here: https://enermerco.com.br/wp-content/uploads/2016/12/ABNT-NBR-14522.pdf
There are several protocols described in this document. in case you are willing to check out. I am referring to the protocol "saída do usuário estendida" (Extended user data output) on page 99.
3.4.2.1 Protocol
at each full second, a data block must be transmitted through serial user output (extended format). At each end of demand interval (15 minutes), corresponding block must be sent there consecutive times, repeating such data.
3.4.2.2 Transmission characteristics
110 Baud
assynchronous
monodirectional
char: 1start bit, 8 data bits, 1 stop bit
data block: 9 bytes
time between blocks: 1 second.
logic level 1 represents disabled output
3.4.2.3
binary data
3.4.2.4
describes each byte parsing instruction.
3.4.2.5
represents an overview of data sent
3.4.2.6
presents how to read registers and interpret data
08-20-2024 12:20 PM
Not the most elegant usage, but working as a proof of concept, Thank you all!