Anda di halaman 1dari 4

1

-------- Serial I/O Example for RX3i CMM --------

Please also review the CMM hardware configuration


Adjust serial communication parameters as needed

Please note: The Serial I/O protocol can generally read or write any byte string
(i.e. Not necessarily only ASCII character strings)
2
For readability, this example uses Port 1 on the CMM and the status- and control references are mapped to %I1 and %Q1
3

4
Call Read Block
5 #ALW_ON CALL
SIO_Re...

%S00007
6
Call Write Block
7 #ALW_ON CALL
SIO_Wr...

%S00007

8
Extra Commands and Status Bits
The below commands are not used in the Read- and Write blocks above, but may be useful for troubleshooting or recovery

More detail about status- and control bit locations and meaning available in GFK-2460 Chapter 4
9
Reset Port 1 on CMM + Clear Application Input Buffer
10 Reset_Port BLK CLR Q00067
WORD

%Q00067
32 Reset_Port
AI0001 IN R
%AI0001
11
Flush Port 1 Input Buffer (on CMM)
12 Flush_Port Q00083

%Q00083
Flush_Port
R

13
Port 1 is ready (OK)
May be used as permissive
14 I00129 Port_Ready

%I00129
15
Port 1 Receive Error

In this implementation, this bit may be almost always on because the read command is issued continuously and many of them time out
(Actually only off, directly after byte string was successfully received)
16 I00065 Read_Error

%I00065
17
Port 1 Transmit Error
18 I00065 Write_Error

%I00065

CMM Serial IO: Target1: _MAIN 12/7/2015-2:07:36 PM Page 1


1
Read Example for Port 1

Port 1 Control (Command) Start: %Q1 (128 Bit)


Port 1 Status Start: %I1 (224 Bit)

Port 1 Read Data Start: %AI1

Reading byte strings with delimiter = <CR> (see HWC)


2
Continuously read incoming <CR> terminated byte strings
Note: The port is setup in HWC to read delimited strings
Other options like e.g. read variable byte count are configurable as well
(The application then writes the byte count (Word) to %Q97)
3
Read Request pending (Read Command Bit != Read Status Bit)
Read status bit 'echoes' read command bit when finished
4 CmdRead ReadFinished SKIP
JUMPN
%Q00001 %I00001
CmdRead ReadFinish...

%Q00001 %I00001
5
Read Request finished (Read Command Bit = Read Status Bit)
6
Read Requests may also finish through error, timeout or missing data or delimiter, i.e. no (or partial) data received
- Check number of bytes last read. If bytes read > 0, a string (with delimiter) was read and may be copied to the application
7
Copy string read to application memory (AppReadBuffer)
8 ARRAY
MOVE
BYTE

1024
AI0001 SR DS AppReadBu...
%AI0001

1 SNX

1 DNX

BytesRead N
%I00177
9
Toggle read command bit to start next Read Request
10 CmdRead CmdRead

%Q00001 %Q00001

11
SKIP

12

CMM Serial IO: Target1: SIO_Read 12/7/2015-2:08:05 PM Page 1


1
Write Example for Port 1

Port 1 Control (Command) Start: %Q1 (128 Bit)


Port 1 Status Start: %I1 (224 Bit)

Port 1 Write Data Start: %AQ1

Writing dynamic length byte strings


2
Coninuously write ASCII Strings
The port is setup in HWC to write a variable length string
Other options like e.g. writing a static length are configurable as well
3
Generate an ASCII String 'Hello World'!
4 #FST_SCN DATA
INIT
ASCII
%S00001
12
Q AppWriteBu...

5
No Write Request pending (Write Command Bit = Write Status Bit)
Write status bit 'echoes' write command bit when finished

--> Port ready to accept next Write Request


6 CmdWrite WriteFinished PortReady

%Q00002 %I00002
CmdWrite WriteFinish...

%Q00002 %I00002
7
Write ASCII String every 2 seconds when port is ready
8 Tick_Write PortReady TMR Tick_Write
THOUS

TmrWrite
2000 PV CV

9 Tick_Write SKIP
JUMPN

10
Copy string to write from application memory (AppWriteBuffer)
Adjust string length to write
11 ARRAY MOVE
MOVE INT
BYTE

1024 1
AppWriteBu... SR DS AQ0001 12 IN Q BytesToWrite
%AQ0001 %Q00113

1 SNX

1 DNX

12 N

12
Toggle write command bit to start next Write Request

CMM Serial IO: Target1: SIO_Write 12/7/2015-2:08:24 PM Page 1


13 CmdWrite CmdWrite

%Q00002 %Q00002

14
SKIP

15

CMM Serial IO: Target1: SIO_Write 12/7/2015-2:08:24 PM Page 2

Anda mungkin juga menyukai