08-23-2016 01:34 PM - edited 08-23-2016 01:35 PM
08-23-2016 01:35 PM - edited 08-23-2016 01:37 PM
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.
08-23-2016 01:36 PM
@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.
08-23-2016 01:38 PM - edited 08-23-2016 01:39 PM
@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.
08-23-2016 01:39 PM
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?
08-23-2016 01:41 PM
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.
08-23-2016 01:47 PM - edited 08-23-2016 01:52 PM
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.
08-23-2016 01:55 PM
@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).
08-24-2016 09:13 AM
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?
08-24-2016 09:21 AM - edited 08-24-2016 09:31 AM
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.