Sending text file to serial port - COM1

Programming Tools, Tips, and Tutorials.
reeskej
Posts: 2
Joined: Sun Jun 01, 2008 10:26 am
Location: Belgium

Sending text file to serial port - COM1

Post by reeskej »

Hi,


I've made a small application to drill some holes on a CNC machine. The output of the program is a text file. I want to transfer this file to my CNC machine by means of a serial cable. To do so, I'm using the print command

Code: Select all

        open "hoekverdraaiing_HAAS.nc" for input as #HaasNC
                open "com1:9600,n,8,1,ds0,cs0,rs" for random as #comm2Handle
                while EOF(#HaasNC)=0
            input #HaasNC, lijn$
            'print #comm2Handle, lijn$
            print lijn$
            print #main.statusbalk, lijn$
        wend

        'sluit com2 poort
        close #comm2Handle
        'sluit HAASNC file
        close #HaasNC

This is working well, except for one thing. The file contains some commas (","). During the transfer these commas are transformed in CR/LF.

How can I overcome this problem? When I'm using a dedicated transfer program, this problem does not occur.

Thanks for your input.
Jos Reeskens
JanetTerra
Site Admin
Posts: 117
Joined: Wed Nov 24, 2004 2:49 am

Post by JanetTerra »

Try using line input instead of input.
From the Help File
Description:This gets the next data line from the open file or device using handle #handle and assigns the data to var$. If no device or file exists that uses the handle named #handle, then it returns an error. The line input statement reads from the file, ignoring commas in the input stream and completing the data item only at the next carriage return or at the end of file. This is useful for reading text with embedded commas
reeskej
Posts: 2
Joined: Sun Jun 01, 2008 10:26 am
Location: Belgium

Line input

Post by reeskej »

Thanks Janet,

You pointed me to the right direction. It's all in the documentation. I should have used LINE INPUT instead of INPUT, because this command sees the comma as a delimiter.
Thank you for your fast reply.


Jos Reeskens
Jos Reeskens