08-18-2022 02:43 AM
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?
08-18-2022 02:23 AM - edited 08-18-2022 02:45 AM
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.
08-18-2022 03:06 AM - edited 08-18-2022 03:08 AM
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.
08-18-2022 03:39 AM
Yes, this VI runs on cRIO.
I have selected ARSL1 in the VISA Resource center, since that one is for RS232 port.
08-18-2022 10:36 AM
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.
08-18-2022 10:56 AM
@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.
08-18-2022 11:28 AM - edited 08-18-2022 11:29 AM
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.
08-18-2022 12:22 PM
@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
08-19-2022 01:10 AM
You mean like this?
void loop() {
Serial.println("hello world");
delay(1000);
}
08-19-2022 01:35 AM - edited 08-19-2022 01:36 AM
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?