LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino Mega Hardware Serial

Hello Fellas.

i asked this question in another thread about software serial, but i think this deserves a new thread because its hardware serial on the mega

i have been working with my Arduino Mega and the serial connections, but having a hard time figuring this thing out.

The devices im using is an Arduino Mega 2560 and an ID12/20 RFID Reader. (i want the reader to be on serial3).

and so far i tried to modify LVIFA Interface.ino and heres my code:

//RFID Variables

//-------------------------------------

  byte valRfid = 0;

  byte i = 0;

  byte codeTag[6];

  byte checksum = 0;

  byte tempbyte = 0;

//-------------------------------------

/******************************************************************************* **

** NEW COMMAND(RFID)

******************************************************************************** */    

      case 0x35:  // RFID Packet

      if (Serial3.available() > 0) {

        if((valRfid = Serial3.read()) == 2) {        // check for header

          incommingByte = Serial3.read();

          while (incommingByte < 12) {               // read 10 digit code + 2 digit checksum

            if( Serial3.available() > 0) {

          valRfid = Serial3.read();

          if((valRfid == 0x0D)||(valRfid == 0x0A)||(valRfid == 0x03)||(valRfid == 0x02)) { // if header or stop bytes before the 10 digit reading

            break;                                    // stop reading

          }

          // Do Ascii/Hex conversion:

          if ((valRfid >= '0') && (valRfid <= '9')) {

            valRfid = valRfid - '0';

          } else if ((valRfid >= 'A') && (valRfid <= 'F')) {

            valRfid = 10 + valRfid - 'A';

          }

           // Every two hex-digits, add byte to code:

          if (incommingByte & 1 == 1) {

            // make some space for this hex-digit by

            // shifting the previous hex-digit with 4 bits to the left:

            codeTag[incommingByte >> 1] = (valRfid | (tempbyte << 4));

            if (incommingByte >> 1 != 5) {                // If we're at the checksum byte,

              checksum ^= codeTag[incommingByte >> 1];       // Calculate the checksum... (XOR)

            };

          } else {

            tempbyte = valRfid;                           // Store the first hex digit first...

          };

          incommingByte++;                                // ready to read next digit

        }

      }

     // Output to Serial:

      if (incommingByte == 12) {                          // if 12 digit read is complete

        Serial.print("5-byte code: ");

        for (i=0; i<5; i++) {

          if (codeTag < 16) Serial.print("0");

          Serial.print(codeTag, HEX);

          Serial.print(" ");

        }

        Serial.println();

        Serial.print("Checksum: ");

        Serial.print(codeTag[5], HEX);

        Serial.println(codeTag[5] == checksum ? " -- passed." : " -- error.");

        Serial.println();

        }

      incommingByte = 0;

        }

      }

       break;

Right after the IR Case (expanding the case structure)

and i made an edit in syncLV:

void syncLV()

{

  Serial.begin(DEFAULTBAUDRATE);

  Serial3.begin(DEFAULTBAUDRATE);

  i2cReadTimeouts = 0;

  spiBytesSent = 0;

  spiBytesToSend = 0;

  Serial3.flush();

  Serial.flush();

}

Plus in unknown packet

    /****************************************************************************** ***

    ** Unknown Packet

    ******************************************************************************* **/

    default:      // Default Case

      Serial.flush();

      Serial3.flush();

      break;   

    }

  }

  else{

    // Checksum Failed, Flush Serial Buffer

    Serial.flush();

    Serial3.flush();

  } 

So anything i should consider or anything i can do in my firmware, and what can i do in labview to read it ?

i attached my LabVIEWInterface.ino if the you wanna check and see if i did it correctly.

Thanks in advance.

- Thomas R.

0 Kudos
Message 1 of 1
(3,159 Views)