07-11-2007 01:21 PM
07-11-2007 02:20 PM
07-12-2007 11:02 AM
Hi Dennis,
Thanks for your reply.
"Why don't you just set the VISA Read for 2 bytes."
I have tried to set the Visa Read to read 2-bytes at a time but I still get the same problem.
"Since the device is presumably sending data all of the time, you don't know the byte order since you can't synchronize the VISA Read with anything."
I have though of this issue as well but could not really think of a solution to the problem. Either do something in Labview or change the C code in the PIC. You suggested:
"You'll probably have to do a couple of single byte reads, convert and then test if the data makes any sense. If it doesn't, read one more byte, discard that, and then start reading 2 bytes at a time."
I am afraid my knowledge of Labview is just above the Basics 1&2 courses and I would not know how to implement the above.
07-12-2007 11:21 AM
The simplest thing would be to have a single byte transmitted after the two data bytes. With the VISA Configure Serial Port, you would enable the termination character and set the term character to be equal to this single byte you would append. The problem is the byte cannot be a valid data byte. When data is transmitted as text, it's common to use a CR or LF character as the termination character. The x0A and x0D of LF and CR are liable to be valid data and this would ruin the whole synchronization.
I don't have an example handy but I think there have been some posted to the forum. You might want to try some searches. An approcah to take would be a state machine. In the first state, read 2 bytes, concantanate them together and do a type cast to get a number. I don't know if you are sending an unscaled integer or a floating number. Type cast to whatever is appropriate. You could then wire this number to an In Range and Corece function. If the number is in range, go to a state where you continuously read 2 bytes and the conversion to a number. If it's not in range, go to a state where a VISA Read is set to return only 1 byte. Don't do anything with the returned byte, just jump to the continuous read state.
07-12-2007 12:34 PM
Hi Dennis,
Thanks for your fast reply. I am aware of the 'software' flow control you have suggested and the problems that might occur with using it.
As for your suggestion of using a state machne, it is of course a sound idea. However, I do not have much expereicnce of implemented state machine and I am certain that there must be a simpler solution to my problem (or that I am overlooking something).
I would like to ask you this. How would I go about implementing a small rooutine of creating an array of the incoming data and then removing each byte one by one (maybe even at predifiend increments). I would like to do this as I am under the impression that it is the Type Cast that is creating all these problems.
Would it be much to ask for a small example, if you have time.
Thanks Dennis you are a star!
All the best
Alex
07-12-2007 01:07 PM - edited 07-12-2007 01:07 PM
Not sure if this is what you are looking for. I just created a for loop to read 1 byte x number of times. The resultant string array is then wired to another for loop that type casts the string to a U8.
Message Edited by Dennis Knutson on 07-12-2007 12:08 PM
07-12-2007 01:28 PM
Thanks Dennis for your shift reply.
Though this is not exactly what I think I want, It gave me some ideas, which I will try out.
One more thing. If Visa Read reads only one byte at a time it will overflow pretty quickly. I think I am thus forced to have the bytes at port output connected to the VISA Read.
Thanks for your time and I will get back to you with more questions.
All the best
Alex