Problems with Siemens CP340 RS232C communication

Borte

Member
Join Date
Feb 2004
Location
Norway
Posts
238
Hello!

Have anyone in here used the Siemens CP340 RS232C communication processor (6ES7 340-1AH01-0AE0)?
I'm trying to figure out how to use this card to send ASCII codes (or string data) to an external unit that only accepts straight ASCII.

The card came with some examples but none of them have straight ASCII communication, the examples are for printer communication (special setup of the card) and send / receive (step7 db's). None of this suits my needs.

Hope anyone can help me with this; an example would be greatly appreciated.

Regards
Borte
 
I've done a ton of programming with the CP340 and 341 modules, and can help you if you provide a little more info. What type of device are you talking to? How much data are you trying to send, and how often?
 
Hello!

I'm talking to a Telesis Pin Writer witch only accepts straigh ASCII codes at the input.

The data I'll be sending will be in the range of 10 - 20 Bytes (10 - 20 characters).

And it'll be sent each 10 sec so the time is not an issue here I think.

So far I have just set up a test system with my computer to see if I vere able to send some data, but still no luck. I've been looking at the examples that Siemens provide but they are not easy to understand.

Hope this is all the information you need.

Regards
Borte
 
Ok, the first thing you will want to do is copy the required function block from the Simatic CP PtP library. Then, create an associated Instance Data Block to go with this FB. You would create an IDB for each printer that you are talking to. I’m assuming you know how to do this, but if not, I’ll go into further detail.

To send data, you will need to determine the length of the data in bytes, plus the starting byte of the data. In the code example I am giving you, I have used absolute addresses and a fixed data length, but in reality you will need to determine these dynamically based on the actual data. I have used “512” as the CP340 module address, and I set the “Send Request” every ten seconds. I always use symbolic programming and pass a udt into my Printer Control function, but there are a dozen other ways to do it depending on your programming style. Or, if you only have one printer and don’t need multiple instances, you can continue to use absolute values.

I haven’t tested this, so maybe I made a typing mistake, but this should get you started. If you need help in determining things like the data length for your live conditions, then let us know.

By the way, if it doesn't seem to communicate with your pin writer, then try sending the data to your laptop instead via HyperTerminal. That is probably the easiest way to test hardware like this.

Here's the code:

//******************************
//Sample Data: "THIS IS A TEST!"
//******************************
L 'T'
T "Test CP340".Printer.AsciiCharacter[1]
L 'H'
T "Test CP340".Printer.AsciiCharacter[2]
L 'I'
T "Test CP340".Printer.AsciiCharacter[3]
L 'S'
T "Test CP340".Printer.AsciiCharacter[4]
L ' '
T "Test CP340".Printer.AsciiCharacter[5]
L 'I'
T "Test CP340".Printer.AsciiCharacter[6]
L 'S'
T "Test CP340".Printer.AsciiCharacter[7]
L ' '
T "Test CP340".Printer.AsciiCharacter[8]
L 'A'
T "Test CP340".Printer.AsciiCharacter[9]
L ' '
T "Test CP340".Printer.AsciiCharacter[10]
L 'T'
T "Test CP340".Printer.AsciiCharacter[11]
L 'E'
T "Test CP340".Printer.AsciiCharacter[12]
L 'S'
T "Test CP340".Printer.AsciiCharacter[13]
L 'T'
T "Test CP340".Printer.AsciiCharacter[14]
L '!'
T "Test CP340".Printer.AsciiCharacter[15]
//******************************
//Load Parameters
//******************************
L 0
T "Test CP340".Printer.CP340Parameters.DataByteNumber
L 15
T "Test CP340".Printer.CP340Parameters.LengthOfData
L DBNO
T "Test CP340".Printer.CP340Parameters.SourceDataDataBlock
//******************************
//Transfer Module Address
//******************************
L 512
T "Test CP340".Printer.CP340Parameters.ModuleAddress
//******************************
//Send Data every 10s
//******************************
AN "Test CP340".Printer.CP340Parameters.Request
L S5T#10S
SD T 300
A T 300
S "Test CP340".Printer.CP340Parameters.Request
//******************************
//Send Data
//******************************
CALL "P_SEND" , "CP340"
REQ :="Test CP340".Printer.CP340Parameters.Request
R :="Test CP340".Printer.CP340Parameters.Reset
LADDR :="Test CP340".Printer.CP340Parameters.ModuleAddress
DB_NO :="Test CP340".Printer.CP340Parameters.SourceDataDataBlock
DBB_NO:="Test CP340".Printer.CP340Parameters.DataByteNumber
LEN :="Test CP340".Printer.CP340Parameters.LengthOfData
DONE :="Test CP340".Printer.CP340Parameters.SendComplete
ERROR :="Test CP340".Printer.CP340Parameters.SendError
STATUS:="Test CP340".Printer.CP340Parameters.StatusWord

A "Test CP340".Printer.CP340Parameters.SendComplete
R "Test CP340".Printer.CP340Parameters.Request

Or, here's the same code with absolute value representation:

//******************************
//Sample Data: "THIS IS A TEST!"
//******************************
L 'T'
T DB200.DBB 0
L 'H'
T DB200.DBB 1
L 'I'
T DB200.DBB 2
L 'S'
T DB200.DBB 3
L ' '
T DB200.DBB 4
L 'I'
T DB200.DBB 5
L 'S'
T DB200.DBB 6
L ' '
T DB200.DBB 7
L 'A'
T DB200.DBB 8
L ' '
T DB200.DBB 9
L 'T'
T DB200.DBB 10
L 'E'
T DB200.DBB 11
L 'S'
T DB200.DBB 12
L 'T'
T DB200.DBB 13
L '!'
T DB200.DBB 14
//******************************
//Load Parameters
//******************************
L 0
T DB200.DBW 206
L 15
T DB200.DBW 208
L DBNO
T DB200.DBW 204
//******************************
//Transfer Module Address
//******************************
L 512
T DB200.DBW 202
//******************************
//Send Data every 10s
//******************************
AN DB200.DBX 200.0
L S5T#10S
SD T 300
A T 300
S DB200.DBX 200.0
//******************************
//Send Data
//******************************
CALL FB 300 , DB300
REQ :=DB200.DBX200.0
R :=DB200.DBX200.1
LADDR :=DB200.DBW202
DB_NO :=DB200.DBW204
DBB_NO:=DB200.DBW206
LEN :=DB200.DBW208
DONE :=DB200.DBX200.2
ERROR :=DB200.DBX200.3
STATUS:=DB200.DBW210

A DB200.DBX 200.2
R DB200.DBX 200.0
 
Last edited:
Woohhhaaa This is a long time ago...

I have finally got around to test this, but I'm still running into problems... Hopefully someone in here can help!

I'm using the test program that S7Guy created for me (thanks for the program S7Guy) but it seems like my computer or the plc has a problem when I'm sending more than 4 characters at the same time. If I'm using 15 as in the example then all my computer is receiving is the last character (!). I tried playing with character delay and transmission speeds without any luck.

Anyone has any ideas on this?

Regards
Borte
 
I worked it out, it seemd to a configuration problem in the CP card.

I had to set the parameters correct, just a user problem! :sick:

Regards
Borte
 
CP340 Print String DB ISSUE!!!

Hello everybody,
I've an issue printing data from a DB (on a CPU315) to a Printer via CP340 (RS232).
Module configuration and test exercise from Simens Manual seems don't write properly.
The string should be:
'At %Z the value %N the limit of %i liters'
where:
%Z: Is the conversion instruction for the data type TIME_OF_DAY
%i: Is the conversion instruction for the data type INT, WORD, DINT, DWORD
%N: Is the conversion instruction for outputting a message configured in HW Config

So the printed message should be:
---------------------------------------------------------
At xx:xx:xx.xxx the value reached the limit of 1500 liters.
---------------------------------------------------------

But the printed message is:
---------------------------------------------------------
had

172842 h vau ahd h m ****** s
---------------------------------------------------------

Extra information:
If I connect the PC directly to printer via serial and use Hyperterminal, I can write properly sentences, numbers, chars...

Do you have any hint maybe about the CP340 configuration parameters?

THANKS,
Ema
 
My guess is that there is nothing wrong with the CP340 configuration parameters. After all, you are getting a message successfully delivered from the module to the printer, so things like baud rate etc must be OK.

What does seem to be screwed up is the content of the message. I've had a look at the Siemens CP340 printer driver 'Getting Started' guide. Is this the example you're referring to? In DB10 there is a STRING variable which holds the structure of the output message. Are you sure you have observed the correct structure of a STRING data-type? Remember that the 1st byte holds the overall length of the STRING, the 2nd byte defines how many valid characters are in the STRING (must be less than or equal to 1st byte) and the data only begins at the 3rd byte. If you get these wrong you may find that any operation using the STRING will incorrectly interpret where the data starts, and therefore what each subsequent character is intended to be. I would start by checking this and any other STRINGs to make sure they're properly formatted.

regards

Ken
 
I've done a ton of programming with the CP340 and 341 modules, and can help you if you provide a little more info. What type of device are you talking to? How much data are you trying to send, and how often?

Hi S7Guy,
Please have a look here and give me some guide http://www.plctalk.net/qanda/showthread.php?t=29358&page=3
(Sorry but I am a newbie in Step7, STL is difficult for me...I try to read your code but it seems so big project to me..
Could you give me some guide to write a program which function as belows (I think it simple with you but for me it difficult because the first time I do thiso_O, please guide me in LAD):
- Hardware: CPU 314c-2DP + CP340 connected to 05 indicators (can be addressed) through RS485, 2wire, ascii 8data bits+1stop bit.
- Step7 program:
+ Send code <STX>PA<CR> (eg: ^BP!^M for addres 1) to Poll for data from indicators
+ Receive data return from indicators.
(I can do the setting for HW already)

Many thanks for your attention!🍻)
 
Urgent help please!

I've done a ton of programming with the CP340 and 341 modules, and can help you if you provide a little more info. What type of device are you talking to? How much data are you trying to send, and how often?

Hi S7Guy,
I have CPU314-2DP with CP340(rs485) on my desk.
I have connected cpu-cp above to a display via 2wired rs485, the command and data frame of display as in the attatchment, I done all settings for both partners (I already do parameter for ASCII data exchange in cp340). I write user program to communication. However, in P_receive the STATUS shown 811 in HEX. I check CP340 manual and found desciption for this error but cannot solve it.
I jugde that you are expert on this matter so please share me a little of your time to look through the attatchment and give me some guide...
This very urgent with me...Thank you very must for your attention!

cont mode.jpg poll mode.jpg config.jpg
 
Status value 811

Hello all,

I to am getting the status value 811, which when converted to binary does not match with any of the error codes.

I am using a SI module ASCII 32 bit reading from an RS232C input. The Module Rx light is flashing but no data is populating the data block assigned in the function block.

Does anyone have any ideas as to where my problem may lie.

Many thanks

Richard
 
CP-340 RS 232C ptp module printing problem

Hi all,

I hope anyone here can help me with my problem regarding on CP-340 RS 232C ptp module.

This is my first time working with printing module, Our client has an existing CP-340 module communicating with epson Lx-310. They want to replace their printer with the same printer but the old epson Lx-310 was obsolete already so they bought the newer version of Lx-310. I don't have problem communicating the two devices because I can able to print the problem is the printer printing unknown characters (Ç). Supposed to be the printer will print temperature data every 5 minutes. But when I install again the old printer the printing was working properly. I don't know what is the problem because the only thing I change in the existing program is the communication parameters.

Thank you.
 
Hi all,

I hope anyone here can help me with my problem regarding on CP-340 RS 232C ptp module.

This is my first time working with printing module, Our client has an existing CP-340 module communicating with epson Lx-310. They want to replace their printer with the same printer but the old epson Lx-310 was obsolete already so they bought the newer version of Lx-310. I don't have problem communicating the two devices because I can able to print the problem is the printer printing unknown characters (Ç). Supposed to be the printer will print temperature data every 5 minutes. But when I install again the old printer the printing was working properly. I don't know what is the problem because the only thing I change in the existing program is the communication parameters.

Thank you.


You should open new thread for this.


It can be wrong character set selected on printer side or com speed, parity.


If you have some odd characters, then check character coding selected on old and new
 

Similar Topics

I'm using a cp340 to send a print string to an Intermec printer. My test plc is a CPU318-2P I have at my desk. Later after I get this working I'll...
Replies
0
Views
1,770
Hello. I appreciate the insights here and the willingness to share. I've got a lot of Rockwell experience, but my Siemens experience is...
Replies
6
Views
130
I currently have 4 siemens mp277 10 inch touch screens I deal with. Lately 2 of them have been giving erratic touch screen results. To specify...
Replies
7
Views
1,754
Hello , Can you please have a look at the code in the attached file and say why it isn't working? The piece of code is ' copy@paste' PID from...
Replies
2
Views
1,256
Hi all I have a cpu314c with a 5ai/2ao unit, I can’t get any reading within my program. I have tried with the simulator and the program works...
Replies
8
Views
2,309
Back
Top Bottom