Author Topic: PRINT AND INCOMM keywords  (Read 14884 times)

sid80555

  • Newbie
  • Posts: 36
  • I'm a llama!
    • View Profile
PRINT AND INCOMM keywords
« on: May 31, 2011, 09:10:41 AM »
I need to use the PRINT or the INCOMM keyword to check if the modem which is serially connected to my COMM1 has responded.That is when i send an AT+CMGS="+44XXXX" msg from my PLC it sends an response character(>),after which i send the required message using the print command.I just need to check if the character is in COM1 port without deleting it from here(the print and incomm seem to remove it from port1).Is there another keyword to do this?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PRINT AND INCOMM keywords
« Reply #1 on: May 31, 2011, 09:20:18 AM »
Does the modem send a CR after the ">" character? If so you can use the INPUT$ command to read it. If not you can only use the INCOMM to check it.

Once you read it using INCOMM or INPUT$ the character(s) is/are removed from the serial buffer to free up space for new incoming characters. If you need to preserve what you read you can keep it in a memory (a DM location or a string variable) so that you concatenate it with what you will be reading later.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

sid80555

  • Newbie
  • Posts: 36
  • I'm a llama!
    • View Profile
Re:PRINT AND INCOMM keywords
« Reply #2 on: May 31, 2011, 09:27:11 AM »
It works like this
when i send an AT+CMGS Command from the plc to the modem,the modem responds by sending a > character.After recieving this >character i need to send the necessary message,hence the > needs to be in the comm1 port.So do you mean that i can use the INCOMM keyword.However do i need to read in the ASCII format or as > character?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PRINT AND INCOMM keywords
« Reply #3 on: May 31, 2011, 10:45:07 AM »
">" is sent from the modem to your PLC program and is not needed to be sent back to the modem.

So what you do is to put in a FOR NEXT loop until you get the ">" character from the modem. After that you use the "PRINT #" command to SEND your COMMAND to the modem (">" should not need to be sent back to the modem).
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

sid80555

  • Newbie
  • Posts: 36
  • I'm a llama!
    • View Profile
Re:PRINT AND INCOMM keywords
« Reply #4 on: June 16, 2011, 07:30:12 AM »
I have not been able to get the requird result yet.I have explained below what i have done and if you can let me know where i have been going wrong that would be great :) i have no clue why you say i should use a for loop...
I have attached my ladder logic in the attached diagram.The message1 function sends out PRINT #1 "AT+CMGS="+CHR$(34)+"+44******"+CHR$(34)+CHR$(13) when the input goes to 1.
Then i use a timer of 2 sec to wait for a response from the modem (waiti for the > character).After which message 2 function executes.Message 2 has
A$=INCOMM(1)
B$=CHR$(62)
IF STRCMP(A$,B$)=0 THEN
PRINT #1 "HELLO"+CHR$(26)
ENDIF   

This does not seem to work at the moment,however if my message2 function has only PRINT #1 "HELLO"+CHR$(26)
it sends the message hello(it assumes that the > is recieved in this case).
please help

 

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PRINT AND INCOMM keywords
« Reply #5 on: June 16, 2011, 10:46:21 AM »
I don't think your program will compile. The following statement will cause a syntax error during compilation:

A$=INCOMM(1)


You can try the following in CF message2

FOR  I = 1 to 10000      
   DM[1] = INCOMM(1)
   IF DM[1] <> -1 GOTO @10: ENDIF
NEXT
SETLCD 1,1, "Receive nothing"
RETURN

@10  SETLCD 1,1, "DM[1]=" + STR$(DM[1])+"        "

IF DM[1]= 62 THEN   ' check if '>' char is received.
   PRINT #1 "HELLO"+CHR$(26)
ENDIF  


The SETLCD command above is for debugging purpose and can be removed after you have got your code working.







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

sid80555

  • Newbie
  • Posts: 36
  • I'm a llama!
    • View Profile
Re:PRINT AND INCOMM keywords
« Reply #6 on: June 20, 2011, 05:37:17 AM »
Yeah this works fine.But there is another problem
When i send my first modem configuration message(at+cmgs=1),the response is an OK.After this i send the at+cmgs command.Now when i search for DM[1] it has another ascii value(13 for Carriage return) in it and not ascii value 62.When i check the position of ascii value 62 in the COMM port it comes after 8 response characters 13(CR),10(NEXT LINE),79(O),75(K),13,10,13,10,62. So how in my program can i check for this rather than for checking DM[1],since only 1 bit is read at a time from COMM port.
 

sid80555

  • Newbie
  • Posts: 36
  • I'm a llama!
    • View Profile
Re:PRINT AND INCOMM keywords
« Reply #7 on: June 20, 2011, 02:55:47 PM »
I understand the INCOMM command just lets me read the first character in the circular buffer, but how will i read the 9th(> character)....

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PRINT AND INCOMM keywords
« Reply #8 on: June 20, 2011, 04:39:48 PM »
You read it nine times...
Email: support@triplc.com
Tel: 1-877-TRI-PLCS