LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Hex Value on DIO

Hello All,

 

I am sending Hex value on USB 6509 DIO card on low of Echo clock (clock.jpg). When I send an software generated Clock pulse, I get in response Echo clock from the microcontroller. I want to send min 1 and max. 4 bytes of data e.g. AA,BB,CC,DD. Presently when I send data, the output I get is different than what I am sending. Also the counter which I am using goes on running and I have to close the vi and start over again to get the 0 value for counter. And I am not able to display in Hex a similar stream of serial data coming on another DIO pin.

 

 Compiling above problems below are my questions:-

1) How to send Hex value on DIO?

2) Is there a way to reset the counter, or is there a different technique for sending boolean array bit by bit? (Data sending.jpg)

3) How to read in bit by bit data and display it into a Hex value?

 

I am using Labview 8.5 and a beginner, so excuse me if I have asked some basic questions.

 

Thanks in advance,

 

Nick

Download All
0 Kudos
Message 1 of 27
(3,709 Views)

Hello All,

 

For the Question 1, I found that the way I am sending Hex value on DIO is correct, just that if I increase my clock speed less than 100msec, then the data sent is incorrect (Microcontroller reads the data on rising edge of Clock). If I use a delay of 100msec between two clock cycles the data sending works. Can I increase speed and still achieve sending a correct data?

For the Question 2, I used "Formula Node", instead of using a counter I used x = x+1, and reset it after all data bytes are sent.

For the Question 3, I tried to use the "Insert Into Array" block. But the data keeps on changing on receiving each new bit. How can I buffer the data till all the 32 bits are received and then display? Here I am trying to create an array of boolean 32 bits.

 

I would appreciate help here..

 

Thanks in Advance.

 

Nick

0 Kudos
Message 2 of 27
(3,635 Views)

It might be easier to see what you're doing if you could attach an actual VI instead of an image.

 

You are doing everything way too complicated. Since you are sending between 1 and 4 bytes of data you need to make sure you are using the correct datatype. Once you have a byte array, you could just autoindex on a FOR loop to send the bits in sequence.

 

Why are you creating and clearing a new task with each iteration? That is a lot of extra work! Wouldn't it be more reasonable to create the task once and then just repeat the io part inside the loop?

 

Why are you using DBL for a counter? That should be an integer (blue). Still, you don't even need any of it.


Nick26 wrote:

Presently when I send data, the output I get is different than what I am sending.


You might want to start by explaining things a bit more clearly. Nobody can tell what you mean by that sentence! While there is only one way to be the same, there are infinite ways to be "different". What kind of data are you sending? What do you get instead? What do you expect to get? 

Message 3 of 27
(3,621 Views)

HI

Are you writing the hex value to the port or do you want to write the bit by bit to only one channel?

 

Following points may help you

1. If you are writing to one channel, put the for loop where you are writing to the channel DAQmx write vi

2. Instead of using insert into array use Build array function, at the output of reading for loop use boolean array to number so you will get the data in hex/decimal form

 

Is it possible to elobrate your requirement 

Hope this helps you

Regards

Santosh

0 Kudos
Message 4 of 27
(3,618 Views)

Hello Altenbach,

 

Thanks for the reply.

 

------------------------------------------------------------------------------------------------------

Altenbach wrote:-

You are doing everything way too complicated. Since you are sending between 1 and 4 bytes of data you need to make sure you are using the correct datatype. Once you have a byte array, you could just autoindex on a FOR loop to send the bits in sequence.

------------------------------------------------------------------------------------------------------

 

As you can see from the Project.vi the user will be entering a Hexadecimal string of 4 bytes(of 8 string length).

I convert this Hex string to Number to boolean array, reverse 1D array and then convert to Number to Hex String to boolean array, rotate 1D array and through Index array write to DIO line. As reversing byte Array does not give the inversed 32 bits, though a faster method. Is there any other alternative?

 

-------------------------------------------------------------------------------------------------

Altenbach wrote:- 

Why are you creating and clearing a new task with each iteration? That is a lot of extra work! Wouldn't it be more reasonable to create the task once and then just repeat the io part inside the loop?

--------------------------------------------------------------------------------------------------

 

Can you help me with this?

 

----------------------------------------------------------------------------------------------------

Altenbach wrote:- 

You might want to start by explaining things a bit more clearly. Nobody can tell what you mean by that sentence! While there is only one way to be the same, there are infinite ways to be "different". What kind of data are you sending? What do you get instead? What do you expect to get? 

----------------------------------------------------------------------------------------------------

 

Here I meant that If I send data AA in the "Commands to Microcontroller" string the data I observe on the oscilloscope on the line is other than AA, this is also confirmed as the microcontroller  also reads other than AA, when clock speed is more than 100msec(delay in loop).

When I send a 4 byte command I expect a similar value from the microcontroller.

 

 Hope I am clear with my requirements.

 

Thanks,

 

Nick

0 Kudos
Message 5 of 27
(3,611 Views)

Sorry, but your code makes very little sense.

 

When you get the response, you start out with a all FALSE 32 bit array and change a single bit to either T or F.

 

 

So you want to write 8 ..32 bits, one bit per iteration. Then there is also an obvious race condition: You write to the "echo clock bit counter output" terminal in one parts and read from a value property in another part. Since there is no data depedency, there is no way to tell what occurs first. As I said, your representations are wrong, there shouldnt be a single orange wire anywhere.

 

Anyway you do an incredible amount if useless operations, converting strings to numbers to byte arrays and back ad infinitum. I am sure there is a much more direct way.

 

Can you explain the instrument setup in more detail? I don't understand how your four DAQ trains are supposed to interact. Why do you call them "loops" if the are all tied to the same while loop?

Message 6 of 27
(3,601 Views)

Hello Altenbach,

 

The attached clock.jpg image shows the communication protocol between NI DIO and Microcontroller.The Functionality required is as below:

1) The user enters Command e.g. 4 bytes (8 string length).

2) When NI clock is started with the falling edge microcontroller also makes its echo bit low.

3) Then first LSB bit data of User Command is to be sent to the NI Data Out line. 

4) With the rising edge of NI clock, the first bit is read by the microcontroller. The microcontroller also makes it echo bit high.

5) This cycle continues till all the 4 data bytes are sent by NI hardware.

6) After 1st byte the microcontroller starts giving data on pin which is to be read and displayed on screen as a string after capturing all bits (in this case 24).

 

My basic requirement was to start the clock, send the data and stop the clock. But i was unable to do so, and I made the clock as a continuous loop. Which I want to change. I just called them loops for understanding nothing else.

 

I will try to change my representations and use shorter conversions, thanks for the reply.

Please suggest how to read bits and store them/capture them and display as a string?

 

Thanks,

 

Nick

0 Kudos
Message 7 of 27
(3,589 Views)

Hello All,

 

From a previous post I used the "dynamic_array.vi" for reading data from DIO pin and I get an array with cluster of two elements x and y. Please tell me how can I read element y from this data? I can see the array of 32 x and y's on my screen but am unable to retrieve them so that I can display them in string format.. I tried unbundle but it does not work. Is there any other method?

 

I also tried to implement the thread "Separating 1D array of clusters containing two elements" but I did not suceed in doing so.

 

Hope someone will repond soon.

 

Nick

0 Kudos
Message 8 of 27
(3,555 Views)

Since your x array has absolutely no information, all you probably need is to built a plain 1D U16 array containing only y.

 

All your x are 1. This seems incorrect anyway.

 

There are still quite a few odd things, e.g.: Since your loop spins only once, you don't need the FOR loop and you don't need the shift register. "Built array" is a more appropriate tool than "insert into array". What is coming into the shift register from the left?

 

Anyway, to get the y component from an array of xy clusters, use unbundle and place a small autoindexing FOR loop around it. You don't even need to wire N.

 

Why don't you attach your actual VI instead of a picture?

Message Edited by altenbach on 02-23-2009 09:12 PM
Message 9 of 27
(3,537 Views)

Hello Altenbach,

 

Thanks for the reply.

 

Sorry for not attaching the VI. Please find attached project1.vi.

 --------------------------------------------------------------------------------

 Altenbach wrote:

Since your x array has absolutely no information, all you probably need is to built a plain 1D U16 array containing only y.

All your x are 1. This seems incorrect anyway.

--------------------------------------------------------------------------------

 I could not find of any other way to read data from DIO line and store into an array so that I could convert it to String format. So I used  x=1.

------------------------------------------------------------------------------------------------------

Altenbach wrote:

What is coming into the shift register from the left?

------------------------------------------------------------------------------------------------------ 

I dont know I just copied the vi from "dynamic_array.vi" from a previous thread. Can you explain how shift register works?

------------------------------------------------------------------------------------------------------

 Altenbach wrote:

Anyway, to get the y component from an array of xy clusters, use unbundle and place a small autoindexing FOR loop around it. You don't even need to wire N.

------------------------------------------------------------------------------------------------------

I tried the above solution but I get element x = 1 and y = 0. I am expecting a String e.g. 00AA55AA. I can see the data in the 1D array cluster of two elements. Data of element Y shows = 00000000 10101010 01010101 10101010. I have attached Array data.jpg for reference.

I would appreciate if you attach a vi.

 

Thanks and regards,

 

Nick

 

Download All
0 Kudos
Message 10 of 27
(3,528 Views)