Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Receive incorrect information through serial

Hi, I have a problem receiving information, which I explained in the file below.

0 Kudos
Message 1 of 14
(2,017 Views)

How do you know that you start reading at the beginning of a 10 byte piece.

Maybe you start reading somewhere half way and I don't see something that can capture a new start.

Also send the vi instead of (both vi's in fact) and you seem to initialize the port before each read that anyhow causes trouble.

greetings from the Netherlands
0 Kudos
Message 2 of 14
(2,000 Views)

What do you think is the solution to my problem?

0 Kudos
Message 3 of 14
(1,990 Views)

Please compose your question directly in the forum editor. You can embed your images here.

 

As a first step, you should post your code in the LabVIEW forum, because it is highly flawed.

 

  1. No, a greedy polling loop is never appropriate!
  2. If you want array elements in order, there is no need to wire indices of index array.
  3. There is no way to tell how your two disconnected code fragments relate to each other?
  4. Yes, frame shifts are a possibility and you need to handle them.
  5. Your "x+y" local variable should be replaced by a shift register.
  6. What's in the other cases of the case structure?
  7. What do the subVIs do?
  8. ...
0 Kudos
Message 4 of 14
(1,989 Views)

Hi there

I'm writing a program for serial communication. The information of FPGA is sent to a computer through a USB using CH340 serial converter. Data is being read through LabVIEW software using the VISA Configure Serial Port VI and VISA Read modules. The submitted information is 8-bit and is sent in a 10-byte package. However, when it is read, the sent bytes are disordered.

In the image below, you can see the part of the FPGA code that is for sending information. This code reads and sends a memory 1024 times.

pooya_B_0-1630841221806.pngpooya_B_1-1630841231269.png

 

First two bytes of constant, then two bytes of data and one byte of constant, then two bytes of data and another byte of constant and two bytes of data are sent.

In the image below, you can also see the part of the code that receives the information in LabView.

After reading the information, 10 bytes are separated and we check the place of the constants by a condition that is correct, and if it is correct, the data will be sent to the next stage for processing.

pooya_B_2-1630841244657.pngpooya_B_3-1630841251907.png

 

I really appreciate if you could help me to solve this problem

0 Kudos
Message 5 of 14
(1,958 Views)
  1. No, a greedy polling loop is never appropriate!

What do you suggest to do? I would appreciate if you could spell it out

  1. If you want array elements in order, there is no need to wire indices of index array.

I needed to index the array to specify the start and end of the 10 bytes of data sent.

10 byte is consisting of 3 types of data: Time, Temperature and pulse shape

This is the reason behind wire indexing the index array

  1. There is no way to tell how your two disconnected code fragments relate to each other?

I did not see any relation. They seem to be random

  1. Yes, frame shifts are a possibility and you need to handle them.

Could you please explain it?

  1. Your "x+y" local variable should be replaced by a shift register.

Please explain more about this.

  1. What do the subVIs do?

This is an initial connection that determines that there is a proper connection between application and hardware

0 Kudos
Message 6 of 14
(1,957 Views)
  1. You are waiting for a button to be pressed. There is no need for sub-nanosecond resolution, spinning the loop as fast as the computer allows, using 100% CPU doing nothing but polling one button (See also). If you would place a 50ms wait inside that loop, the CPU use would be millions of times less keeping your computer cool and saving electricity/battery. Of course the really correct way is to have a state machine architecture. Your sequence frame  has probably no purpose and can be deleted.
  2. You don't need to wire the indices! You get the same 10 elements! Less diagram clutter. Fewer places for bugs to hide, e.g. if you accidentally type one number wrong. 

    altenbach_1-1630852415702.png

  3. Exactly. There is no visible relation between your two pictures. We like to see the entire code, so attach your VIs!
  4.  if the other end is continuously sending ...012345678901234567890123456789012... there is no guarantee that a 10 element segment is 0123456789, could equally be 4567890123. That's a frame shift.
  5. Well, learn about shift registers and feedback nodes. There is no reason to use front panel elements (x+y indicator in this case) to store data between iterations. Data belong on the diagram unless it is for user interaction.
  6. Your code shows the presence of subVIs. Since we don't have these, we cannot debug.

 

In summary. Do a few basic LabVIEW tutorials first. Attach your code (VIs, not pictures!) and make sure that all controls have typical default values.

0 Kudos
Message 7 of 14
(1,948 Views)

@altenbach wrote:
if the other end is continuously sending ...012345678901234567890123456789012... there is no guarantee that a 10 element segment is 0123456789, could equally be 4567890123. That's a frame shift.

To elaborate on this a little bit...You need to define a message format to that the receiver knows when the message begins and ends.  It looks like this is a binary message that you are currently sending.  Therefore, I would do something like have a start byte, typically 0x2 (Start Of Text byte as defined by ASCII), followed by your 10 bytes of data, and finally a checksum of some sort.  The checksum could be something as simple as a sum of all the data bytes.  So I am basically recommending adding 2 bytes to your message.  This is also with the assumption that all of the messages are 10 bytes of data.  If that changes, then you will need something to tell the receiver how many bytes of data are in the message.

 

So with this setup, you will first need to make sure the Termination Character is turned OFF.  It is an input on the top of the VISA Configure Serial Port (defaults to TRUE).  Then I would read a single byte until 0x2 is read.  Once that byte is read, read 11 bytes (10 data bytes plus the checksum), perform the checksum operation and verify it is correct.  If correct, you know you have a good message and can do whatever with it.  If the checksum fails, throw away the data.  Regardless, go back to reading 1 byte at a time until 0x2 is read.

 

If you want even more details, go watch this: VIWeek 2020/Proper way to communicate over serial

Around half way, I get into the binary protocols.


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
0 Kudos
Message 8 of 14
(1,943 Views)

Thanks for your help, but I need to constantly get information from the FPGA and process it, and I can not delay doing so. Do you have other suggestions? I will give you my program to make it clearer.
In the case of "x + y", this is a fixed number that is read at the beginning of the program in order to remove (bias voltage) the ambient noise received by the primary data from the rest of the data. The problem I am facing is not in this part. I put an array after Read visa and there I see that my data is received cluttered.

0 Kudos
Message 9 of 14
(1,928 Views)

To start the message, I send two values in binary, the decimal is 65 and 122, and then two bytes of data related to my analog data. A fixed value of 112 is sent to separate the previous data value and two bytes of data for temperature, then another fixed value of 90 and two bytes of data are sent for time.
I need fast processing and I can not use the set of checks. I tried this way before and it slowed down data receiving a lot and there was a problem in processing my information.

0 Kudos
Message 10 of 14
(1,927 Views)