Author Topic: File Read Problem Blues  (Read 7084 times)

raan

  • Newbie
  • Posts: 31
    • View Profile
File Read Problem Blues
« on: February 07, 2010, 12:15:12 PM »
What is written below is a dcusF triggered every 60 secs and where i=-1 ( by  assumption) means the tlserver is not busy  i.e. I am not doing  any online monitoring . The sq.txt file in in the fileservice directory  and where the contents of the sq.txt is:

"hello"
"please"
 
save in notepad as text unicode format. When I launch a monitoring session all I  see for A$ and B$ is blank data. The Java Console says that the file was read.


I=incomm(1)                      
if I=-1                        

print #1 "<read sq.txt>"      
A$=input$(1)
B$=input$(1)

print #1 "</>"
endif

                           
You technical support is awesome.
Raan
 ???

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:File Read Problem Blues
« Reply #1 on: February 07, 2010, 12:49:12 PM »
You may need to put the INPUT$(1) in a loop so that it spend some time checking the incoming data. INPUT$(1) does not block, meaning it is returned immediately when there is no complete string received yet and your program run much faster than the serial data can come in.

Typically you can create a custom function as follow:

' This function read a CR-terminated string received from COMM1
' and' the returned string is stored in A$.
'================================

FOR I = 1 to 10000
   A$ = INPUT$(1)
   IF LEN(A$) <> 0 RETURN: ENDIF
NEXT


Lets name this function RdComm1.

In your actual program, you will "CALL RdComm1" and then check for A$,

   IF LEN(A$)  B$ = A$: ENDIF  ' store the first line in B$
   CALL RdComm1
   IF LEN(A$)  C$ = A$: ENDIF  ' store the second line in C$


« Last Edit: February 07, 2010, 12:50:16 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

raan

  • Newbie
  • Posts: 31
    • View Profile
Re:File Read Problem Blues Almost there
« Reply #2 on: February 08, 2010, 08:32:49 AM »
I am now able to get data stored in my string variables but it is the word "ok" and not the letter in the text file with the following code :
I=incomm(1)
if I=-1
print #1 "<read sq.txt>"
call rdcomm1
D$=A$
print #1 "</>"
endif

rdcomm1
for i= 1 to 10000
a$=input$(1)
if len(a$)<>0
If strcmp(A$,"p") return:endif
endif
next

What I am trying to do is control my plc with a text message that i send to an e-mail acount associated with the plc and which is download by a popmail client and served up to the as a single letter on which to take action
as sq.txt to be read by the plc.

raan

  • Newbie
  • Posts: 31
    • View Profile
Re:File Read Problem Blues
« Reply #3 on: February 08, 2010, 09:01:49 AM »
Wow part art, part science and part voodoo. if I send any letter other that a "p" which is embedded in the code snippet i sent on my 2nd post it reads and posts the correct letter. Go figure

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:File Read Problem Blues
« Reply #4 on: February 08, 2010, 02:59:56 PM »
If two strings are the same. STRCMP returns a 0 (there is also < 0 and > 0 cases). So if what you want is to check for "p" then it should be:

IF STRCMP("A$", "p")=0 THEN
  ...

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

raan

  • Newbie
  • Posts: 31
    • View Profile
Re:File Read Problem Blues
« Reply #5 on: February 10, 2010, 03:02:17 PM »
Well Technical support I finally got there where I can interact with my  PLC  (named Ruby) by sending text to her using my cell phone and by Ruby sending me status e-mails (using an external  smtp applet and not the built in smtp). However the problem I am having now is the  write/read file operations are sometimes quick  and at other times they are slow as evidenced by watching the java console. Can you shed any light on this and how I can keep speedy?
Raan

raan

  • Newbie
  • Posts: 31
    • View Profile
Re:File Read Problem Blues
« Reply #6 on: February 10, 2010, 03:09:39 PM »
TS
Update it seems that read write is dependence  on the size and complexity of the program. It seems like the earlier versions of my code which were smaller and less complex do file read/write faster.
The code differences are maybe 5 lines and 2 or 3 more dcustf .
Please advise.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:File Read Problem Blues
« Reply #7 on: February 11, 2010, 10:27:46 AM »
You have to identify the bottle neck of the operation. When you are dealing with communication there are many factors. The slowness will not be due to the speed of the program execution. Most likely the CPU is waiting in loops for the data to be available. How does your PLC communicate with your external SMTP applet? How is the file written into the TLServer file services directory from your email client?
Email: support@triplc.com
Tel: 1-877-TRI-PLCS