12-25-2011 06:42 AM
Hello all,
I'm using a state machine to read a serial port and process its data so my state machine (attached below) works this way:
---state 1: initial state: i configure serial port using visa serial
this state passes to the next one if we detect a byte at port
*****transition1: this transition is true when there is a byte at the serial port : i use visa wait on event with event = serial char
if we have a byte we pass to state 2
-----state 2: we read this byte (using visa read)
*****transion to state 3= true
----state 3: we take this byte and compare it with the character 'S'(S=start) if it corresponds to it we compare the next byte to E (E= end) untill we find this E so we have received a frame under this shape SxxxxxxxxxxE(where xxxxxxx is the usefull information) this frame is saved in an array (comparing every incoming byte with S or E can be also solved by state machine)
this state passes to the next one (fourth state only if we have collected a complete frame (example SxxxxxE)
*****transition2: collecting a complete frame
----state 4: we extract the usefull information and do some processings on it
the problem is for example : we are at state 3 and we receive a byte: we must read it (pass to state2) at the same time as we must pass to the state 4
so we must add a transition which allows me to pass simuttaniousely from state 3 to state 4 AND state 2 ==>is this possible in labview to activate two states at the same time?and how???
please could someone help me ????
thank you very much for responding me:)
12-25-2011 08:54 AM
any help please? i'm really confisued with using queues or semaphores to synchronize loops???
12-25-2011 09:27 AM
Hello Samiti,
Can you post your VI..
Regards,
Bijay
12-25-2011 10:07 AM
@samiti wrote:
any help please? i'm really confisued with using queues or semaphores to synchronize loops???
Yes, posting your VI would be most helpful. I would also point out that this is Christmas (and Christmas weekend), so please be patient with responses because most people are busy with family (myself included). Weekends are pretty slow as it is, and throw in a major holiday, well....
12-25-2011 10:26 AM
hello all,
i'm also supposed to be with my family ,but i've received an email 2 days ago telling me that i've used the wrong arcitecture on my labview work so i must restart all the work done and choose an appropriate architecture: so here i'am alone in my room working while people are celebrating!!! however, thank you guys for paying attention to my vi,, the point is that i'm working with very simple examples to try to understand how can i use state machine architecture to resolve my problem, but i don't really understand how it works, so this is the example i'm actually working on it:
problems:
1-when i connect enum to while loop, case structure which used to be named serial ,extract....turn to 0,1....,is that because the input is a number?
2-how can i compare with S and E and then store all the frame
3-how can i read continusely from port (state 2) independently from other states??
i'm really confused how can i process to find solution????i'm frustrated because of all past months work is the wrong solution and i'm blocked
i would be eternaly thankfull if you help me,or give ideas....
12-25-2011 10:38 AM
the major idea is that labview work must be modular:
-module one : read serial port if there is a byte at the port
-module two :get the read byte and compare it with the header then if the header is found i must look for the footer , when i found both i must put the frame composed by header+usefull information+footer into an array
-module three: get the array element (the frame) and extract the usefull information in order to do some processings on it
modules must be independent==> for exmple module one which reads the serial port must read it continusely independently from other modules ,,, that's why i thought about a state machine , if anyone have another idea or suggestions for state machine one please do not hesitate
12-25-2011 11:36 AM
Hi,
Please check the attached VI. I hope its useful.
Regards,
Bijay
12-25-2011 12:05 PM
ok , thank you , this is a good idea to compare after reading, but the problem is that we must read only if there is a byte at port, with this solution:
state one:configure serial port
transition: byte at port
state two read: read continusely the port using while loop, but what this state is supposed to do is only to compare if there is a byte==> we must compare than check if there is a byte at port if yes we continue comparing
i'll try finding a solution based on your idea,, if you have any other suggestion please let me know
thank you too much for helping me 🙂
12-25-2011 02:43 PM
See this thread for an example that finds valid serial frames.
ben
12-25-2011 07:55 PM
Use the Byte at Port function to return the number of bytes in the buffer (Compare > 0), if true, read the port. Your read state is set to jump to the config state. Make sure your enums are stated and wired in each case, even if set to jump back to the default state.
I don't quite understand your reasoning for having a config state in your state machine. Why configure the serial port every time you want to read it? Config the serial port in your initialization VI at the start of your program, or from your run-time menu or both.