10-26-2009 04:57 PM
It depends. What exactly are you trying to accomplish? Will you still be using the commerical application or are you replacing that with the LabVIEW application? Is the LabVIEW application going to act as a middle man to interpret the commands from the commerical application and translate them into the command set for the treadmill? If you will still be using the commerical application you will need to know what is sends and expects to receive from the treadmill. If you are creating a layer between the treadmill and the software then you will need to implement both sides of the communication. The suggestion I gave you regarding the very simple LabVIEW application is to stub out the treadmill portion of the system and allow you to capture what the software application is sending.
If you are reverse engineering the entire communication chain it is always easiest to do this with a working system. As it has been suggested this means talking to the actual treadmill. If the communication between the treadmill and the application is not bidirectional than creating the simple stub like I suggested would be enough for you to capture what actually getrs sent when each button on the appication is pressed. From there you can create the necessary functionality in your LabVIEW application.
10-27-2009 03:15 PM
It looks like I have been able to figure a few things out. Thanks to you guys. I am using two computers to do this and without actually connecting the treadmill, I have been able to issue a command using LabVIEW to accept that there is a connection. And now, by pressing every button on the software and listening to the port as suggested by Mark, I have kinda verified the codes and they seem to match the minimal documentation that I have. Thanks guys!
But, now going to LabVIEW, i have a question. How do I set the "byte count" in "VISA read" to be dynamic? Like, I am able to set it to say 10 bytes, it shows 10 bytes on the buffer. How to I keep clearing the "read buffer" to update to new information that has been received as an when I click the icons on the software?
V
10-27-2009 03:18 PM
@ Mark, Yes I will be using that commerical software (kinda have to) but i thought of first doing the same on LabVIEW and then making labview a middleman. But, turns out I have been able to sniff out the codes that are under each icon of the software and now with LabVIEW as middleman, I will have to figure out a way to perform appropriate operation with the treadmill hardware.
V
10-27-2009 03:31 PM
VeeJay wrote:
But, now going to LabVIEW, i have a question. How do I set the "byte count" in "VISA read" to be dynamic? Like, I am able to set it to say 10 bytes, it shows 10 bytes on the buffer. How to I keep clearing the "read buffer" to update to new information that has been received as an when I click the icons on the software?
V
I am not entirely sure exactly what you would like to do but I assume you are trying to either read data that is variable length or read the buffer in its entirety. There are a few different approaches you can take. You can use the VISA function "Bytes at Serial Port"to read how many bytes are available and then read that amount.
Another approach would be to read a large number which would be larger than your longest message and simply read whatever is there. In this case you would also have to ignore and clear the timeout error that occurs. In addition, you would not want to set your timeout too long or you will be waiting most of the time for more data and wouldn't actually be processing the data.
Yet another approach would be to read a single byte at a time in a small, fast loop. Again, you would need to ignore and clear timeouts but you would keep cycling back to read a byte until told to stop. When a byte has been read it would have to be posted to a queue for another task to process. This task would have the intelligence for handling the different messages that are expected.
If you are lucky there is a defined protocol used which is effectively a command/response scheme where you should know what data to expect back and what to read. Even better would be if the data always included a length field which would tell you exactly how much data you need to read.
10-27-2009 03:34 PM - edited 10-27-2009 03:35 PM
VeeJay wrote:
But, now going to LabVIEW, i have a question. How do I set the "byte count" in "VISA read" to be dynamic? Like, I am able to set it to say 10 bytes, it shows 10 bytes on the buffer. How to I keep clearing the "read buffer" to update to new information that has been received as an when I click the icons on the software?
There are two ways of doing this, depending on the communication protocol.
If the messages returned by the device end with a specific character (like a linefeed), then you can configure the serial port initialization VI to enable termination, and set the termination character to be the character that indicates the end of a response. Then, simply wire a large number to the VISA Read for the byte count. The VISA Read will terminate once it sees that magic character. One of the examples that ships with LabVIEW shows you this.
If the messages returned by the device do not end with a specific character then you need to use the VISA Bytes at Serial Port to find out how many bytes have actually arrived at the serial port and read that many characters. You will need to do this in a loop, and stop the loop once you know you've received the full response. There's also an example that shows you how to do this.
EDIT: Sorry for the double response - was writing my response at the same time that Mark was...
10-27-2009 03:39 PM
smercurio_fc wrote:
VeeJay wrote:But, now going to LabVIEW, i have a question. How do I set the "byte count" in "VISA read" to be dynamic? Like, I am able to set it to say 10 bytes, it shows 10 bytes on the buffer. How to I keep clearing the "read buffer" to update to new information that has been received as an when I click the icons on the software?
EDIT: Sorry for the double response - was writing my response at the same time that Mark was...
Message Edited by smercurio_fc on 10-27-2009 03:35 PM
But you also caught the case that I missed. You included the termination character.
10-27-2009 04:11 PM
Thanks for the immediate responses. The thing is there is communication both sides. And, there is no particular interval between which commands are sent and received. On LabVIEW, if it doesnot receive any msg within a certain time, it shows a timeout error. I guess I have to check the examples on how to eliminate timeout errors. And I don't see any termination characters after each command. But, will look more deeper on that one.
I guess I am reading one or 2 bytes at a time, just that there are timeout errors, if there is no code sent from the software to LabVIEW (say after the treadmill has been started for 30seconds).
And, in the labview code, is it good to use "Run Continuously" or do I use while loop?
V
10-27-2009 04:28 PM
VeeJay wrote:Thanks for the immediate responses. The thing is there is communication both sides. And, there is no particular interval between which commands are sent and received. On LabVIEW, if it doesnot receive any msg within a certain time, it shows a timeout error. I guess I have to check the examples on how to eliminate timeout errors. And I don't see any termination characters after each command. But, will look more deeper on that one.
I guess I am reading one or 2 bytes at a time, just that there are timeout errors, if there is no code sent from the software to LabVIEW (say after the treadmill has been started for 30seconds).
And, in the labview code, is it good to use "Run Continuously" or do I use while loop?
V
As I indicated in my previous posts you will need to catch and process the timeout errors. There is a Clear Errors VI under the "Dialog and User Interface" palette.
Don't use the run continuously. Use a while loop with the appropriate means of deciding when to stop such as a user selection to stop.
10-29-2009 01:27 PM
Hi Guys,
I seem to have made some progress in figuring out the codes behind the buttons. Now, I have a list of commands and their corresponding ACK's that I have to program on LabVIEW. How do I go about doing that? It is equivalent to programming "bytes" (that are commands) on a processor. Thanks!
V
10-30-2009 09:25 AM
I have one more question. How do you convert a string that you obtain from the Serial read Buffer into a hexadecimal number? The information that the port is reading is basically hex codes but they are in string format. How do I convert then into Hex number or decimal so that I can use them directly in Case structures as case A0 or case A1 to do the corresponding operation.
Thanks!
V