LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to find, separate, and convert hex strings streaming through com port?

Solved!
Go to solution

double post deleted (forum is very unresponsive today for me…)

Best regards,
GerdW


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

After finding some time to work on your problem, perhaps a State Machine is a little too much.  You can have a single loop that just reads the 1 byte.  If it is a 0x7E, read the rest of the message and loop back.  If not 0x7E, just loop back and read the next byte.  See if the attached code works for you as far as getting the data.  I still recommend using a queue to send the data to another loop for processing.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Download All
Message 22 of 39
(2,160 Views)

@GerdW wrote:

Hi mario,

 

still not working

- You are mixing up "hex values" and "normal string display":in state 2 you try to convert the 2 bytes read from port into a number the completely wrong way. Btw. why do you need to write to the local too?

 

No writing necessary it is set to openly stream to the receiver node on com11. 

 

- Which event do you miss? The "stop" event should work, the "port connected" will never work: the event structure is waiting for user events on the frontpanel. Writing to an indicator will never fire such an event as you should have read in the LabVIEW help. Btw. that indicator is written once outside your loop - how will you ever fire an event then?

 

It never gets past the wait for event and get to state 1. the stop event works fine. I tried using bytes at port value change as my trigger but that did not work either. 


 

0 Kudos
Message 23 of 39
(2,158 Views)

@superomario wrote:



What would that look like? when you say write value(signalling)?

 

 


This is to show you how to do a value(signalling) which explains why your state machine can't get past the wait state.  But I do not endorse doing this because it is just delaying inherent logic flaws you have in your program.

 


@superomario wrote:

I don't understand what makes this read one byte at a time then 2 bytes state machine a better solution that just reading in all the bytes at once and doing a string search for the node identifier, then reading a fixed length of string characters that follow that identifier. 


I don't understand your comment here to be able to reply to it.

0 Kudos
Message 24 of 39
(2,154 Views)

THank you for the help crossrulz I will give this a try. To split up the different transmitters based on their identifiers I take the read buffer and perform the substring stuff yes? 

 

Would it work better to add another layer into the true false and do as you suggested to find the node identifier and then build a case structure where if it equals 333 read X bytes, if it equals 444 read Y bytes,  and then send that read buffer to my queue? 

0 Kudos
Message 25 of 39
(2,151 Views)

Sorry it was recommended to me to try: 

 

Based on the data I am seeing, you will want a state machine for reading your data.  First have a state where you read 1 byte at a time until you find a 0x7E.  That will mark the beginning of your message to read.  From there, read 2 bytes and that will give you your message length (not counting the CRC).  So then read the message length+1 bytes.  You will now have your entire message.  I recommend passing that string to another loop via a queue for processing.

 

I don't understand why this is the optimal solution, but others have been suggested and I am going to give them a try too. 

0 Kudos
Message 26 of 39
(2,150 Views)

Thanks Ravensfan for correcting about event structure.

-I am sorry if i used OT as wrong(I thought Off Topic as posted by Ben sometimes), so i used.

Thanks
uday
Message 27 of 39
(2,144 Views)

@superomario wrote:

Would it work better to add another layer into the true false and do as you suggested to find the node identifier and then build a case structure where if it equals 333 read X bytes, if it equals 444 read Y bytes,  and then send that read buffer to my queue? 


I would not add another layer the the case structure in the code I gave you.  Part of the message is how many bytes are in it, which is the first read inside of the case structure.  As I keep saying, you will want another loop to do all of your processing (Producer/Consumer).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 28 of 39
(2,138 Views)

I have the producer/consumer architectur set up, and have it set up to split it up similar to a terminal program into the individual components of the received hex string. I do not know how to say do nothing if the node identifier is not that type of sensor. So for example if 0333 pops up read  the 18byte data string, otherwise do nothing. but I can't figure out how to wire the select comparator to do that so I don't get the plot going back to 0 when a 0444 or 0555 pops up (and vice versa)  since i have 0 bytes wired to the false case. How should I be doing this? 

 

0 Kudos
Message 29 of 39
(2,107 Views)

Case structure accepts other types of case selector also apart from boolean.

-Case selector can be  integer, Boolean value, string, or enumerated type value.

 

Edit: You can even combine compare and select operations into case structure.

Thanks
uday
0 Kudos
Message 30 of 39
(2,103 Views)