Author Topic: Reading an input continuous  (Read 12071 times)

YunLong

  • Newbie
  • Posts: 2
  • I love YaBB 1G - SP1!
    • View Profile
Reading an input continuous
« on: March 17, 2002, 02:17:08 AM »
How to program PLC to continuous wait for an input to be read?

At the moment i can only read an input at the very first time then subsequent, it won't.

i try using "CALL" OR "GOTO" to loop back but give me error when i doing simulation.

My friend is using a visual basic program to send me  singals

Please help tks  :)


« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: Reading an input continuous
« Reply #1 on: March 17, 2002, 08:23:58 AM »
What type of input are your refering to? Is it digital input? analog input? Or serial communication input (since you mentioned your friend is sending you signal using visual basic)?. I guess you are not referring to digital input programmed on the ladder diagram. So you are probably refering to reading a digital input or analog input within the custom function. Note that the digital inputs are only refreshed after the ladder logic finishes a complete scan. So you cannot put a goto loop within a custom function to monitor the change of state of an input.  (A goto loop that could not exit after 0.5 sec will trigger a watch dog time reset hence you get a warning in the simulator)

You need to let the custom function exit after reading the input[n] and the next scan read it again. In this case you either use a periodic clock pulse to trigger the custom function regularly or use the non-differentiated form of the custom function.

One way of forcing an I/O refresh within a custom function is to use the REFRESH command. This is however not recommended because it goes against the basic ladder logic processing and it adds significant processing time to the whole program if you keep doing REFRESH within a custom function.

The above have been described in details in your TBASIC help document. Please refer to:

C:\TRiLOGI\TL5\public\help\tbasic\tbasicIntro.htm

in your harddisk.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

YunLong

  • Newbie
  • Posts: 2
  • I love YaBB 1G - SP1!
    • View Profile
Re: Reading an input continuous
« Reply #2 on: March 26, 2002, 08:53:00 AM »
I'm using these commands to receive a string which will later convert to values

A$ = INPUT$(1)
A=VAL(A$)

Is  the "1" stands for com port 1or ? I having trouble in receiving the input
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: Reading an input continuous
« Reply #3 on: March 26, 2002, 06:20:18 PM »
Yes, the INPUT$(1) means to read from COMM port #1.

Note that INPUT$(n) command is non-blocking, meaning that it WILL NOT wait there until a string become available, (otherwise the rest of the ladder program will cease to work, which is not desirable).  

A string is only accepted when terminated with a CR (ASCII 13 or 0D Hex) character. Hence the PLC's serial port will accumulate all the characters until it sees a CR character and then it will past the entire string to the INPUT$(n) command.

If there is no string availalble, INPUT$(n) returns an empty string.  Hence you need to test whether the return string is an empty string. The easiest way is to check the length of the return string:

e.g.  A$ = INPUT$(1)
       IF LEN(A$) <> 0     ' a string is available
            .....
       ENDIF

You can use a clock pulse to periodically execute a custom function to check for available string.  Incoming serial characters are automatically stored in system buffer up to 256 characters so they won't be lost even if you don't check the serial port very regularly. A one second clock pulse maybe good enough for this purpose.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS