The Easiest Way to Save and Share Code Snippets on the web

#FSharp

ocaml | by: Cynede

posted: Dec, 8th 2011 | jump to bottom

  1. module FBOI (* Top level library *)
  2.  
  3. open System
  4. open System.Threading
  5. open System.Collections.ObjectModel
  6.  
  7. open Work
  8. //------------------------------------------------------------------------------------------------------------//
  9. module Lambda =
  10. //------------------------------------------------------------------------------------------------------------//
  11. let mutable internal workbase : list<Dev> = []
  12. //------------------------------------------------------------------------------------------------------------//
  13. let internal (<%=) W Z clear async N v =
  14. let X thriller =
  15. (W : Dev).ListPos .Clear()
  16. if clear then W.Out .Clear()
  17. thriller()
  18. if async then
  19. W.Thread <- new Thread( new ThreadStart( fun () -> W.Run N v) )
  20. W.Thread.Start()
  21. else W.Run N v
  22. X <| fun () -> Array.iter(fun z -> W.ListPos.Add <| z) Z
  23. //------------------------------------------------------------------------------------------------------------//
  24. let internal get W = if workbase.Length <> 0 then
  25. workbase |> List.findIndex(fun w -> w.ID = W)
  26. else -1
  27. let internal (=%>) W thriller = (* Dev -> unit *)
  28. let id = get W
  29. if id <> -1 then workbase.[id] |> thriller
  30. let internal (=%=) W thriller = (* Dev -> 'a *)
  31. let id = get W
  32. if id <> -1 then Some ( workbase.[id] |> thriller )
  33. else None
  34. //------------------------------------------------------------------------------------------------------------//
  35. let Reset() = workbase <- []
  36. //------------------------------------------------------------------------------------------------------------//
  37. let Start id ip port user password =
  38. let work = new Dev(ip, port, user, password)
  39. work <%= [| Byteworks.Authorize(user,password) |] (*TODO: Run it empty*)
  40. <| true (*clear*)
  41. <| false (*async*)
  42. <| id (*workid*)
  43. <| -3 (*v*)
  44. work.ID <- id
  45. workbase <- work :: workbase
  46. true
  47. //------------------------------------------------------------------------------------------------------------//
  48. let GetArchive W dev v dt1 dt2 numIT numArh = (* Get Archive Data *)
  49. W =%> fun w ->
  50. w.Out.Clear()
  51. w.Start()
  52. while (not w.Stop) do
  53. w.Dev <- dev
  54. w <%= [|( Byteworks.GetArchive dev dt1 dt2 numIT numArh Nisemono.next )|]
  55. <| true (*clear*)
  56. <| false (*async*)
  57. <| W (*workid*)
  58. <| v (*v*)
  59. let GetCurrent W dev numIT = (* Get Instant Data *)
  60. W =%> fun w ->
  61. w.Out.Clear()
  62. w.Dev <- dev
  63. w <%= [|( Byteworks.GetCurrent dev numIT)|]
  64. <| true (*clear*)
  65. <| false (*async*)
  66. <| W (*workid*)
  67. <| -1 (*v*)
  68. //------------------------------------------------------------------------------------------------------------//
  69. let TimeSync W dt = (* BOI Time Synchronization *)
  70. W =%> fun w ->
  71. w.Out.Clear()
  72. w <%= [| Byteworks.SyncTime(dt) |]
  73. <| false (*clear*)
  74. <| true (*async*)
  75. <| W (*workid*)
  76. <| -2 (*v*)
  77. let DoSync W = TimeSync W DateTime.Now
  78. //------------------------------------------------------------------------------------------------------------//
  79. let Read W = match W =%= fun w -> w.Out with
  80. | Some(t) -> t
  81. | None -> new Collection<string>()
  82. let Check W = match W =%= fun w -> w.Error with
  83. | Some(t) -> t
  84. | None -> true
  85. let ReadDevices W = match W =%= fun w -> w.Devices with
  86. | Some(t) -> t
  87. | None -> new Collection<BModel.Device>()
  88. let GetBytes W = match W =%= fun w -> w.Recived with
  89. | Some(t) -> t
  90. | None -> [||]
  91.  
  92. let CanRead W dev v = match W =%= fun w -> w.GetCanRead dev v with
  93. | Some(t) -> t
  94. | None -> false
  95. let GetABytes W dev v = match W =%= fun w -> w.GetArchive dev v with
  96. | Some(t) -> t
  97. | None -> [||]
  98. let GetIBytes W dev = match W =%= fun w -> w.GetInstant dev with
  99. | Some(t) -> t
  100. | None -> [||]
  101. //------------------------------------------------------------------------------------------------------------//
143 views