FSharp.Plc.Ads


Reading and writing of string variables

Sample based on Beckhoff Infosys - Sample 04

Task

A .Net application should read a string from the PLC and write a string to the PLC.

Description

The PLC contains the string MAIN.text.

PLC program

1: 
2: 
3: 
4: 
PROGRAM MAIN
VAR
 text : STRING[30] := 'hello';
END_VAR

F# program

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
#r "FSharp.Plc.Ads.dll"
//using IEC 61131-3 type aliases for convenience
#r "NuSoft.FSharp.IEC.DataTypes.dll"
open FSharp.Plc.Ads.Experimental
open System
let amsNetId = "192.168.68.132.1.1"
let amsPort = 801
//instantiate builder for specific TwinCAT instance
let plc = createClient amsNetId amsPort

let myInput = "hello PLC world!!!"

plc {
  writeAny "MAIN.text" myInput
}
|> function 
  | Choice1Of3 _ -> ()// handle success
  | Choice2Of3 errMsg -> ()// handle error
  | Choice3Of3 (adsCode,additionalInfo) -> ()// handle ADS error

plc {
  readAny "MAIN.text"
}
|> function 
  | Choice1Of3 (res: string) -> ()// handle success
  | Choice2Of3 errMsg -> ()// handle error
  | Choice3Of3 (adsCode,additionalInfo) -> ()// handle ADS error
namespace Microsoft.FSharp
Multiple items
type ExperimentalAttribute =
  inherit Attribute
  new : message:string -> ExperimentalAttribute
  member Message : string

Full name: Microsoft.FSharp.Core.ExperimentalAttribute

--------------------
new : message:string -> ExperimentalAttribute
namespace System
val amsNetId : string

Full name: Readwritestring.amsNetId
val amsPort : int

Full name: Readwritestring.amsPort
val plc : (obj -> Choice<string,obj,(obj * obj)>)

Full name: Readwritestring.plc
val myInput : string

Full name: Readwritestring.myInput
union case Choice.Choice1Of3: 'T1 -> Choice<'T1,'T2,'T3>
union case Choice.Choice2Of3: 'T2 -> Choice<'T1,'T2,'T3>
val errMsg : obj
union case Choice.Choice3Of3: 'T3 -> Choice<'T1,'T2,'T3>
val adsCode : obj
val additionalInfo : obj
val res : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
Fork me on GitHub