Author Topic: Input ASCII character using serial port  (Read 19621 times)

Agradon

  • Guest
Input ASCII character using serial port
« on: July 15, 2004, 09:32:30 AM »
I just got my hands on a t100MD board, and I need help figuring out how to transfer ( to get me started ), a single ASCII character to the PLC and output it onto the LCD display. Currently, I am using the "InputStr.pc5" program that came along with the card on the installation CD. The ladder program reads from the Input$(1) and prints to the LCD display. I am using Hyperterminal and the WebServer to communicate with the Card by calling commands like:

@01WVS0101000E66

@01WVS0101000D67

Etc...

And all I get is random echo's of the commands on the LCD screen when I get any output at all. Ideally, I would like to be able to send an ASCII character through the serial port and have it pop up on the LCD screen. If you have any idea what I'm doing wrong, please enlighten me :)

-Agradon

Joel Moore

  • Full Member
  • Posts: 128
    • View Profile
Re:Input ASCII character using serial port
« Reply #1 on: July 15, 2004, 09:54:22 AM »
Those are host commands that you are sending.  I'm not sure if you can expect INPUT to be able to read them since the PLC automatically handles them.  Maybe it's a race to see who gets to the comm buffer first, the INPUT statement in the ladder or the CPU's communication algorithm, which is why the results are inconsistent.

Just send the ASCII characters you want to appear on the screen.

Agradon

  • Guest
Re:Input ASCII character using serial port
« Reply #2 on: July 19, 2004, 06:23:10 AM »
Thanks for your answer, but I am still having trouble communicating with the card. I don't really know the basics i.e. what program to use, what commands with what format... etc.

Agradon

  • Guest
Re:Input ASCII character using serial port
« Reply #3 on: July 19, 2004, 08:13:16 AM »
Ok...I figured out how to input strings into the PLC via the serial port using HyperTerminal. In retrospect, it was really easy to do :). The problem now is that whenever the PLC is freshly reset, and I input a string "test", for example, the PLC received a bunch of garbage strings before receiving the input strings, after these strings are received, the strings are input normally. My TBasic program reads the input string, outputs it into the LCD screen and writes the same string back to the HyperTerminal. The garbage strings are always the same, here is a transcript of my HyperTerminal communications:

test                           <----- my input
1WF8     48*             <----- Garbage strings, displayed on LCD
@01WF9     49*        <----- and sent back to HyperTerminal
@01CL4E*                <----- line by line.
@01C133*                <-----
@01CL4E*                <-----
test                           <----- My string returned from the PLC

After this initial weirdness, input/output works fine and the garbage strings do not re-appear unless the PLC is reset again. Is there any way to avoid this confusion?

-Gene

Joel Moore

  • Full Member
  • Posts: 128
    • View Profile
Re:Input ASCII character using serial port
« Reply #4 on: July 19, 2004, 12:18:57 PM »
That's really strange.  I'm not sure what to make of that.  Are you still using the InputStr.pc5 sample program?  Because I can't see anything in there that should send data back out the COMM port so you shouldn't be seeing anything returned to hyperterminal.

Maybe once support sees this they'll have some ideas.


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Input ASCII character using serial port
« Reply #5 on: July 19, 2004, 09:46:28 PM »
You must have just transfered a program to the PLC and the PLC is displaying those remaining host link commands sent during the program transfer process.

TRiLOGI software uses host link commands to transfer its compiled code to the PLC and these host link commands are not lost after the PLC processes these commands in the background. They are still stored in the buffer and you can use the INPUT$(1) to read them. Of course since the input serial buffer is only 256 bytes in size the subsequent host link commands will overwrite the formal commands so what you see are just partial strings.

So right after you have transferred a program to the PLC and you attempt to read from the same serial port using the INPUT$(n) you will see 256 bytes of these "garbage". You own data will only come up after the queue has been flushed.

The easiest thing to do flush out the queue is to turn off power to the PLC and then on again. Alternatively, you can use an input to trigger a custom function that reads the serial buffer continuously using the INCOMM function until there is no more data to read (-1 is returned).

Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Agradon

  • Guest
Re:Input ASCII character using serial port
« Reply #6 on: July 20, 2004, 07:03:23 AM »
That's exactly what seems to be happening. Rather then have to power the PLC off and back on again each time the software is updated, I would like to put in a function to, like you said, clear the buffer before input is read. Could you give me an example of a function that would do that for COMM port 1?

-Gene

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Input ASCII character using serial port
« Reply #7 on: July 20, 2004, 11:14:37 AM »
WHILE INCOMM(1) >= 0: ENDWHILE

The above statement will flush out the queue until no more characters is present (-1 is returned). You can use an input or an internal relay to trigger the above statement.
« Last Edit: July 20, 2004, 11:15:03 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS