halcon语法和C语言有很大相似之处,参考 https://blog.51cto.com/u_15698411/5661523
基础语法
赋值: :=
不等号: #
注释符(f4): *
字符串赋值: str:=’halcon’
等于比较符: if(X=10)
与: if(A>1 and A<30)
或: if(A>1 or A<30)
求反: if(not(A=10))
For 循环:
for I := 0 to NumBalls by 1
*dosomthing
endfor
While 循环:
while (x == 1)
*dosomething
Endwhile
异常获取:
Try
*dosomthing
catch (Exception)
Endtry
Switch多分支:
switch (Index)
case 1:
break
case 2:
break
case 3:
break
default:
break
endswitch
数组的一些操作
将一个Tuple数组赋值给变量
Tuple1 := [1,0,3,4,5,6,7,8,9]
求数组长度 len = |Tuple1| 此时len应该是9
给Tuple数组元素赋值
Tuple1[1] := 2
结果变为:
[1, 2, 3, 4, 5, 6, 7, 8, 9] // 可见第二个数从 0 变成了 2
批量改变数组元素的值
Tuple1[1,3,5] := 'abc'
结果变为:
[1, 'abc', 3, 'abc', 5, 'abc', 7, 8, 9] // 下标 1, 3, 5 对应的改成了 `abc`
批量给Tuple数组赋值, 例如,0到10连续数值
Tuple3 := [0:10]
结果为:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
批量给Tuple数组赋值,其值为3到20连续数值,步长为2。 // 中间的步长为1就成连续的了。
Tuple4 := [3:2:20]
1.
结果为:
[3, 5, 7, 9, 11, 13, 15, 17, 19]
批量给Tuple数组赋值,其值为100到-100连续数值,步长为-10
Tuple5 := [100:-10:-100]
结果为:
[100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, -10, -20, -30, -40, -50, -60, -70, -80, -90, -100]
1.
对两个Tuple数组进行合并操作
TupleInt1 := [3,1,2,9,1]
TupleInt2 := [10,2,4,3,2]
tuple_union (TupleInt1, TupleInt2, UnionInt)
变量UnionInt变为:
[1, 2, 3, 4, 9, 10]
对两个Tuple数组进行交集操作
TupleInt3 := [3,1,2,9,1]
TupleInt4 := [10,2,4,3,2]
tuple_intersection (TupleInt3, TupleInt4, IntersectionInt)
变量IntersectionInt变为:
[2, 3]
对Tuple数组元素进行替换
OriginalTuple := [0,1,2,3,4,5]
tuple_replace (OriginalTuple, [0,1], ['x','y'], Replaced)
变量Replaced变为:
['x', 'y', 2, 3, 4, 5]
向Tuple数组插入数值
OriginalTuple := [0,1,2,3,4,5]
tuple_insert (OriginalTuple, 3, 'x', InsertSingleValueA)
变量InsertSingleValueA变为:
[0, 1, 2, 'x', 3, 4, 5] // 在索引 3 位置插入了元素 `x`