LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read information from RS-422 protocol

Solved!
Go to solution

Byte count only limits the maximum read, if you have less it'll just read them all and then end. If you'd have byte count set to 10 tho, then the last two bytes would be cut off.

0 Kudos
Message 31 of 54
(3,452 Views)

VI on the recommendation of RavensFan. I reviewed the 'Crossrulz' week presentation. I'm trying to read one byte at a time, similar to the example here. I think the termination byte is 0D because heb is a fixed value. However, sometimes I am having a problem with all the information read is muffled. I don't think this problem is caused by the joystick itself because this only occurs when trying to read information in labview, in a different application it's not a problem.

 

Does anyone know why this problem may be caused, what is the solution?

0 Kudos
Message 32 of 54
(3,426 Views)

You'll have to show what you mean by "all the information read is muffled".  I have no idea what muffled data looks like.

0 Kudos
Message 33 of 54
(3,422 Views)

This sign that I said earlier sometimes appears. The data disappears and reappears on the screen very quickly, as this happens, the data is shuffled, the data collides, the data vibrates. For example, the value 0 changes to 8.

I added the picture before. The same problem appears as a rectangular square. It appears in the middle of the array. Of course, it does not happen continuously. It happens when the first vi is run. Then sometimes it happens.

0 Kudos
Message 34 of 54
(3,412 Views)

Hi worker,

 


@constructionworker wrote:

The data disappears and reappears on the screen very quickly, as this happens, the data is shuffled

The same problem appears as a rectangular square. It appears in the middle of the array. Of course, it does not happen continuously. It happens when the first vi is run. Then sometimes it happens.


Which underlying data values do you receive when this "rectangular square" is shown in the frontpanel?

Can you provide a VI containing such data?

(Once you know which data cause that display you could filter your received data…)

 

Btw. data usually don't "collide" nor "vibrate"…

Best regards,
GerdW


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

Your main problem is that you have no synchronization whatsoever between what your device sends and when you receive it. So while you read some data, this could or could not be an exact data frame and there is no simple way to guarantee that it is.

 

With serial communication you do not have additional trigger lines from the device that tell you: "Here this is an entire frame, you can now decode it!" instead this information somehow has to be embedded in your data. Except since your sensor data is ultimately binary, there is no simple data byte that can be used to indicate the end of the message as that data byte can occur anywhere in a message too. And I still wonder about your claim that it is 7bit, Space, 2 stop bits. RS-422/485 is usually always 8-bit but especially for RS-485 networks with a special meaning for the highest significant bit. Here when this bit is set it means that the lower significant 7-bits are the network node address that tells which device should receive the message. In principle 8-bit, no parity and 2 stop bits should return exactly the same data, if it doesn't, something weird is going on.

 

Now let's get back to synchronization. Your receiver code somehow must be able to clearly and without any doubt reestablish the data frame boundaries in order to be able to interpret the data correctly. Otherwise you end up with this "noise" since the data you interpret doesn't really start at byte 0 of the message but anywhere in the middle and then you interpret the wrong bytes as joystick position and buttons.

 

And your device makes this synchronization fairly hard. If it would send text messages then you could use the built in VISA mechanisme to let it break receiving a message as soon as it encounters the termination character. Since it is binary there is no easy way to let VISA do all the work for you as that termination character 0x0D can theoretically also appear anywhere in the data and then you are introducing even more problems. Rather than just receiving 10 bytes, or whatever your message length is, and HOPE that everything goes right you have to do some more elaborate processing when receiving data. Somehow you have to try to receive data and then analyse it if it can be a valid data frame:

- is the length ok? (there could be more data in the received message since it could contain fractional left over data from a previous message)

- are the two seeming obvious markers of 0x0D and 0x00 at the correct position?

 

If any of this is not true you need to loop back and read more data and append it to the already received data until you can securely find a valid data frame. Only then can you interpret that data frame without strange "noise". And don't forget error handling. If VISA Read returns with anything else but a timeout error, there is something seriously wrong and it makes no sense to try to loop and read more data! 

 

While this may all sound complicated and annoying, this is what robust device programming is about. Just calling a VISA Read function and hoping that everything is alright, may work for some hobby projects with well behaved devices, but it often is by far not enough when dealing with real world devices that are used in industrial environments.

 

I would definitely switch to 8-bit, no parity and 2 stop bits for a next test. If that fails with errors, there is no good way that 7-bit, space parity, 2 stop bits should work instead!

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 36 of 54
(3,400 Views)

Hello ,
I took pictures of the values I received, I added them.
This rectangle pops out very quickly and disappears.

0 Kudos
Message 37 of 54
(3,397 Views)

Hi mr. Rolf Kalbermatter

Your main problem is that you have no synchronization whatsoever between what your device sends and when you receive it. So while you read some data, this could or could not be an exact data frame and there is no simple way to guarantee that it is.

-I also agree with this situation, I guess this can happen when there is no synchronization.

 

With serial communication you do not have additional trigger lines from the device that tell you: "Here this is an entire frame, you can now decode it!" instead this information somehow has to be embedded in your data. Except since your sensor data is ultimately binary, there is no simple data byte that can be used to indicate the end of the message as that data byte can occur anywhere in a message too. And I still wonder about your claim that it is 7bit, Space, 2 stop bits.

 

-First of all I get unstable information when I try a combination other than this. It randomly reads the information that does not change according to the joystick position. Data bits 7 parity: Space stop bits: 2 provide more meaningful information and change information according to the joystick position. That's why I believe this combination is right.

RS-422/485 is usually always 8 bits, but especially for RS-485 networks that have a special meaning for the highest significant bit. Here when this bit is set, the lower meaning 7-bit means that it is the network node address that tells which device should receive the message. In principle 8-bit, no parity and 2 stop bits should not return exactly the same data, if it doesn't, something strange is happening.
-I don't understand exactly what you are talking about here.

If he's going to send text messages, you can use the built-in VISA mechanism to let him stop receiving a message as soon as it encounters the terminate character.
-I do not understand what you mean by the built-in visa mechanism, please can you elaborate a little bit. Please excuse my lack of information.

- is the length ok? (there could be more data in the received message since it could contain fractional left over data from a previous message)

-I think the length is appropriate. If I understood what you mean by length correctly, I added a picture below and I elaborate a bit there.

 

 

I want to thank everyone who helped me here, so I try to do something with my ignorance and learn from experienced people. I can say that I am really new to this. So trying to read data from this current device is a mysterious secret, trying to read data without any information is really difficult.

 

I continue to study and read to understand what was said 🙂

0 Kudos
Message 38 of 54
(3,380 Views)

Ok lets try again:

 

RS-422/485 is usually always at least 8 bits, but for some RS-485 networks, the highest significant bit has a special meaning: When this bit is set, the lower 7-bit are the address of the network node that the controller wants to talk with. With this bit cleared, the byte is part of the data message.

 

In principle, if 7-bit, space parity and 2 stop bits seems to work, 8-bit, no parity and 2 stop bits should work too and return exactly the same data, if it doesn't, something strange is happening. In fact there is a chance that the 7-bit mode returns data with the highest significant bit randomly set, since it is the serial port drivers task to stuff this bit if the data stream itself only contains 7 bits. Most serial port drivers set this to a 0 but some have a bug there and leave it uninitialized and NI-VISA doesn't go and try to second guess the data it receives from the driver.

 

>If the device sends text messages, you can use the built-in VISA mechanism to let it stop receiving a

>message as soon as it encounters the terminate character.

 

This is the configuration for the termination character on the VISA Configure Serial Port function. VISA allows to be configured to terminate on receiving the termination character. BUT, your device uses binary communication and even though it seems to use a specific byte at the end of the message you can't just use VISA to do everything for you. This is because that termination character can almost certainly also occur in your data and VISA can't know which of them is a data byte and which is a termination character.

 

So your Read operation needs to add the smartness to do so. You can't just execute a VISA Read and pass its data to your parsing routine but first need to write a routine that receives data, checks if there is a full data frame present and if not, loops back and reads more data until it can present a complete and valid data frame to your parsing code. So this comes down to you having to write code that loops (is using a loop) and repeatedly reads bytes from the serial port until you have received a complete frame of data, before returning that data to the rest of your code. And this code needs to be smart enough to exit this loop when any of the following conditions is true:

 

- there is any error other than a timeout error on the VISA Read function

- You have properly received a full data frame to whatever criteria your device uses for a data frame

- optionally: some timeout, you pass into the routine, has elapsed to prevent this loop to loop infinitely if there is no device connected to the serial port

 

This is the principle operation you need to follow, whenever your device doesn't send messages with a specifically designated termination character that can not occur anywhere else in your message.

 

A lot of this discussion, guessing and miscommunication could potentially also have been avoided if we actually knew exactly what sort device it is and had a data sheet to look at.

 

There are many possible options this device could have. Maybe it is using the 0x0D or 0x00 as termination character and has special provisions such as COBS (Consistent Overhead Byte Stuffing) or escape encoding to avoid the occurrence of this byte in the data? We don't know, we only have a few confusing front panel shots of data that may or may not be representative of the data your device sends.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 39 of 54
(3,367 Views)

My whole problem with this conversation about "noise" (whatever that truly means) and the graphic of a squashed diamond shape, is that I see absolutely no way that LabVIEW can show a graphic like that inside of an unsigned byte array which is strictly integer values.

 

Actually, it kind of reminds me of a zero that is squashed a bit and stretched wide.

 

Put another unsigned byte array indicator in there, but change the display format to something else like Hex display with 2 characters, or a binary display.  If something is truly wrong with that byte, the error should show up in the other indicators, but in a different manner.

 

 

0 Kudos
Message 40 of 54
(3,351 Views)