LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

RS232 communication with cRIO9040 RJ50 port

Hello,

 

I'm trying to establish my RS232 communication with my electronic card,

I'm using a the RS232 RJ50 port of my cRIO9040,

I think that my port is the ASRL1::INSTR (the only one which is responding when I open a port and read buffer)

Ayous_0-1761643382466.png

So I configure it with NI MAX with BaudRate=115200, 8N1,

I establish my com as it follows:

Ayous_1-1761643508029.png

And I have very strange answers,

Ayous_2-1761643570543.png

I swapped RX/TX to see if it changes something but the result is quite the same,

Here is the manual of the card:

# RS232 Communication — Frame Description

This document describes the format of frames sent via the **RS232** link by the program.
Communication is in ASCII text, at **115200 baud**, using the **8N1** format (8 data bits, 1 stop bit, no parity).

---

## Link parameters

- **Speed**: 115200 baud
- **Format**: 8N1
- **Encoding**: ASCII
- **End of frame**: `\r\n` (carriage return + line feed)
- **Direction**: transmission only (no received frames expected)

---

## Frame types

### 1. Position frames (normal mode)

Sent continuously when the system is operating without fault.

```
>Pos: <raw_value>
>Posdeg: <value_in_degrees>
```

#### Details:
| Field | Description | Type | Example |
|-------|--------------|------|----------|
| `>Pos:` | Raw position read from the sensor (16-bit resolution) | Unsigned integer | `>Pos: 18452` |
| `>Posdeg:` | Position converted to degrees (0.000 to 360.000) | Floating point (3 decimal places) | `>Posdeg: 182.345` |

Each complete measurement consists of a pair of lines `>Pos:` / `>Posdeg:`.

---

### 2. Fault frames (error mode)

Sent when a fault is detected by the system.

```
>Fault: <fault_counter>
```

## Complete example of exchanges

```
>Pos: 12345
>Posdeg: 120.345
>Pos: 12400
>Posdeg: 120.910
>Fault: 3
>Pos: 12500
>Posdeg: 121.750
```

 

And here are the informations I followed to build my RJ50 (from
Ayous_4-1761643903848.png)

 

:

Ayous_3-1761643884220.png

 

 

Do I forget something to work with my RS232-RJ50 port ?

0 Kudos
Message 1 of 6
(218 Views)

Hi Ayous,

 


@Ayous wrote:

I establish my com as it follows:

Ayous_1-1761643508029.png

And I have very strange answers,

Ayous_2-1761643570543.png

Do I forget something to work with my RS232-RJ50 port ?


Why do you need to initialize the COM port in each iteration? You should do that only once before the loop!


@Ayous wrote:

Here is the manual of the card:


Apparently you read a valid (?) response from your device, you just need to parse it correctly.

Do you mind to share the manual (or provide a link to) instead of copying some badly formatted text?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(194 Views)

Hi GerW, thank you for your fast answer,

- I initialize the COM at each iteration because I was playing with it modifying the constants with controls instead, I kept it this way but yes, if it works, I will modify this

- The response I read don't seems to be valid comparing it to what I found in the documentation :

## Complete example of exchanges

```
>Pos: 12345
>Posdeg: 120.345
>Pos: 12400
>Posdeg: 120.910
>Fault: 3
>Pos: 12500
>Posdeg: 121.750
```

This "badly formatted text" is all the documentation I have,

 

Respectfully,

0 Kudos
Message 3 of 6
(188 Views)

Hi Ayous,

 


@Ayous wrote:

- The response I read don't seems to be valid comparing it to what I found in the documentation :

 

This "badly formatted text" is all the documentation I have,


Then you need to ask the manufacturer of that device to provide a better manual!

 

There should be a clear description on the datatypes you need to parse: 

| `>Pos:` | Raw position read from the sensor (16-bit resolution) | Unsigned integer | `>Pos: 18452` |

I would expect a 2-byte integer (U16) value for position, but they don't mention the byte order in the text.

 

We cannot help you with parsing message data when the manufacturer doesn't provide a good description/manual for its product!

 

All I can say: as you can read responses without errors (apparently) the communication should work as expected.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 6
(176 Views)

if you swap tx and rx and are getting the same results you are probably not reading correctly. 

 

What do you receive on your indicator from Visa Read ? (not from the VISa interactive control). 

Tip: INclude a wait milisseconds on the while loop, to give your device some time to process. 

Puting the config serial outside the loop (and the close too) will help troubleshoot too. 

I wonder if you run config serial every iteration it will clear the buffer every time and you loose data there. You are reading 100  bytes, so the function will not return until the 100 bytes arrive or time out occours. 

Is this how your equipment is suppose to do ? 

 

 

0 Kudos
Message 5 of 6
(139 Views)

Thank you GerdW, I'm still waiting an answer from the manufacturer of the card,

 

Hi LVNinja, I swapped Tx and Rx and I had result from both but in a certain position I have no errors from my VIs so I think I have the correct position,

As you told me I modified my RT VI

Ayous_1-1761742367762.png

 

 

The behaviour I have is :

My first Bytes at port found 4092 bytes,

My Read VI read a buffer until he found the termination char \n,

The next iteration the Bytes at port is 4092-return count and the read VI read a buffer until he found the termination char \n,

And again until the Bytes at port is 0 and it does the same thing,

Is it a normal behaviour ? The electronic card is sending me a position in real time by sending frames as I shown before (found in the documentation)

The buffer I read are like that :

Ayous_2-1761742628455.png

 

Which is far from:

## Complete example of exchanges

```
>Pos: 12345
>Posdeg: 120.345
>Pos: 12400
>Posdeg: 120.910
>Fault: 3
>Pos: 12500
>Posdeg: 121.750
```

 

for me...

0 Kudos
Message 6 of 6
(114 Views)