Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

String Subset from Serial error

Solved!
Go to solution

Hi Everyone

I have  a simple program. I have used arduino to tranfer some string to labview.

And In Labview I want to Subset string. But, It is working only first string and the later strings not be subset.

Can you help me find my error?

Thank for reading

Here is my code and my error

serial.png

 

Here is my Video: https://www.youtube.com/watch?v=Gm5nOrZ3iyo

Here is my arduino code:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int i=0;
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x20 for a 16 chars and 2 line display

void setup()
{
  lcd.init();    // initialize the lcd
  Serial.begin(9600);
 // attachInterrupt(0,irt1,CHANGE);
  attachInterrupt(1,irt2,FALLING);
  // Print a message to the LCD.
  lcd.backlight();
  lcd.print("Hello, world!");
  Serial.print("Hello, world\n");
  delay(1000);
  lcd.clear();
}

void loop()
{

  while(Serial.available())
  {
  char r = (char) Serial.read();
  if(r=='t')
  {
    lcd.setCursor(0,0);
  lcd.print("you are robot");  
 // Serial.print("you are robot\n");
  }
  else if (r='a')
  {
    lcd.setCursor(0,0);
    lcd.print("you are human");  
   // Serial.print("you are human\n");
  }
  }
}

void irt2()
{
  delay(1500);
  i++;
  if(i%2)
 { Serial.print("ngaysinh010071992\n");}
  else
  {Serial.print("ngaysinh123455\n");}
}

0 Kudos
Message 1 of 7
(3,589 Views)

That feedback node is keeping all of the read data.  The first 7 bytes will never change since they will always be from the first message.  Since I'm sure you just want to see the latest message, just wire the substring indicator to the data coming out of the VISA Read.

 

Let's take care of some other issues while we are at it.

1. Get rid of the Bytes At Port.  You are using the Termination Character.  So let VISA use it.  The VISA Read will stop reading when it encounters the termination character or it reads the number of bytes specified, whichever comes first.  So use a constant to tell the VISA Read to read a larger number of bytes than you would ever get from a message.

2. The VISA Clear isn't really needed.


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 2 of 7
(3,586 Views)

thank for support.

Let me try again

0 Kudos
Message 3 of 7
(3,583 Views)

Hi. I have tried but It still not working.

Morever, I want to compare input string with constant string. But It working only with first string

I know feedback node is problem, But I can not fix it.

Can you help me fix it?

thanks

error.png

0 Kudos
Message 4 of 7
(3,567 Views)

Your Read Buffer is EVERYTHING that you have received.  Any comparisons you want to do should only be on the CURRENT message.  So the output of the VISA Read should be going to the Equals function, not the output of the Concatinate String.


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 5 of 7
(3,565 Views)

How can I fix it? Please help me

0 Kudos
Message 6 of 7
(3,563 Views)
Solution
Accepted by topic author xaxa9ztb

I went ahead and did some cleaning up of your diagram.  See if this makes sense.


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 7 of 7
(3,558 Views)