LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ebus protocol (serial data parser)

Hi there!

 

I'm very new to LabView and as my first challenge I would like to try making a remote interface for an ebus device.

The device is sending serial data so I'm planning to use VISA serial driver.

 

I would need some help to start with my project.

The device is sending data but without CRLF. The data is sent continuously and the separator between the "useful data blocks" is a so called "Synchronization Symbol" (can be one or more in sequence) an it's bit sequence is 101010...(AAh) and according to the documentation luckily this value or sequence of this value is never included into the data blocks.

 

As the first step I would like to achieve is to have a terminal like window where I can see the parsed data blocks (like in a serial terminal) in HEX and to have a way to send out such a data block.

As the second step I would like to know how to parse those data blocks further (ex.: 10 26 B5 04 01 00 D9 00 0A 00 23 00 00 00 00 01 00 80 F8 A9 01 00) to extract data like time, temp, ID's etc..whatever is coded into the blocks and display it.

(The data blocks can be of different lenght.)

 

As an example the data block above can be translated as:

M1=Master ID, M2=Slave ID, M3=command, M4=Data block ID, M5=Lenght of data followed (1byte), M6=a block ID, S1=ACK, S2=Lenght of data followed(10bytes), S3=Status, S4=ss(BCD), S5=min, S6=hh, S7=ss, S8=mm, S9=ww, S10=yy, S11=Outside temp L byte, S12=Outside temperature H byte, S13=CRC, M8=ACK 1st byte of the block = Master's ID, second byte= Slave' ID

 

Any help is welcome and many thanks in advance!

 

 

Szabi 

0 Kudos
Message 1 of 9
(5,431 Views)

Hello Szabi,

 

For a quick reference about serial communication please see our Serial Quick Reference Guide:

In the  middle of the page you will find the basic programming model for serial port communication in LabVIEW.

http://www.ni.com/pdf/manuals/371253c.pdf

 

For working programming examples on how to send or receive bytes, please see the built in Example Finder (Help menu -> Find Examples...). Click on the Search tab and search for the keyword "serial". I recommend the Basic Serial Write and Read, Basic 2 Port Serial Write And Read and Advanced Serial Write and Read examples.

 

For a serial input parsing example please see the post on the following link:

http://forums.ni.com/t5/LabVIEW/how-to-parse-serial-data/m-p/1637328#M589095

Please note, that this example employs higher-than-beginner level LabVIEW programming techniques (producer-consumer architecture and state machines for example)  . It is very well implemented though and contains important structures that are used often in LabVIEW, so please take your time to understand it completely, because it will help you in the future.

 

If you have further questions, please feel free to ask!

 

Regards,

Daniel

 

Dániel Fülöp
Field Application Engineer (CLA, CTA)
National Instruments
0 Kudos
Message 2 of 9
(5,386 Views)

Hi Daniel,

 

first of all thanks for your input!

I already checked the forum before opening a new topic and I have seen that parser example (yes, it looks quiet complicated for me at this stage) but there are another two options I found on the forum: http://forums.ni.com/t5/LabVIEW/instrument-io-assistant-parse-hex-values/td-p/1463596 (this looks much more simple for me but we can turn back later to this)

 

But let's take one step after the other because I want to ketch up, understand and learn while I'm building mi little project 🙂

I was trying to read my device with the simple vi attached, which is working OK, but I'm already facing my first question.

I need to tell for the "VISA read" object how many bytes I wish to receive. Now, the problem is that I never know that. As I described above the length of the useful data streams may be different, the only thing I know that it ends with "AAh" so before start parsing the data I need to split them and put it in a kind of buffer. (I guess)

 

Thanks again!

 

br.

Szabi

 

0 Kudos
Message 3 of 9
(5,357 Views)

Hello Szabi,

 

the problem you mentioned (variable package size) is exactly why the correct approach will be to use a loop to receive the bytes from the serial line, a separate loop to parse the bytestream into separate packages, and another loop to process the data.

Let's see the example I suggested earlier. The upper loop is there only to simulate the equipment that is sending the data, so you won't need it if you have real equipment to receive data from. If you want to use real serial data you will have to replace the Dequeue Element function in the "get byte"case with the VISA Read function and read the serial port one byte at a time. The shift register named Buffer will collect the bytes until a full package is received. The "Check" state will decide if you have a complete package in the buffer or not. You will have to modify the logic in the "Check" case to detect the packet borders according to your specifications. If a complete package is received, the state machine will go to the "Packet received"state.  The "packet received" case will send the package to the processing loop through a queue.

 

Some links to the help pages of the more advanced LabVIEW components used in the example:

 

Shift registers and feedback nodes:

http://zone.ni.com/reference/en-XX/help/371361G-01/lvconcepts/shift_registers_feedback_node/

 

Queues:

http://zone.ni.com/reference/en-XX/help/371361G-01/glang/queue_vis/

 

 

Regards,

Daniel

Dániel Fülöp
Field Application Engineer (CLA, CTA)
National Instruments
0 Kudos
Message 4 of 9
(5,336 Views)

Hi!

 

I could not get the vi working with VISA serial. It seems that is still to much for me 😞

Than the idea came that I could use the AAh as termination char which can be set for the VISA serial, and the result is what I expected. I'm getting my clean useful data.

 

So for now I'm happy with my results.

The next step I would like to do is to extract some data and display it. As you can see from the screenshot attached there are many type of data arrays from which I wish to extract the byte values.

As per example 1026 B504 0100 D900 0A00 2948 0822 0805 0820 FBF0 00 contains a timestamp which needs to be extracted somehow (29ss,48min,08hh,22dd,08mm,05ww,08yy)

I would need something like:

If string begins with "1026 B504 0100 D900 0A" then extract byte from the the 11th(29h) to the 18th(28h)

than from 10FE B505 0427 0100 0184 

If string begins with "10FE" extract each byte from 1 to 10 (10h till 84h) and display it

 

I will start reading help files and books but meanwhile any help is welcome 🙂

 

 

cheers!

Szabi

 

parser

0 Kudos
Message 5 of 9
(5,324 Views)

HI!

 

I made some progress in the project but I'm facing a problem I can't understand.

The vi attached below parses the data as I wish until it's facing a 0Dh 0A or 0C on the 6th byte location (last received on the screenshot 0Dh does not appear at Out1) As I noticed any other byte value on the 6th place is not causing any problem but for the mentioned 3 values will simply be omitted and not taken in consideration.

Could somebody explain me what's happening?

Just try and insert the value I placed under the 3rd case and it won't work but replacing 0d with 01 for example will work.

 

Thanks!

 

 Capture.PNG

0 Kudos
Message 6 of 9
(5,309 Views)

The vi attached below parses the data as I wish until it's facing a 0Dh 0A or 0C on the 6th byte location (last received on the screenshot 0Dh does not appear at Out1) As I noticed any other byte value on the 6th place is not causing any problem but for the mentioned 3 values will simply be omitted and not taken in consideration.

 

 


Ok, I think I got it!

It is because the ASCII equivalent of the above characters are whitespace characters like \r\n\f.

 

Is there any workaround?

 

Thanks!

0 Kudos
Message 7 of 9
(5,300 Views)

Hi Szabi,

 

I noticed that possibly you would like to deal with your serial input as a series of bytes instead of a continuous string. If that is the case you can use the String To Byte Array function (String -> Conversion palette) at the beginnig of your processing pipeline. This will require some rearchitecturing of the code, but the result will be much cleaner. This way you will have access to every single byte in the stream and you won't have to deal with string scanning, whitespace characters, etc. If you wish to interpret some part of your input as a continuous string you can convert it back with the Byte Array To String function (same palette).

 

Regards,

Daniel

Dániel Fülöp
Field Application Engineer (CLA, CTA)
National Instruments
0 Kudos
Message 8 of 9
(5,287 Views)

Looks like the link to
  https://www.ni.com/pdf/manuals/371253c.pdf
is broken.  I could not find where it moved to 

DavidDyck_0-1622773748114.png

 

 

0 Kudos
Message 9 of 9
(2,118 Views)