LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

rs232

Hello,
I have a problem with my program. I would like to read bytes using "visa read" function.  How to make read byte count changing. Please take a look on attached vi. For example for byte count "8" I would like to execute case structure with selector label" "0", Default ", and for selector label "1" the desired byte count read is "60".
 
Thank you for all the answers.
Download All
0 Kudos
Message 1 of 6
(4,079 Views)

Sorry, I had a look at your vis and I didn't get an idea of what you would like to do (spending 2min..)

Maybe you describe what data you get and how you would like to interpret it. Then someone/I/we can give you some hints or solutions for your problem

I'm shure your dataconversions can be done much more elegant.

PS: I don't want to comment your coding, however have a look at this threat  http://forums.ni.com/ni/board/message?board.id=170&message.id=187562  

http://www.ni.com/pdf/manuals/321393d.pdf#labview_style_guide

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 2 of 6
(4,058 Views)
Ok, the style is maybe not that excellent, but there will be time for optimalization. Now I'm looking for an advise how to read specified byte count (for example 8 bytes) and look in this 8 bytes for a string "010003", and than read 60 bytes and look for a string "010005".Attaching another vi. Maybe it would be now more readable.
0 Kudos
Message 3 of 6
(4,044 Views)

Always a good choice for such tasks is a state machine.

state (as type defined enumeric into the selector of a case structure, each case/state handle one task, look for examples in help/KB)

#wait : wait for data (bytes at port? ) or exit condition true,  data ->#read8 , exit-> exit loop or goto state #END

#read8 : read bytes , use match pattern (string vis) , 8byte pattern found? yes -> #read60  no-> #nomatch

#read60 : read bytes, error? no-> #process_data,  yes-> #ERROR

#process_data : do it  -> #wait

#nomatch : do something (read all data from port?)  ->#wait

#ERROR :

#END  : do some clean up, save data, close files and ports ....

you can add more states later , maybe the port init routine, if you use the type defined enumeric it's just editing the enumeric and add a new case 🙂

Sorry for not providing  an example I currently have no access to LV and when you have the current version, than just hit NEW and select from template - frameworks - standard state machine.

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


Message 4 of 6
(4,029 Views)
Thank you for your ideas. But could someone who have acces to LabView provide me a VI showing this solution (or other ideas)? I would be very grateful, becouse not everything is for me clear.
0 Kudos
Message 5 of 6
(4,002 Views)
Hello Kingarth,
I am not sure if the confusion lies in how to use a case structure, or how to search the string for the values you are looking for.  Case structures execute particular cases based on the input to the case selector (the question mark on the left side of the structure).  If you pass a boolean to this case selector you will have a true or false case to execute.  If you pass an enum, then the cases can be populated with the values of the enum.  I do recommend looking at examples that use the Case Structure for more information about this usage.  The most simple will be to look in the LabVIEW Example Finder under Fundamentals>>Simple Case Structure.
 
The way your last posted code is configured, your case structure will probably never execute Case 1.  It may be better to use one of the string functions to search for a string, rather than a case structure.  I am including a very simple partial VI that will execute a For Loop two times.  The first time it will read 8 bytes, the second 60.  Then instead of using a Case Structure to look for a number, it uses the Match True/False String to search for a pattern.  I do not know if this is exactly what you are trying to do, but I hope that this helps.  There are many other ways that this could be achieved.
 
In general though I would not use the returned string as the value passed into your case selector.  You could use a comparison to see if you read 8 or 60 bytes then pass the resulting boolean value to the case selector.  I hope that this helps.  Good luck with your application.
Regards,
Angela
Applications Engineer
0 Kudos
Message 6 of 6
(3,957 Views)