
逐条讲解:



用到的相关信息:
下面为 8 种不同的变量类型,前 5 种为有号数值型态,后 3 种为无号数值型态:
变量类型 | 描述 | 范围 |
|---|---|---|
bool 布尔型 | 1 bit (一个位) | 0, 1 |
char 字符型 | 8 bits (一个字节) | +127 ~ -128 |
short 短整型 | 16 bits (一个字) | +32767 ~ -32768 |
int 双整型 | 32 bits (双字) | +2147483647 ~ -2147483648 |
float 浮点型 | 32 bits (双字) | |
unsigned char 字符型 | 8 bits (一个字节) | 0 ~ 255 |
unsigned short 短整型 | 16 bits (一个字) | 0 ~ 65535 |
unsigned int 双整型 | 32 bits (双字) | 0 ~ 4,294,967,295 |
long 长整数 | 64 bits (四个字)(只支援于 cMT X) | +281474976710655 ~ -281474976710655 |
unsigned long 长整数 | 64 bits (四个字)(只支援于 cMT X) | 0 ~ 281474976710655 |
double 双精度浮点数 | 64 bits (四个字)(只支援于 cMT X) |
函数一览表
函数名称 | 简述 |
|---|---|
PLC 函数 | |
GetData | 读取 PLC 的数据。 |
GetDataEx | 读取 PLC 的数据,不等待 PLC 响应,径自往下执行。 |
GetError | 取得错误码。 |
SetData | 将数据写到 PLC 中。 |
SetDataEx | 将数据写到 PLC 中,不等待 PLC 回应,径自往下执行。 |
函数名称 | GetData |
|---|---|
语法 | GetData(read_data[start], device_函数名称, device_type, address_offset, data_count) or GetData(read_data, device_函数名称, device_type, address_offset, 1) |
描述 | 获取 PLC 的资料。数据是存储在read_data[start]~read_data[start+data_count-1] 这些一维数组变量中。 data_count 是设定的读取数据的个数。一般来说, read_data 是一个一维数组, 但是如果 data_count 是 1, read_data 可以是一个一维数组,也可以是一个普通 的变量。下面是两种从 PLC 中读取一个字的方法。 macro_command main() short read_data_1[2], read_data_2 GetData(read_data_1[0], "FATEK FB Series", RT, 5, 1) GetData(read_data_2, "FATEK FB Series", RT, 5, 1) end macro_command 此处的 device_函数名称,即为在 “系统参数” 中建立 PLC 类型时,设定的“PLC 名称”。在此, PLC 名称被设定为 “FATEK FB Series”,如下图所示。 device_type 是设备类型和 PLC 中数据的编码方式。例如:如果 device_type 是 LW_BIN,那么读取的设备类型为 LW,数据编码方式为 BIN。如果使用 BIN 编码 方式, "_BIN" 可以忽略。 如果 device_type 是 LW_BCD,表示设备类型 LW,数据的编码方式为 BCD 格式。 address_offset 是 PLC 中的地址偏移量。 例如, GetData(read_data_1[0], "FATEK FB Series", RT, 5, 1) 代表读取的设备地址偏 移量为 5。 |