-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhplctalk.mac
81 lines (68 loc) · 2.02 KB
/
hplctalk.mac
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Name MonitorFile
Parameter infile$, outfile$
Local in$, cmd_no, cmd$, response$, sep_position, cmd_len, last_cmd_no
Print "infile: ", infile$, "outfile: ", outfile$
! Overwrite files
Open infile$ for output as #3
Print #3, "0 Sleep 1"
Close #3
Open outfile$ for output as #4
Close #4
last_cmd_no = 0
Repeat
errorflag = 0
Sleep 0.5
result$ = ""
Open infile$ for input as #3
Input #3, in$
Close #3
sep_position = InStr (in$, " ")
cmd_len = Len (in$)
cmd_no = Val (in$[1:sep_position])
cmd$ = in$[(sep_position+1):cmd_len]
If cmd_no > last_cmd_no Then
last_cmd_no = cmd_no
Print "Executing: ", in$
! Acknowledge reading command
Open outfile$ for output as #4
Print #4, cmd_no, "ACK"
Close #4
If cmd$ = "Exit" Then
! do nothing
Else
Evaluate cmd$
On Error HandleError cmd_no, cmd$, outfile$
EndIf
If errorflag = 0 Then
! Write output
Open outfile$ for append as #4
Print #4, cmd_no, response$
Close #4
EndIf
! Confirm command execution
Open outfile$ for append as #4
Print #4, cmd_no, "DONE"
Close #4
EndIf
Until cmd$ = "Exit"
Print "Idle"
EndMacro
Name HandleError
Parameter cmd_no, cmd$, outfile$
errorflag = 1
Open outfile$ for append as #4
Print #4, "ERROR:", cmd_no, cmd$, "caused Error #", _Error
Close #4
EndMacro
Name HPLCTalk_Loop
MonitorFile "C:\Users\group\Code\analyticallabware\AnalyticalLabware\test\cmd", "C:\Users\group\Code\analyticallabware\AnalyticalLabware\test\reply"
EndMacro
Name HPLCTalk_Run
If CPExists(HPLCTalk_Cp) = 0 Then
CpStart HPLCTalk_Cp
EndIf
CpRequest HPLCTalk_Cp, HPLCTalk_Loop
EndMacro
Name HPLCTalk_Stop
CpTerminate HPLCTalk_Cp
EndMacro