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