Author Topic: Getting ASCII data from DataLogger  (Read 10500 times)

jabaez

  • Newbie
  • Posts: 1
  • jabaez
    • View Profile
Getting ASCII data from DataLogger
« on: April 04, 2004, 06:40:11 PM »
Hello,

I need to read data from a datalogger and store it in T100MD EEPROM for further analysis

The Datalogger has a RS232 port and handles "plain" ASCII protocol. To get data from it, a command (D?) is sent by the the PC and the datalogger sends information in this format

Site xxx
Date xxxxx
Date1 Variable1 Variable2...Variablen
..........................................................
Date24 Variable1 Variable2...Variablen
END

How can I use T100MD PLC to interrogate this datalogger and "interpret" (parse)  information sent by PLC ?

Your help will be greatly appreciated

Thanks

Jesus Baez

Jesus Baez
ACEE
Phone/Fax: +52 81 8114-9771

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Getting ASCII data from DataLogger
« Reply #1 on: April 05, 2004, 09:53:09 AM »
The M-series PLC should be able to handle this with ease.

When you send "D?" to the Datalogger, do you need to send CR or CR+LF? Does the datalogger return multiple lines of ASCII text? Are each line terminated with CR or CR+LF?

You can use the PRINT #1 "D?" statement to send a "D$" terminated with CR and

   PRINT #1 "D?"+CHR$(10);

to send "D?" termianted with CR and LF.

Then after that, you can use the INPUT$(1) command to read the data
returned from the Datalogger until INPUT$(1) return an empty string.

You do have to take care if there are delays between each line of text
received from the data logger. You can use a clock pulse to trigger a
custom function to read one line every 0.1s until A$ return an empty
string:

    A$ = INPUT$(1)
    IF LEN(A$)=0 RETURN: ENDIF
       .....    ' process the string.

Since the PLC automatically buffers the incoming data in its 256 bytes input queue there is no need to worry of losing any character if you don't read them in time, unless more than 256 bytes has been received before you issue an INPUT$ command.

Data from the string can be extracted using the "MID$" function and numerical data can be converted to integer by using the VAL or HEXVAL functions. YOu will have to check the TBASIC language help or programmer's reference for the use of these commands.

Note that if your datalogger returns a CR+LF, the LF may appear as the first character in the next received string since INPUT$(1) only strips away the CR character but not the LF character.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS