Serial Communication Example Programs
 
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  

Read string data from one serial device, parse numeric data from the string, and write integer data to V2000 in BCD Word format.

Serial Data Format: +####.##CRLF

f0comex1.abm (F0-CP128)
f2comex1.abm (F2-CP128)
f4comex1.abm (F4-CP128-1)

     
arrow  

Read string data from one serial device, parse numeric data from the string, and write integer data to V2000/V2001 in BCD Double Word format.

Serial Data Format: +########CRLF

f0comex2.abm (F0-CP128)
f2comex2.abm (F2-CP128)
f4comex2.abm (F4-CP128-1)

     
arrow  

Read string data from two serial devices, parse numeric data from the string, and write integer data for device 1 to V2000/2001 in BCD Double Word format and device 2 to V2002/2003 in BCD Double Word format..

Serial Data Format: +########CRLF

f0comex3.abm (F0-CP128)
f2comex3.abm (F2-CP128)

     
arrow  

Read string data from a serial device, parse numeric data from the string, and write integer data to V2000 in BCD format.

Serial Data Format: ##.#CRLF

f0comex4.abm (F0-CP128)
f2comex4.abm (F2-CP128)

     
arrow  

Read data from a bar code reader, parse data from the string and write the numeric and ASCII code data to the PLC.

Serial Data Format:
PPPPPSLLPJJJUUUUUUU CR
PPPPP = Product Number
S= Shift Number
LL = Line Number
P = Plant Number
JJJ = Julian Day
UUUUUUU = Undefined Characters
Carriage Return Terminated String

f0comex5.abm (F0-CP128)
f2comex5.abm (F2-CP128)

     
arrow  

Read a string from a serial device containing a 10 digit integer and write to 3 contigous V-memory locations.

Serial Data Format:##########CRLF

f0comex6.abm (F0-CP128)
f2comex6.abm (F2-CP128)

     
arrow  

Request string data from a serial device, parse numeric data from the string, and write integer data to V2000 in BCD format.

Serial Data Format:####.##gCRLF

f0comex7.abm (F0-CP128)
f2comex7.abm (F2-CP128)

     
arrow  

Read string data from one serial device, parse numeric data from the string, and write integer data to V2000/V2001 in BCD Double Word format.

Serial Data Format:
STX / +or- / ####### / Units / CRLF

f4comex3.abm (F4-CP128-1)

     
arrow  

Read string data from one serial device, parse numeric data from the string, and write integer data to V2000/V2001 in BCD Double Word format.

Serial Data Format:
STX / +or- / ####### / Units / CRLF

f4comex3.abm (F4-CP128-1)

     
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 Power Meter information from a 3300 ACM connected via 2-wire RS485 using Modbus Function Code 3.

3300acm.abm (F4-CP128-1)

     
arrow  

Simple Optomux Master
- Use command M to Read 16 Discrete Inputs from address 0 and put in C0-C17
- Use command L to Read 4 Analog Inputs from address 1 and put in V1400-V1403
- Use command J to Write 16 Discrete Outputs to address 2 from C20-C37

optomast.abm (F4-CP128-1)

     
arrow  

Simple Modbus RTU Master
- Use FC 2 to Read RTU Input Status and put in C0
- Use FC 4 to Read (3) RTU Analog Inputs and put in V1400,1401,1402
- Use FC 5 to Write status of C1 to RTU Output

modmast.abm (F4-CP128-1)
modmasf2.abm (F2-CP128)

This example adds FC16 to modmasf2.abm example
fc16wf2.abm (F2-CP128)

     
arrow  

Print the decimal value of the ASCII code of each character of $(0) (read as string 0).

100 FOR X=1 TO LEN($(0))
105 PRINT1 ASC($(0),X),SPC(1),
110 NEXT X
115 PRINT1

To print the hex value of the ASCII code change line 105 to:

105 PRINT1 HEX$(ASC($(0),X),1), SPC(1),

     
arrow  

Copy the ASCII code of each character of $(0) (read as string 0) to a numeric array element.

10 DIM CHAR(20)
20 $(0)="Test String"
30 FOR X=1 TO LEN($(0))
35 CHAR(X)=ASC($(0),X)
40 NEXT X

     
arrow  

Read a string from a device and write the ASCII codes for that string to a block of V-memory in the PLC.

f0_rdstr_writeplc.abm (F0-CP128)
f2_rdstr_writeplc.abm (F2-CP128)

     
    Updated 1/21/2008