Shop OBEX P1 Docs P2 Docs Learn Events
Converting Audrino C code to Parallax Issues.. — Parallax Forums

Converting Audrino C code to Parallax Issues..

I'm trying to convert the audrino c code example for Rfid read/write, but am having some issues in the conversion. This is what I have..

the issue I am trying to solve is: serial_open

I'm not sure how to calll the function:

Can someone give me a hand..

Thanks ahead of time..


Comments

  • james.t,

    It looks like you are trying to use the Parallax RFID Read/Write module (#28440) on the Propeller in C.

    I noticed that the Arduino code you translating was a translation of BS2 code and someone placed a Spin translation in OBEX but the only C code appears to be for the Arduino or just the Reader.

    One of the C gurus should be able to help you out.
  • Rather than spending time converting an Arduino project, you can use the librfidser library that already exists in SimpleIDE's Learn Libraries. Make a copy of the librfidser library project, and open the new copy in SimpleIDE. You will need to change the project's Linker options to NOT check the "Create Project Library" checkbox.

    The code will build as an RFID demo program that you can use as a basis for your project...

    Here's the top file of the librfidser project, which when built as non-library creates a test harness for the RFID module (#28440):
    /*
      librfidser.c
    
      Test harness for rfidser library.
    
      Enable -> P2
      Sout   -> P1
    */
    
    #include "simpletools.h"                      // Include simpletools
    #include "rfidser.h"                          // Include rfidser
    
    int rfidEn = 2;                               // Reader /ENABLE pin
    int rfidSout = 1;                             // Reader SOUT pin
    
    rfidser *rfid;                                // Set up device ID
    
    int main()                                    // Main function
    {
      rfid = rfid_open(rfidSout, rfidEn);         // Open reader, start reading
    
      while(1)                                    // Main loop
      {
        char *str = rfid_get(rfid, 1000);         // Wait up to 1 s for card
    
        if(!strcmp(str, "timed out"))             // Timed out?
          print("No ID scanned.\n");              //   display "No ID..."
        else if(!strcmp(str, "70006E0299"))       // Round card ID match?
          print("Round card.\n");                 //   diaplay "Round..."
        else if(!strcmp(str, "0200822A14"))       // Rectangle card ID match?
          print("Rectangle card.\n");             //   diaplay "Rectangle..."
        else                                      // No matches?
          print("id = %s.\n", str);               //   print ID.
      }  
    }
    
    /**
     * TERMS OF USE: MIT License
     *
     * Permission is hereby granted, free of charge, to any person obtaining a
     * copy of this software and associated documentation files (the "Software"),
     *  to deal in the Software without restriction, including without limitation
     * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     * and/or sell copies of the Software, and to permit persons to whom the
     * Software is furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     * DEALINGS IN THE SOFTWARE.
     */
    
    

    dgately
  • Or, if you want it to be really easy take a look at this tutorial: https://learn.parallax.com/tutorials/language/blocklyprop/rfid-scan-and-store-eeprom-project

    You can do this in Blockly or switch to the "code view" and see the resultant C code.

    Ken Gracey
  • Thanks, I've tried the blocklyprop project but its not for the rfid read/write, just the read.. i may have to look again and see if i missed something..
  • To convert code from Arduino requires a little work. First Arduino is CPP and while the propeller support CPP some of the functions are not there.

    I convert the code as close as possible to the original code but there is some bad coding in there to start with which I was not going to fix and I don't have that device to test that the changes I made actually work.

    I switched to fdserial as it has functions close to what is need by Arduino.

    While I have converted serval devices from Arduino over to Propeller I generally start over and write from scratch.

    Mike


    c
    c
    12K
    RFID.c 12.3K
Sign In or Register to comment.