Author Topic: Serial Communication via Modem  (Read 10747 times)

peterh_DK

  • Newbie
  • Posts: 37
    • View Profile
Serial Communication via Modem
« on: June 13, 2006, 06:35:10 AM »
Hi There,
I?ve got at T100MD888 Plc connected to a  Fargo Maestro GSM Modem. Communication is one way ? From PLc through Modem-to-modem-to-PC-running-Trilogi server
The PLC dials a predefined modem number and  when connected it dumps some of the content of the DM
  • variable.


I use Tri-logis custom function to control the modem. This works fine ? most of the time ?.
As long as I only transfer from DM[1] to DM[200] is works every time, but If I send 1000 variables I often loose the line.

I am not sending it  all at once but I packets of 10 the i.e.
Y = 200
For I = 1 to y step 10
   put dm [I to I+10] into to A$ as one string
    Print#1 A$
Next

I hope this ensures that the serial buffer doesn?t  overflow but I am not sure, and I don?t notice if the lines breaks

The problem is I don?t  perform any quality control whatsoever. Just dial up ? send data ? clear ram.
So instead of writing from scratch I just  want to se if there is some code available already, using Incomm/ Input$ to check the transmission.
Any samples I could have a look at?

Best regards

Peter

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Serial Communication via Modem
« Reply #1 on: June 13, 2006, 12:57:03 PM »
Does the line break even without sending data? Just curious to see how good the connection is. Since you are sending data out from the PLC to the PC, the only possible buffer overflow is at the GSM modem since the PC line modem would push the data to the PC and PC has no problem receiving the data immediately into its buffer and write to the hard disk.

I assume you are using the TLServer's  File services to write data to a file on the hard disk? Why don't you open the file, write 200 data points and close the file, then check for the <OK> response from the TLServer, then open the file again and APPEND another 200 data points. Repeat this until all the data are written to the file. If you don't receive the <OK> response from the TLServer you can assume that the line has dropped, or you can send a test request to see if the connection has indeed been dropped say by requesting for an RTC data. If the line is dropped you may have to re do it.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

peterh_DK

  • Newbie
  • Posts: 37
    • View Profile
Re:Serial Communication via Modem
« Reply #2 on: June 14, 2006, 02:51:00 PM »
No I dont think the line breaks without data but it could happen.
The problem is I want to check for the returned "OK" after issuing the PRINT#1 command
If I issue the following after the connection is established
==================
Z$= "ABC"
print#1 z$
if strcmp(input$(1), "OK")= 0
   setlcd 1,1,"all ok"
else
   setlcd 2,1,"trouble  "
endif

======================
Then I only get "trouble" on the LCD

I guess this is because the PLC is reading INPUT$(1) before the "OK" answer has been returned

How do I continue reading INPUT$(1) until I get the "OK" , but "give up" and resend the PRINT#1 z$
after reasonable time assuming the the "OK" doesn't arrive becaus there was an error ?

Rgs
Peter

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Serial Communication via Modem
« Reply #3 on: June 14, 2006, 08:02:58 PM »
Note that XServer doesn't return an OK after you send it some command. It only happens when you use the <WRITE> or <APPEND> and then end the command with the closing tag </>.

INPUT$(1) is a non blocking function, i.e. it doesn't wait to receive a string before returning to the calling statement. If the serial buffer does not contain a complete string that is terminated with a CR, this command simply returns an empty string so that the PLC program can continue to run.

So you need to put a loop such as the following:

For I = 1 to 5000
   A$ = INPUT$(1)
   IF LEN(A$)=0 GOTO @10: ENDIF
NEXT

SETLCD 1,1,"trouble": RETURN

@10  SETLCD 1,1, "OK"




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

peterh_DK

  • Newbie
  • Posts: 37
    • View Profile
Re:Serial Communication via Modem
« Reply #4 on: June 20, 2006, 02:30:31 AM »
Thanks! I modified it a bit and got it working. I think I have isolated the "hanging up" problem to be connected with email.

If I send an email with 1000 datapoints taken from the DM variable, then it oftens hangs up halfway through. But he email is sent ust containing 5-800 datapoint.

It is not a serious problem, since I really only need to write the datapoint to a file on the PC and that works.

I'll keep you posted
« Last Edit: June 20, 2006, 02:36:12 AM by peterh_DK »