From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Channel OFF/ON program

Hi

 

I'm building a program which send a command to microcontroller, for instance: send number '1' --> channel ADC 1 OFF. And there is my problem: I have 4 channels, which measure ADC voltage on input. I really don't like soldering (:D) so I'd like to turn praticular channel on/off in my program by sending a command to microcontroller. 4 channels, 2 different status -> 16 different combinations. Have you any idea how simplify this process? Maybe I should send a xxxx numeric (x - refers to state 1 OFF, 2 ON, example '1378', channel 1 ON, channel 2  ON, channel 3 ON, channel 9 OFF), and load it to frame in microcontroler?  Byte UDR, which is in charge of reception, have 8 bits, so I have to send '1378' one number by one and I can't do it. Any ideas? 🙂 

0 Kudos
Message 1 of 22
(2,822 Views)
I don't get where 1378 comes from. Send hex as a single byte - 00, 01, 10, 11, etc.
0 Kudos
Message 2 of 22
(2,797 Views)

But how I can transmit boolean values via VISA write? On the input is string only. 

 

 

Here it is, my inefficient solution:

 

inefficient.jpg

 

0 Kudos
Message 3 of 22
(2,791 Views)
You can use a U8 and the byte array to string and then send 4 bytes.
0 Kudos
Message 4 of 22
(2,779 Views)
Clicked too soon.

Or send a single byte. The first four bits could be the channel and the last four the state. OR them together.
0 Kudos
Message 5 of 22
(2,772 Views)

What is 'U8'? Sending 4 bytes (0,1), will complicate situation - I can't recognise if it is channel 1 or 2 etc, because my Atmega will read only 1 byte and then another byte. It will be neccessary to use separator or something like that 

0 Kudos
Message 6 of 22
(2,769 Views)

Ok, seems good. But how I can write information about channel and state to 1 byte array? Array of 8 booleans? Array of booleans will lead to string conversion error 

0 Kudos
Message 7 of 22
(2,763 Views)
A U8 is an integer - 8 bits.

I just realized that you don't even need to send the channel. You only need the state information with the last four bits. Channel 1 is either 0x01 for on, channel 2 is 0x02 for on, channel 3 is 0x04 for on. Channel 4 is 0x08 for on.
0 Kudos
Message 8 of 22
(2,760 Views)

You're smart, thanks! But there is problem in conversion of array of bytes to string...

 

byte.png

0 Kudos
Message 9 of 22
(2,750 Views)

And of course value 0111 can't be converted to numeric

0 Kudos
Message 10 of 22
(2,745 Views)