You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old September 5th, 2015, 09:45 AM   #1
milan12
Member
Netherlands

milan12 is offline
 
Join Date: Sep 2015
Location: eindhoven
Posts: 7
serial communication between Siemens PLC and Arduino

Hello everyone,

I want to make a serial communication using Siemens S7-1200 with CM 1241 (RS-232) and communicate with my Arduino.

Here is the setup of the communication, I have 2 temperature sensor and one Led connected to my Arduino and on the PLC side I have S7-1200 from Siemens and CM-1241. Arduino and my PLC are connected just by using Tx and Rx pin no handshake is done.

I am sending the temperature data from both the sensor to the PLC and on the PLC side i decide when to turn on the Led connected to my arduino depending on the different temperature values. I have assigning a ID to both the sensors before sending out the data. This is how the transmitted data from Arduino looks like $AOPT_TEMP1_20_TEMP2_21 <CR><LR>.

I have a filter on the PLC which only accepts the serial data starting with '$AOPT_', so for its good. I am receiving the serial data using RCV_PTP block and sending data using SEND_PTP. I can send signal from PLC to turn ON or OFF the led but what I want to do is evaluate the received temperature value from two temperature sensor TEMP1 & TEMP2 and then decide to control the Led. For instance if (TEMP1>TEMP2 ) then turn ON the Led else turn OFF.

I am able to receive the data on the PLC from Arduino but now I don't know how to proceed with comparing the received information. How do i extract the only required data from the received buffer? Any suggestions will be highly appreciated.

Thanks in advance
  Reply With Quote
Old September 5th, 2015, 05:21 PM   #2
boneless
Lifetime Supporting Member + Moderator
United States

boneless is offline
 
Join Date: Feb 2008
Location: OKC
Posts: 1,459
Hi Milan and welcome!

Wouldn't you know how to deconstruct whatever you are getting since you are sending it yourself?

I can't really help you here, but am interested so please keep us informed .
  Reply With Quote
Old September 5th, 2015, 05:41 PM   #3
milan12
Member
Netherlands

milan12 is offline
 
Join Date: Sep 2015
Location: eindhoven
Posts: 7
Quote:
Originally Posted by boneless View Post
Hi Milan and welcome!

Wouldn't you know how to deconstruct whatever you are getting since you are sending it yourself?

I can't really help you here, but am interested so please keep us informed .
Hello boneless, Thank you very much

Yes true, since I am sending the data from arduino i know whats going in the PLC and even change it if necessary but the problem is that I am receiving each character in my PLC's buffer (RCV_PTP) and from there I don't know how to proceed further. Since I am new to PLC i do not know how to handle those received characters and how to filter out the required data in order to take a proper action, in my case depending on the temperature value Led should be ON or OFF.
  Reply With Quote
Old September 6th, 2015, 01:21 AM   #4
(8{)} ( .)
Lifetime Supporting Member
Israel

(8{)} ( .) is offline
 
(8{)} ( .)'s Avatar
 
Join Date: Apr 2004
Location: Israel
Posts: 590
Use Modbus. There are several free Arduino/Modbus projects out there. Then use the Siemens as a Modbus master.

Good luck,

Yosi
  Reply With Quote
Old September 6th, 2015, 03:50 PM   #5
milan12
Member
Netherlands

milan12 is offline
 
Join Date: Sep 2015
Location: eindhoven
Posts: 7
Quote:
Originally Posted by (8{)} ( .) View Post
Use Modbus. There are several free Arduino/Modbus projects out there. Then use the Siemens as a Modbus master.

Good luck,

Yosi
Thanks Yosi for the suggestion but I cannot go to Modbus, Currently I am just using a Arduino to test my PLC program but in the reality there will be other system sending out the serial data. I am just doing the PLC part, in the mean time I am just trying to simulate the serial data to see weather the PLC work as it should.

Any idea on how I can solve my problem with the current system?
  Reply With Quote
Old September 7th, 2015, 12:41 AM   #6
(8{)} ( .)
Lifetime Supporting Member
Israel

(8{)} ( .) is offline
 
(8{)} ( .)'s Avatar
 
Join Date: Apr 2004
Location: Israel
Posts: 590
The only real question I've got is whether the data is always located in the same position or if you have to calculate the position.

The string is '$AOPT_TEMP1_20_TEMP2_21 <CR><LR>'

If the temperatures are always 2 characters long and at the same position then you would simply extract them using FIND to find the strings "TEMP1_" and "TEMP2_" in the input string and then using MID to extract the characters in question. You would then feed the result string into STRING_TO_INT to convert the results to an integer.

If the temperatures are of varying character lengths then you'd use FIND to find those same strings but use MID to extract one character at a time for as long as those characters are numeric and then use the STRING_TO_INT to convert the extracted strings.

Mind you this is a very simplified explanation. I would do some validation on the input string to test for length and to insure that both the TEMPx strings appear in it and, of course I'd validate the strings before conversion to insure that they consist of only numeric characters but you get the point.

Good luck,

Yosi
  Reply With Quote
Old September 8th, 2015, 10:54 AM   #7
milan12
Member
Netherlands

milan12 is offline
 
Join Date: Sep 2015
Location: eindhoven
Posts: 7
Quote:
Originally Posted by (8{)} ( .) View Post
The only real question I've got is whether the data is always located in the same position or if you have to calculate the position.

The string is '$AOPT_TEMP1_20_TEMP2_21 <CR><LR>'

If the temperatures are always 2 characters long and at the same position then you would simply extract them using FIND to find the strings "TEMP1_" and "TEMP2_" in the input string and then using MID to extract the characters in question. You would then feed the result string into STRING_TO_INT to convert the results to an integer.

If the temperatures are of varying character lengths then you'd use FIND to find those same strings but use MID to extract one character at a time for as long as those characters are numeric and then use the STRING_TO_INT to convert the extracted strings.

Mind you this is a very simplified explanation. I would do some validation on the input string to test for length and to insure that both the TEMPx strings appear in it and, of course I'd validate the strings before conversion to insure that they consist of only numeric characters but you get the point.

Good luck,

Yosi
Hello Yosi,

Thank you for your answer. I will try to do this but I have one question before I use the FIND block dont I have to convert the characters received in my buffer to string? Can I directly use FIND in the received buffer?
  Reply With Quote
Old September 9th, 2015, 01:47 AM   #8
(8{)} ( .)
Lifetime Supporting Member
Israel

(8{)} ( .) is offline
 
(8{)} ( .)'s Avatar
 
Join Date: Apr 2004
Location: Israel
Posts: 590
I would suspect the receive buffer to be a string. If the data is byte rather than string you should use memcopy or the equivalent. Sorry I can't be of more help. The software isn't in front of me...

Good Luck,

Yosi
  Reply With Quote
Old September 10th, 2015, 04:27 AM   #9
milan12
Member
Netherlands

milan12 is offline
 
Join Date: Sep 2015
Location: eindhoven
Posts: 7
Quote:
Originally Posted by (8{)} ( .) View Post
I would suspect the receive buffer to be a string. If the data is byte rather than string you should use memcopy or the equivalent. Sorry I can't be of more help. The software isn't in front of me...

Good Luck,

Yosi
Thanks for the suggestion Yosi. I managed to got this working. I can now extract the values from my received buffer. This is what I did,
- Created a new static data buffer in the project and filled (Fill_BLK) it with a empty characters
- Moved (MOVE_BLK) my received characters from RCV_PTP to my static buffer
- converted (Char to string) the characters in my static buffer to string
- Used FIND block to find the string from the string (I used TEMP1_) which was created in the above step. This gave me the start position (from the above string it gave me 7) of the string.
- I then used MID function to abstract the value of the TEMP1_, giving the start position as 13 and string length as 2.
- finally then I converted the abstracted value 20 from string to INT, is it necessary? this will result the same value, so is this really important?

Now, I am wondering how do I abstract the temperature value if the length is unknown? For temperature it will not be greater than 2 but if other sensors are connected and the output can vary from length 1 to 5 then I do I do this? Any suggestion for this?
  Reply With Quote
Old September 10th, 2015, 01:18 PM   #10
danatomega
Lifetime Supporting Member
United States

danatomega is offline
 
Join Date: Mar 2011
Location: Dayton OH
Posts: 789
I would think that you could just go ahead and use find on all 5 temperatures - looking for TEMP1_ then TEMP2_ all the way to TEMP5_ - if it returns 0 then it didn't find the substring anywhere and you don't try and process the temperature reading.
  Reply With Quote
Old September 11th, 2015, 03:54 AM   #11
milan12
Member
Netherlands

milan12 is offline
 
Join Date: Sep 2015
Location: eindhoven
Posts: 7
Quote:
Originally Posted by danatomega View Post
I would think that you could just go ahead and use find on all 5 temperatures - looking for TEMP1_ then TEMP2_ all the way to TEMP5_ - if it returns 0 then it didn't find the substring anywhere and you don't try and process the temperature reading.
danatomega, thanks for your reply I am able to find the sub-string using FIND block but the problem is what if my temperature returns more or less than 2 characters? Value of the temperature is not know, so in this case I just cannot use MID block to extract the data. I have already checked this and its fails to extract the correct value when the temperatures returns 3 characters.

Any suggestions how I can solve this?
  Reply With Quote
Old September 11th, 2015, 09:07 AM   #12
danatomega
Lifetime Supporting Member
United States

danatomega is offline
 
Join Date: Mar 2011
Location: Dayton OH
Posts: 789
I don't know all the capabilities of the siemens cpu but it looks as though it's at least similar to computer programming languages.

So, the method I would use is to use FIND on your TEMP1_ in addition to FIND on your TEMP2_ ... the difference (subtracting the 6 characters for the 'TEMPx_' substring) equals the length of the actual temperature reading. You may need to tweak this a bit to get the correct results.

Do this for each TEMPx_ that you're looking for excepting at the last one, where the length of your temperature reading would be roughly the length of the original string minus the location of your last FIND result.
  Reply With Quote
Old September 11th, 2015, 10:41 AM   #13
milan12
Member
Netherlands

milan12 is offline
 
Join Date: Sep 2015
Location: eindhoven
Posts: 7
Quote:
Originally Posted by danatomega View Post
I don't know all the capabilities of the siemens cpu but it looks as though it's at least similar to computer programming languages.

So, the method I would use is to use FIND on your TEMP1_ in addition to FIND on your TEMP2_ ... the difference (subtracting the 6 characters for the 'TEMPx_' substring) equals the length of the actual temperature reading. You may need to tweak this a bit to get the correct results.

Do this for each TEMPx_ that you're looking for excepting at the last one, where the length of your temperature reading would be roughly the length of the original string minus the location of your last FIND result.
danatomega, cool now it works fine, its calculates itself thanks for the suggestion.
  Reply With Quote
Old September 11th, 2015, 10:54 AM   #14
danatomega
Lifetime Supporting Member
United States

danatomega is offline
 
Join Date: Mar 2011
Location: Dayton OH
Posts: 789
Glad it works for you and you're welcome!
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Mitsubishi FX and Arduino bgmaxy LIVE PLC Questions And Answers 12 February 3rd, 2017 09:46 AM
connecting s7-1200 plc to Arduino by Modbus RTU smsebnaa LIVE PLC Questions And Answers 18 January 19th, 2016 10:33 AM
Arduino to ControlLogix Ian762 LIVE PLC Questions And Answers 2 June 19th, 2015 02:08 PM
PLC Skills Demo Pendragon8000 LIVE PLC Questions And Answers 10 December 9th, 2014 06:15 AM


All times are GMT -5. The time now is 06:30 AM.


.