Write-to-file issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Write-to-file issue

    I'm encountering an error when trying to write into a CSV file I created. The csv file exists and the path is correct, but the prompt is behaving like it can't open.
    In the snippet of code, S is the part number and there are multiple parts being measured in a loop.
    cap1.JPG
    cap2.JPG

    This is my first time trying to do anything like this in PC-DMIS so it might just be something simple that's going right over my head.
    Attached Files

  • #2
    I think it won't like that space in the path name.

    Either that or you need double backslash

    C:\\csv test\\test.csv
    Automettech - Automated Metrology Technology

    Comment


    • #3
      you need to add " before C:\ and after the .CSV.

      See if that helps.

      Comment


      • #4
        I don't think it likes the backslash being the final character in the string.

        Comment


        • #5
          Originally posted by ajlee7 View Post
          I'm encountering an error when trying to write into a CSV file I created. The csv file exists and the path is correct, but the prompt is behaving like it can't open.
          In the snippet of code, S is the part number and there are multiple parts being measured in a loop.
          cap1.JPG
          cap2.JPG

          This is my first time trying to do anything like this in PC-DMIS so it might just be something simple that's going right over my head.
          This line needs to be wrapped in quotes (" ") like this >> "c:\csv test\TEST.CSV"
          PcDmis 2015.1 SP10 CAD++
          Global 7-10-7 DC800S

          Comment


          • Kp61dude!
            Kp61dude! commented
            Editing a comment
            Just realized that's what acgarcia meant...

        • #6
          I always had to combine the variables so that only one was in the writeline code

          Something like :

          Code:
          ASSIGN/V2=CIR2.DIA+" , "+S
          FILE/WRITELINE,FPTR,V2
          or an array
          Code:
          ASSIGN/V2=ARRAY(CIR2.DIA, S)
          FILE/WRITELINE,FPTR,V2
          As far as the file name, hit F9 and navigate to the csv just to be sure

          Last edited by bherrin; 01-08-2020, 01:49 PM.

          Comment


          • #7
            Originally posted by bherrin View Post
            I always had to combine the variables so that only one was in the writeline code

            Something like :

            Code:
            ASSIGN/V2=CIR2.DIA+" , "+S
            FILE/WRITELINE,FPTR,V2
            or an array
            Code:
            ASSIGN/V2=ARRAY(CIR2.DIA, S)
            FILE/WRITELINE,FPTR,V2
            As far as the file name, hit F9 and navigate to the csv just to be sure
            Same here. This is the method I do.

            Comment


            • #8
              File/Open must be a string (or a reference to a variable defined as a string).
              I reference the "ASSIGN/T_PATH" file directory at the top of the routine, just so all the part-specific data is at the top, all the result output is just tossed at bottom in a rather generic format.

              Strings equate to basic text. "So, if you want basic text added to your string you need to place them within quotes. Any time you want to add the value of a assign or feature you have to " + ADD + "that reference, outside of the quotes."

              File/Writeline uses the same string functionality. Reference Below:

              Code:
                  ASSIGN/C_PATH="C:\PRODUCTION\PGMNAME\partnumber.CSV"
                  ASSIGN/T_PATH="T:\MEASURLINK_TRANSFER\CMM CM-00x\partnumber.CSV"
                  ASSIGN/C_TEMP="C:\PRODUCTION\ML_TRANSFER\CMM CM-00x\partnumber.CSV"
              C_FILE     =FILE/OPEN,C_PATH,APPEND
                          FILE/WRITELINE,C_FILE,"/CAVITY ID/" + "," + TRACE_FOLDER + "," + "Position 1" + "," + CAVID
                          FILE/WRITELINE,C_FILE,"/END/"
                          FILE/CLOSE,C_FILE,KEEP
                FILE/MOVE,C_TEMP,T_PATH
              I learned that it's never a good idea to write directly to a network drive. Communication latency WILL omit data output, especially if your output is looped.
              Last edited by louisd; 01-08-2020, 02:30 PM.

              Comment


              • #9
                Originally posted by louisd View Post
                File/Open must be a string (or a reference to a variable defined as a string).
                I reference the "ASSIGN/T_PATH" file directory at the top of the routine, just so all the part-specific data is at the top, all the result output is just tossed at bottom in a rather generic format.

                Strings equate to basic text. "So, if you want basic text added to your string you need to place them within quotes. Any time you want to add the value of a assign or feature you have to " + ADD + "that reference, outside of the quotes."

                File/Writeline uses the same string functionality. Reference Below:

                Code:
                ASSIGN/C_PATH="C:\PRODUCTION\PGMNAME\partnumber.CSV"
                ASSIGN/T_PATH="T:\MEASURLINK_TRANSFER\CMM CM-00x\partnumber.CSV"
                ASSIGN/C_TEMP="C:\PRODUCTION\ML_TRANSFER\CMM CM-00x\partnumber.CSV"
                C_FILE =FILE/OPEN,C_PATH,APPEND
                FILE/WRITELINE,C_FILE,"/CAVITY ID/" + "," + TRACE_FOLDER + "," + "Position 1" + "," + CAVID
                FILE/WRITELINE,C_FILE,"/END/"
                FILE/CLOSE,C_FILE,KEEP
                FILE/MOVE,C_TEMP,T_PATH
                I learned that it's never a good idea to write directly to a network drive. Communication latency WILL omit data output, especially if your output is looped.
                I don't use a string path for opening a file. I have the file location right in the FILE/OPEN dialog, not a variable. I also don't have any issues writing to a network drive.

                Comment


                • louisd
                  louisd commented
                  Editing a comment
                  It happens. Not frequently, maybe 1 in 10k -to- 1 in 100k was our estimated frequency range. We were able to provide evidence it happened, and the network interaction was root cause. It is possible that it is caused by older equipment or us having a slower network speed than you might have, who knows the direct cause.

                  We redundantly sent the same data to a local drive for about 2 months, running 24/7 before we captured it. Hence the move command at the end. This mitigates it entirely.

              • #10
                Sorry about the late response, I left the office early yesterday so I couldn't start testing solutions until this morning.

                I ran down the list of suggestions (double backslash, quotes in path name, combining to write a single variable, etc.) and nothing worked.

                So, I tried the ol' faithful solution and deleted everything and started from scratch. This time everything worked perfectly.
                Here's the final code and the results
                cap3.JPG
                cap4.JPG

                But while I'm here, I have a follow-up question. Does anyone know if it is possible to have a variable input be used as the file name??
                For example:
                C1 =comment/input
                Enter lot number
                FPTR =File/open,"C:\csvtest"+C1.Input+".CSV" <--tried this and it doesn't work like that

                Thanks for the help everyone!

                Comment


                • louisd
                  louisd commented
                  Editing a comment
                  try making that directory reference within an assignment. preview it by hovering over your assign text to make sure the comment input is converting properly.
                  It likely didn't work because you missed a backslash between csvtest" and the +C1.Input
                  should be FPTR =File/open,"C:\csvtest\"+C1.Input+".CSV"
                  Last edited by louisd; 01-09-2020, 10:53 AM.

                • bherrin
                  bherrin commented
                  Editing a comment
                  Try assigning the the entire path to a variable first, then using that variable in the file open line

                  ASSIGN/CSV="C:\\csvtest"+C1.INPUT+".txt"
                  FPTR =FILE/OPEN,CSV,APPEND
                  FILE/WRITELINE,FPTR,V3
                  FILE/CLOSE,FPTR,KEEP

                • ajlee7
                  ajlee7 commented
                  Editing a comment
                  That worked!
                  I used:
                  ASSIGN/LOTVAR="C:\\CSVTEST\"+C1.INPUT+".CSV"
                  FILE/OPEN,LOTVAR,WRITE

                  Thanks guys!

              Related Topics

              Collapse

              Working...
              X