03-18-2015 03:44 AM
Hello,
I am trying to communicate with a motor controller using labview. I am using NI VISA where I send a string command using VISA Write and then receive and read a response from the controller with VISA Read.
Is there a way to know the time interval between the first read value received and the next read value received? I placed the VISA Write and Read in a while loop.
03-18-2015 04:54 AM
It is actually you -The programmer- who can decide the read interval (Unless you work event driven).
The regular way is to check how many bytes there are available and then read them all. If you would do that every 1s, then you might have more than 1 message from your motor controller in the Visa receive queue. I believe your motor controller to have a start/stop sequence in each package. You wil have to filter that out so you can reconstruct the packages in case you read the buffer while it was receiving...
If your controller works in a Master/Slave principle you can block your program and wait for the full answer... (but I do not like to block programs waiting on a 2400baud transmission), let the hardware buffer of the UART do the work for you!
If you want to know the TX interval of your Motor controller, use an oscilloscope! 🙂
03-18-2015 07:17 AM
What motor controller? What is the message protocol?
Most instruments use a termination character (usually a Line Feed) to tell the reciever that the message is complete. VISA can take care of this for you. If you are leaving the Configure Serial Port VI's termination character settings as the default, the termination character is enabled. You would then just need to tell the VISA Read to read a large number of bytes and it will stop when termination character is read.
Now the timing will be based on software. You will therefore have a lot of jitter. But you can use the Elapsed Time express VI to compare the times from one iteration of your loop to the next.
03-19-2015 06:04 AM
Thanks crossrulz. I am using a Roboteq HBL 1650. What do you mean by message protocol?
03-19-2015 06:14 AM
Thanks Xilinx. The controller's serial communication port is configured as follow : 115200bits/s, 8-bit data, 1 start bit, 1 stop bit, no parity. Actually I just discovered that my motor controller Roboteq HBL1650 can send the motor current request value every 1 ms. I had to send a string command first though to the motor controller to request the value to be sent every 1ms using VISA Write. Then I had to read the value sent using VISA Read in a while loop.
But when I run the VI, there aren't any value visible in the bytes by port indicator. When I turned on the highlight execution lamp in the block diagram, the value showed in the bytes by port indicator is as high as 12289! What does this really mean?
03-19-2015 07:50 AM - edited 03-19-2015 07:51 AM
First of all do NOT use the Bytes At Port. This controller uses a termination character to state when a message is complete. From page 115 of the manual: "Commands are terminated by carriage return (Hex 0x0d, ‘\r’)." So for your Configure Serial Port function, make sure the termination character is turned on and set the 0xD. For the VISA Read, just set the number of bytes to read to something really large (more than you would ever expect from a message). The VISA Read will complete when it finds the termination character, reads the number of bytes it was told to read, or the timeout is reached, whichever happens first. So use that termination character to simplify your code.
03-19-2015 07:57 AM
You should NOT use the Bytes At Port. According to the manual (on page 115), "Commands are terminated by carriage return (Hex 0x0d, ‘\r’)." So with your Configure Serial Port, make sure the termination character is enabled and it is set to be 0xD (the default is 0xA). Now set the number of bytes to read for the VISA Read to something a lot larger than any message you would expect from the controller. The VISA Read will stop reading when it read the number of bytes it was told to, finds the termination character, or has a timeout, whichever happens first. So use that termination character is make your program a lot simpler and more robust at the same time.
03-19-2015 08:04 AM
crossrulz wrote "Most instruments use a termination character (usually a Line Feed)"
Termination Character
Do you know what your motor controller uses for a termination character? Line Feed?
Get rid of the bytes at port call and just use a VISA read requesting more bytes than what you expect (1000).
Configure the termination character to match your motor controller.
The VISA read will automatically return when it receives the termination character sent by our motor controller.
So after you send the 1ms request, all you need in your while loop is just a VISA read (and some way to stop the loop that meets your needs)
Set the timeout and termination character to meet your needs and the loop will be in sync with your motor controller.
It is the termination character that will let you know the time interval between value received. No timing needed on your end.
What are you doing with the numbers?
03-19-2015 08:11 AM
@Omar_II wrote:
Termination Character
Do you know what your motor controller uses for a termination character? Line Feed?
My messages keep getting deleted from this thread...
I found the manual and it states that the termination character is a Carriage Return (0xD). So for the Configure Serial Port, make sure the Termination Character is enabled and set the 0xD (the default is 0xA). And do NOT use the Bytes At Port. It does nothing but create weird race conditions in this situation.
03-19-2015 09:00 AM
Thanks Omar_II. I suppose that my motor controller uses a Carriage return as termination charactor because when I displayed the read buffer indicator of VISA Read in '\' Code display, I saw '\r' appeared.
If I were to enable termination charactor in the VISA Configure Serial Port function, is there any other configuration needed before I execute the VISA Read and Write funcitions?
I am actually trying to do some data acquisition with my controller. I tried to acquire the motor current mesured by my controller via labview. I need the time axis information for the samples acquired so that I can plot time-based graph to study the evolution of motor current.