PLC Communication Examples
 
These examples are provided to demonstrate certain functions using FACTS BASIC Modules. If you download and use any of these example programs, It is your responsibility to test and modify the program to meet your application requirements.
 
arrow  

Examples Main Page

     
arrow  

(1) Read Setpoint data from PLC V-Mem SP High Integer = V1401 (0-9999) SP High Fractional = V1400 (0-999) SP Low Integer = V1403 (0-9999) SP Low Fractional = V1402 (0-999) NOTE: Setpoint Data Must be in BCD format

(2) Read Serial Data from Ohaus Lab Scale Connected to Port 2 Scale Data Format is:
1 2-7 8 9-11 12 13 14
+/- ##.### sp units ? CR LF
Scale is configured to send data once per second

(3) Compare Scale Data with Setpoint Data
If >High Set V1410=1
If >Low and <High Set V1410=2
If <Low Set V1410=3

(4) Repeat from Step 2

rdscl_f2.abm (F2-CP128)

     
arrow  

Read 24 Analog Input Values starting at V1400 and 8 Analog Output Values starting at V1430 every 10 minutes and log them into BASIC Memory.

There will be a dedicated portion of memory for each 10 minute period containing an Hour/Minute Label and all Analog Input/Output values for that ten minute period.

abmlog.abm (F4-CP128-1)

     
arrow  

Read IEEE Floating Point value from a double word in a 450 CPU, assign to a numeric variable in the BASIC module, and display.

ieeeread.abm (F4-CP128-1)
ieeerdf2.abm (F2-CP128)

     
arrow  

Convert a numeric variable in the BASIC module to the IEEE Floating Point bit pattern and write to a double word in the CPU.

ieeewrit.abm (F4-CP128-1)
ieeewrf2.abm (F2-CP128)

     
arrow  

Read Slot Number that the CoPro is Installed In

05 CoProcessor
10 slot=PICK(DPORT~(022H),L)

205 CoProcessor
10 slot=shared~(024H)

405 CoProcessor
10 slot=DPORT~(0AH)

     
arrow  

Write a double BCD word with a 405 CoPro

10 X=99999999
20 XHI=INT(X/10000)
25 XLO=X=XHI
30 S405_VB(2001)=XHI : S405_VB(2000)=XLO

_or _

10 X=99999999
20 XHI=INT(X/10000)
25 XLO=X=XHI
30 DPORT(0,B)=XLO : DPORT(2,B)=XHI
35 BMOVE W,VH(2000),K(4)

     
arrow  

Read a double BCD word with a 405 CoPro

10 BMOVE R,VH(2000),K(4)
20 XHI=DPORT(0,B)
30 XLO=DPORT(2,B)
40 X=(XHI*10000)+XLO

_or_

10 XLO=S405_VB(2000) : XHI=S405_VB(2001)
20 X=(XHI*10000)+XLO

     
arrow  

Write a double BCD word with a 205 CoPro

10 X=99999999
20 XHI=INT(X/10000)
25 XLO=X-(XHI*10000)
30 S205_VB(2001)=XHI : S205_VB(2000)=XLO

_or _

10 X=99999999
20 XHI=INT(X/10000)
25 XLO=X-(XHI*10000)
30 SHARED(128,B)=XLO : SHARED(130,B)=XHI
35 BMOVE W,VH(2000),K(4)

     
arrow  

Read a double BCD word with a 205 CoPro

10 BMOVE R,VH(2000),K(4)
20 XHI=SHARED(0,B)
30 XLO=SHARED(2,B)
40 X=(XHI*10000)+XLO

_or_

10 XLO=S205_VB(2000) : XHI=S205_VB(2001)
20 X=(XHI*10000)+XLO

     
arrow  

Wait for an input with a 405 CoPro

10 DO : UNTIL S405_X(0)

Print status of an input with a 405 CoPro

10 IF S405_X(0) THEN PRINT1 "ON" ELSE PRINT1 "OFF"

     
arrow  

Wait for an input with a 205 CoPro

10 DO : UNTIL S205_X(0)

Print status of an input with a 205 CoPro

10 IF S205_X(0) THEN PRINT1 "ON" ELSE PRINT1 "OFF"

     
arrow  

Write a string to a block of V-memory in the PLC

F0-CP128 Example
1 REM Read a string and write the ASCII codes for the string
2 REM into a contiguous block of V-memory in a 05 or 06 CPU
10 STRING 2551,254 : REM Allocate String Space
20 $(0)="This is a Test"
30 FOR X=1 TO LEN($(0)) STEP 2
32 DPORT((X-1),H)=ASC($(0),X)
34 DPORT((X-1),L)=ASC($(0),X+1)
36 NEXT X
40 BMOVE W,VH(2000),K(LEN($(0)))

F2-CP128 Example
1 REM Read a string and write the ASCII codes for the string into a
2 REM contiguous block of V-memory in a 240, 250, 250-1, or 260 CPU
10 STRING 2551,254 : REM Allocate String Space
20 $(0)="This is a Test"
30 FOR X=1 TO LEN($(0)) STEP 2
32 SHARED(128+(X-1),H)=ASC($(0),X)
34 SHARED(128+(X-1),L)=ASC($(0),X+1)
36 NEXT X
40 BMOVE W,VH(2000),K(LEN($(0)))

F4-CP128-1 Example
1 REM Read a string and write the ASCII codes for the string
2 REM into a contiguous block of V-memory in a 430, 440, or 450 CPU
10 STRING 2551,254 : REM Allocate String Space
20 $(0)="This is a Test"
30 FOR X=1 TO LEN($(0)) STEP 2
32 DPORT((X-1),H)=ASC($(0),X)
34 DPORT((X-1),L)=ASC($(0),X+1)
36 NEXT X
40 BMOVE W,VH(2000),K(LEN($(0)))

     
arrow  

Read a Block of V-memory from a PLC that contains ASCII codes for a string

F0-CP128 and F4-CP128-1 Example
10 STRING 2551,254 : REM Allocate String Space
20 BMOVE R,VH(2100),K(16) : REM Read 16 bytes starting @ V2100
30 FOR X=0 TO 15 STEP 2 : REM Step thru DPORT
32 ASC($(0),X+1)=DPORT(X,H) : REM High Byte
34 ASC($(0),X+2)=DPORT(X,L) : REM Low Byte
36 NEXT X
40 PRINT1 $(0)

F2-CP128 Example
10 STRING 2551,254 : REM Allocate String Space
20 BMOVE R,VH(2100),K(16) : REM Read 16 bytes starting @ V2100
30 FOR X=0 TO 15 STEP 2 : REM Step thru SHARED
32 ASC($(0),X+1)=SHARED(X,H) : REM High Byte
34 ASC($(0),X+2)=SHARED(X,L) : REM Low Byte
36 NEXT X
40 PRINT1 $(0)

     
    Updated 1/21/2008