LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading and decoding binary packets with serial communication

Solved!
Go to solution

Of course it's not necessary to send a command to have this device blurp out data. (For most devices however they will only respond to a command they receive!)

 

But it is easier to work out the decoding if you have a well known answer back from a device than a whole bunch of data that may or may not start with a full message! That is why I would disable auto data transmission for a start. Once you have the command/response handling working properly you can go about letting the device be vocally incontinent and throw data at you and try to figure out how to find where a message starts and where it ends in the potentially large amount of data you receive. Having such a system working properly will require you to do some sort of asynchronous processing where your receiver is trying to continuously decode data packages and then somehow distribute them to other parts in your program. This is always more complicated to setup and design properly than a simple command/response pattern! So start with the simple thing and once you got that working, you can still decide to upgrade to advanced programming requirements and try to figure out how to do that in a proper way.

 

When programming, always try to work in smaller steps. A house is also not build in one day from ground up, you go step by step and trying to finish the electrical and sanitary installation before there is even a raw building with walls and floors is never gonna work, no matter how advanced your building skills are.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 11 of 38
(1,110 Views)

I have no idea where to start. I'm looking at examples written in different languages and trying to convert them to labview, but some points don't make sense to me.What I don't understand is how this package is parsed. So the room is a disappointment.

Can you suggest an example to start with?Because I really don't know where to start. I'm a little confused.

0 Kudos
Message 12 of 38
(1,095 Views)

Look at the code below, I think I'm swimming in the wrong waters.There are no results.

0 Kudos
Message 13 of 38
(1,087 Views)

You're definitely swimming in murky waters. 😀 Not totally hopeless but far from getting anywhere.

 

I'm very hesitant to post this code. It is a quick hack without ever having been able to test with real hardware. So there are bound to be some problems in it. It is also programmed in a way I would write such a driver and not everything is very clear and obvious to a beginner I'm sure.

 

And it will only work as intended if you disable all the chatty talk only messages from the device and rely purely on command/response operations. I don't like talk only devices and devices that can spew out talk only data together with responses to commands are even worse. They are a total pitta to handle in code in a reliable way.

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 14 of 38
(1,055 Views)

After preventing the device from vomiting information, I tried the code you published. I did as in the code below, but I couldn't get an output. But I think the code should work, I don't know where the problem might be.

I'm not doing something wrong, am I?

0 Kudos
Message 15 of 38
(1,038 Views)

When I tried to do some error checking, I observed that no value came to the field specified in the picture below. I am trying to understand the problem.
In the "Address register read" field, the value ranges between 0-253 but no data can be read.

0 Kudos
Message 16 of 38
(1,034 Views)

First you can't read more than 15 registers in one go. So your 30 is definitely going to cause all kinds of trouble. And yes I should have added some error handling for that case. 🙄

 

For the rest it is pretty impossible to debug this without some hardware to exercise the code with.

 

This was my main reason why I hesitated to post the code. I only know that it should more or less work like that, but have no idea what little pesky critters are still in the code as is. And not wanting to be condescending, but your coding skills are unfortunately on a level where debugging this code is going to be a serious challenge.

 

For a first thing you should disable the termination character on the Serial Port Init function. We are dealing with a binary protocol here, so you can not let VISA try to find termination characters in the data stream.

Then the number that comes out of the case before your red marked rectangle should match the number of registers you requested in the first place before it gets multiplied with 4. If that isn't the case and you are sure your device is not chatty anymore, something is off. If it is still chatting on its own, then you can get of course totally unrelated messages here that it just keeps spitting out and then it is very difficult to verify this code.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 17 of 38
(1,024 Views)

I forgot to turn off the letter search. I tried it as you said. It really doesn't match the address I entered. I type the address(DREG_EULER_PSI – 0x71 (113)) 113 and the result = 14 numbers.
Also, when I connect with labview after setting the factory to cut all broadcasts from its own program, it takes some time to terminate VI.

And it sends information at certain intervals, but there is no data that starts with snp.

 

By the way, I realize that there are a lot of things that I really don't know.

0 Kudos
Message 18 of 38
(1,015 Views)

Pictures are always rather limited especially if you cut them off halfway. And Did you request 14 registers, or is that just the number you receive in the Read Frame VI?

 

And it is barely visible but I think your "String" display is connect at the beginning of your loop but you want to have a view of the string that is passed out of the first loop. It certainly did receive an "snp" header otherwise you could never get into that code frame. That loop as is only terminates if there is an "snp" header and at least one more byte received or there is an error on VISA Read.

 

Did you ever notice that LabVIEW also provides single step debugging and a nice highlight mode? 

 

rolfk_0-1645012346212.png

 

If you click on the two black bars (in this image red because LabVIEW is in break mode already) before starting a VI, you can use the three last icons to step through your code. And if you click on the little bulb you will even see how the data passes from one node to the next. Then you can also right click on a wire and select "Probe" and open a probe window that will show real time data for all probes you have created so far.

 

If this is all news to you, I would recommend to go through the Introduction to LabVIEW and other resources linked to in the main page of this forum. Debugging code without understanding these features is like building a house with your arms tied on your back!

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 19 of 38
(1,004 Views)

I think the problem has been solved. After changing it to 5 as in the picture, the information began to be read.now I get an output. Even though I reset all parameters from the factory provided program, now I get an output.

Download All
0 Kudos
Message 20 of 38
(999 Views)