LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW program for reading data from RS232 port of cRIO

I have connected an Arduino UNO to RS232 port of cRIO using Arduino Tx/Rx pins and MAX2323 converter.

 

I have uploaded a simple hello world program on Arduino, And I want to see the 'hello world' on Labview. (This is just for testing. Later, I'll connect multiple sensors to Arduino and will output the data on cRIO)

 

void setup() {
Serial.begin(9600);
}

void loop() {
Serial.print("hello world ");
delay(1000);
}

However, I cannot read the data on Labview from cRIO port.

 

I have attached the Labview VI to this question

Do I have to write a specific code on the Arduino IDE to send data to the Tx/Rx pins so that it sends the data to cRIO?

What am I doing wrong can somebody please tell?

sarwatsarfaraz_0-1660807635436.png

 

 

0 Kudos
Message 1 of 11
(1,127 Views)

I want to connect an Arduino UNO to cRIO-9042 through RS232 port on the chassis through MAX2323 rs232 to TTL convertor. 

 

The rs232 port on crio uses a RJ50 connector. I do not have a rj50 to DB9 connector, so I have first connected an RJ45 connector to the RS232 RJ50 port, which I believe will centrally align.

I have then connected the rj45 to DB9 port of TTL convertor and the other end of the TTL convertor to Arduino.

 

The following table explains the connections I have made.  

 

CONNECTIONS BETWEEN cRIO RS232 AND ARDUINO:

cRIO RS232 RJ 50 Connector                          RJ45 Connector                              MAX2323 chip                                  ARDUINO

Tx(pin 8 )            <------------------------------->           Tx(7)               <---------------->          Tx(3)          Rx                   <----------->        Tx

Rx (9)                <-------------------------------->           Rx(8)             <---------------->           Rx(2)         Tx                    <----------->        Rx

GND (7)            <--------------------------------->          GND(6)          <----------------->          COM(5)     GND                <----------->       GND

                                                                                                                                                          Vcc                   <----------->       5V

 

Can anybody tell me if I have made the right connections? Because a certain program on Labview is not working so I want to make sure that the problem is not with the connections.

0 Kudos
Message 2 of 11
(1,131 Views)

Hi sarwat,

 


@sarwatsarfaraz wrote:

What am I doing wrong can somebody please tell?


Where does the VI run? Which target is used for this VI?

Does it run on your cRIO?

Did you select the COM port of the cRIO?

 

Btw.:

Use Serial.PrintLn to automatically add a CR and/or LF char to your message. Then you don't need any BytesAtPort in your VI.

See this video!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 11
(1,113 Views)

Yes, this VI runs on cRIO.

sarwatsarfaraz_1-1660811946492.png

 

 

I have selected ARSL1 in the VISA Resource center, since that one is for RS232 port. 

sarwatsarfaraz_0-1660811891645.png

 

 

0 Kudos
Message 4 of 11
(1,103 Views)

My problem has been solved. 

The VI is correct. It was some connections problem which I fixed and I'm getting the Arduino output on LabVIEW via cRIO.

0 Kudos
Message 5 of 11
(1,067 Views)

@sarwatsarfaraz wrote:

The VI is correct. It was some connections problem which I fixed and I'm getting the Arduino output on LabVIEW via cRIO.


At a quick glance, I would not say your VI is correct.  You are just getting lucky.  You need to update your Arduino to use the Serial.PrintLn().  This appends the termination character (Line Feed) to the message.  You can then use that when you try to read.  You just need to make sure the Termination Character is enabled and tell the VISA Read to read more bytes than you ever expect in a message.  The read will end when the termination character is read.  This ensures you get a full message when you perform a read.  There should be no need for the Bytes At Port in this situation.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 11
(1,060 Views)

What do you mean by update Arduino? You mean edit the Arduino code? As in change Serial.print to Serial.printIn?

 

Also, can you please explain in more detail how to make sure that VISA reads more bytes than it ever gets? 

I'm totally new to LabView that's why have no clue about it. 

0 Kudos
Message 7 of 11
(1,054 Views)

@sarwatsarfaraz wrote:

What do you mean by update Arduino? You mean edit the Arduino code? As in change Serial.print to Serial.printIn?


Yes, exactly that.

 


@sarwatsarfaraz wrote:

Also, can you please explain in more detail how to make sure that VISA reads more bytes than it ever gets? 


You just wire up a constant to the VISA Read.  I tend to set the number of bytes to read to 50 or 100, which is generally more than most instruments would ever send in a single message.  My general use library defaults to 4096 bytes to be extra sure.

 

For a lot more information, go watch this: VIWeek 2020/Proper way to communicate over serial


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 11
(1,028 Views)

You mean like this? 

 

sarwatsarfaraz_0-1660889347974.png

void loop() {
Serial.println("hello world");
delay(1000);
}
0 Kudos
Message 9 of 11
(976 Views)

Hi sarwatsarfaraz,

 


@sarwatsarfaraz wrote:

You mean like this?


Delete the wait function inside the loop: VISARead will wait anyway for the next message (until the timeout set at ConfigureSerialPort)…

 

Did you watch the video on proper serial communication that was linked twice in your thread?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 11
(969 Views)