public class S7PLC extends PLCNetwork
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_PDU_LENGTH |
static String |
IP |
static int |
PORT |
pduLength, plcType, rack, slotconnectTimeout, enableReconnect, receiveTimeout, socket, socketAddress, socketError, tag| 构造器和说明 |
|---|
S7PLC() |
S7PLC(EPlcType plcType) |
S7PLC(EPlcType plcType,
String ip) |
S7PLC(EPlcType plcType,
String ip,
int port) |
S7PLC(EPlcType plcType,
String ip,
int port,
int rack,
int slot) |
S7PLC(EPlcType plcType,
String ip,
int port,
int rack,
int slot,
int pduLength) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
coldRestart()
冷重启
|
void |
compress()
压缩
|
void |
copyRamToRom()
将ram复制到rom
|
void |
hotRestart()
热重启
|
void |
insert(EFileBlockType blockType,
int blockNumber)
创建插入文件指令
|
void |
plcStop()
PLC停止
|
double |
readActFeedRate()
获取实际进给速率
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 13 00 0C 00 00 04 01 12 08 82 41 00 01 00 01 7F 01 接收[33]:03 00 00 21 02 F0 80 32 03 00 00 00 13 00 02 00 0C 00 00 04 01 FF 09 00 08 00 00 00 00 00 00 00 00 |
double |
readActSpindleSpeed()
实际主轴转速
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 13 00 0C 00 00 04 01 12 08 82 41 00 02 00 01 72 01 接收[33]:03 00 00 21 02 F0 80 32 03 00 00 00 13 00 02 00 0C 00 00 04 01 FF 09 00 08 00 00 00 00 00 00 00 00 |
long |
readAlarmInfo()
报警信息
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 01 00 07 00 01 7F 01 接收[27]:03 00 00 1B 02 F0 80 32 03 00 00 00 00 00 02 00 06 00 00 04 01 FF 09 00 02 05 00 |
int |
readAlarmNumber()
报警数量
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 01 00 07 00 01 7F 01 接收[27]:03 00 00 1B 02 F0 80 32 03 00 00 00 00 00 02 00 06 00 00 04 01 FF 09 00 02 05 00 |
List<Boolean> |
readBoolean(List<String> addresses)
读取boolean列表
|
List<Boolean> |
readBoolean(String... address)
读取多个个boolean值
|
boolean |
readBoolean(String address)
读取一个boolean
|
byte |
readByte(String address)
读取一个字节
|
byte[] |
readByte(String address,
int count)
单地址字节数据读取
|
String |
readCncId()
CNC的ID
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 01 46 6E 00 01 1A 01 接收[57]:03 00 00 39 02 F0 80 32 03 00 00 00 00 00 02 00 24 00 00 04 01 FF 09 00 20 30 30 30 30 36 30 31 39 33 30 38 38 46 43 30 30 30 30 37 35 00 00 00 00 00 00 00 00 00 00 00 00 |
String |
readCncManufactureDate()
CNC的Version
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 01 46 78 00 01 1A 01 接收[45]:03 00 00 2D 02 F0 80 32 03 00 00 00 00 00 02 00 18 00 00 04 01 FF 09 00 14 30 34 2E 30 38 2E 30 37 2E 30 30 2E 30 32 30 20 20 20 20 00 |
String |
readCncType()
CNC的Type
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 01 46 78 00 04 1A 01 接收[45]:03 00 00 2D 02 F0 80 32 03 00 00 00 00 00 02 00 18 00 00 04 01 FF 09 00 14 38 32 38 44 2D 4D 45 34 32 00 00 00 00 00 00 00 00 00 00 00 |
String |
readCncType1()
类型
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 01 46 78 00 02 1A 01 接收[45]:03 00 00 2D 02 F0 80 32 03 00 00 00 00 00 02 00 18 00 00 04 01 FF 09 00 14 38 32 38 44 5F 30 34 2E 30 38 20 20 20 20 20 00 00 00 00 00 |
String |
readCncVersion()
CNC的Version
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 01 46 78 00 01 1A 01 接收[45]:03 00 00 2D 02 F0 80 32 03 00 00 00 00 00 02 00 18 00 00 04 01 FF 09 00 14 30 34 2E 30 38 2E 30 37 2E 30 30 2E 30 32 30 20 20 20 20 00 |
java.time.LocalDate |
readDate(String address)
读取日期,例如:2023-04-04
|
java.time.LocalDateTime |
readDTL(String address)
日期和时间的数据类型
|
double |
readFeedRate()
进给速率
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 13 00 0C 00 00 04 01 12 08 82 41 00 03 00 01 7F 01 接收[33]:03 00 00 21 02 F0 80 32 03 00 00 00 13 00 02 00 0C 00 00 04 01 FF 09 00 08 00 00 00 00 00 00 00 00 |
List<Float> |
readFloat32(List<String> addresses)
读取多个Float32的数据
|
List<Float> |
readFloat32(String... address)
读取多个Float32的数据
|
float |
readFloat32(String address)
读取一个Float32的数据
|
List<Double> |
readFloat64(List<String> addresses)
读取多个Float64的数据
|
List<Double> |
readFloat64(String... address)
读取多个Float64的数据
|
double |
readFloat64(String address)
读取一个Float64的数据
|
List<Short> |
readInt16(List<String> addresses)
读取Int16 2字节数据列表
|
List<Short> |
readInt16(String... address)
读取Int16 2字节数据列表
|
short |
readInt16(String address)
读取一个Int16 2字节数据
|
List<Integer> |
readInt32(List<String> addresses)
读取UInt32 4字节数据列表
|
List<Integer> |
readInt32(String... address)
读取UInt32 4字节数据列表
|
int |
readInt32(String address)
读取一个UInt32 4字节数据
|
List<Double> |
readMachinePosition()
获取机械坐标系
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 13 00 0C 00 00 04 01 12 08 82 41 00 02 00 01 74 01 接收[33]:03 00 00 21 02 F0 80 32 03 00 00 00 13 00 02 00 0C 00 00 04 01 FF 09 00 08 CD CC CC CC CC 6C 61 40 另一种方式也可以一个request,lineCount=3,结果有3个数据 发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 02 00 0C 00 00 04 01 12 08 82 41 00 02 00 01 74 03 接收[49]:03 00 00 31 02 F0 80 32 03 00 00 00 02 00 02 00 1C 00 00 04 01 FF 09 00 18 D8 B6 28 B3 41 26 69 3F 2D 43 1C EB E2 36 3A BF E7 52 5C 55 F6 5D 41 3F |
List<byte[]> |
readMultiByte(MultiAddressRead addressRead)
多地址读取字节数据
|
String |
readProgramName()
程序名
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 41 00 0C 00 01 7A 01 接收[185]:03 00 00 B9 02 F0 80 32 03 00 00 00 00 00 02 00 A4 00 00 04 01 FF 09 00 A0 2F 5F 4E 5F 4D 50 46 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
byte[] |
readRaw(EParamVariableType variableType,
int count,
EArea area,
int dbNumber,
int byteAddress,
int bitAddress)
最原始的方式读取生数据
|
List<Double> |
readRelativePosition()
获取相对坐标系
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 13 00 0C 00 00 04 01 12 08 82 41 00 19 00 01 70 01 接收[33]:03 00 00 21 02 F0 80 32 03 00 00 00 13 00 02 00 0C 00 00 04 01 FF 09 00 08 5B B6 D6 17 89 2D C8 40 |
List<Double> |
readRemainPosition()
获取剩余坐标系
发送[59]:03 00 00 3B 02 F0 80 32 01 00 00 00 00 00 2A 00 00 04 04 12 08 82 41 00 03 00 01 74 01 12 08 82 41 00 03 00 02 74 01 12 08 82 41 00 03 00 03 74 01 12 08 82 41 00 03 00 04 74 01 接收[69]:03 00 00 45 02 F0 80 32 03 00 00 00 00 00 02 00 30 00 00 04 04 FF 09 00 08 00 00 00 00 00 00 00 00 FF 09 00 08 00 00 00 00 00 00 00 00 FF 09 00 08 00 00 00 00 00 00 00 00 FF 09 00 08 00 00 00 00 00 00 00 00 |
double |
readRemainTime()
剩余时间
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 41 01 2A 00 01 7F 01 接收[33]:03 00 00 21 02 F0 80 32 03 00 00 00 00 00 02 00 0C 00 00 04 01 FF 09 00 08 00 00 00 00 00 00 00 00 |
double |
readRunTime()
运行时间
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 41 01 29 00 01 7F 01 接收[33]:03 00 00 21 02 F0 80 32 03 00 00 00 00 00 02 00 0C 00 00 04 01 FF 09 00 08 00 00 00 00 00 00 00 00 |
double |
readSetFeedRate()
获取设定进给速率
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 13 00 0C 00 00 04 01 12 08 82 41 00 02 00 01 7F 01 接收[33]:03 00 00 21 02 F0 80 32 03 00 00 00 13 00 02 00 0C 00 00 04 01 FF 09 00 08 00 00 00 00 00 00 00 00 |
double |
readSetSpindleSpeed()
设定主轴转速
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 41 00 04 00 01 72 01 接收[33]:03 00 00 21 02 F0 80 32 03 00 00 00 00 00 02 00 0C 00 00 04 01 FF 09 00 08 00 00 00 00 00 00 59 40 |
double |
readSpindleRate()
主轴速率
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 41 00 04 00 01 72 01 接收[33]:03 00 00 21 02 F0 80 32 03 00 00 00 00 00 02 00 0C 00 00 04 01 FF 09 00 08 00 00 00 00 00 00 59 40 |
int |
readStatus()
状态,2:stop, 1:start, 0:reset
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 41 00 0B 00 01 7F 01 接收[27]:03 00 00 1B 02 F0 80 32 03 00 00 00 00 00 02 00 06 00 00 04 01 FF 09 00 02 02 00 |
String |
readString(String address)
读取字符串
String(字符串)数据类型存储一串单字节字符,
S1200(非S200SMART):String提供了多大256个字节,前两个字节分别表示字节中最大的字符数和当前的字符数,定义字符串的最大长度可以减少它的占用存储空间
S200SMART:字符串由变量存储时,字符串长度为0至254个字符,最长为255个字节,其中第一个字符为长度字节
|
String |
readString(String address,
int length)
读取字符串
S1200(非S200SMART):数据类型为 string 的操作数可存储多个字符,最多可包括 254 个字符。
|
long |
readTime(String address)
读取时间,时间为毫秒时间,ms,例如1000ms
|
java.time.LocalTime |
readTimeOfDay(String address)
读取一天中的时间,例如:23:56:31
|
int |
readToolNumber()
刀具编号
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 13 00 0C 00 00 04 01 12 08 82 41 00 17 00 01 7F 01 接收[27]:03 00 00 1B 02 F0 80 32 03 00 00 00 13 00 02 00 06 00 00 04 01 FF 09 00 02 01 00 |
int |
readToolRadiusCompensationNumber()
刀具半径补偿编号
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 13 00 0C 00 00 04 01 12 08 82 41 00 23 00 01 7F 01 接收[57]:03 00 00 39 02 F0 80 32 03 00 00 00 13 00 02 00 24 00 00 04 01 FF 09 00 20 32 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
List<Double> |
readTWorkPiecePosition()
T工件坐标
发送[49]:03 00 00 31 02 F0 80 32 01 00 00 00 00 00 20 00 00 04 03 12 08 82 41 00 01 00 04 12 01 12 08 82 41 00 01 00 05 12 01 12 08 82 41 00 01 00 06 12 01 接收[57]:03 00 00 39 02 F0 80 32 03 00 00 00 00 00 02 00 24 00 00 04 03 FF 09 00 08 00 00 00 00 00 00 00 80 FF 09 00 08 00 00 00 00 00 00 00 80 FF 09 00 08 00 00 00 00 00 00 00 80 |
List<Integer> |
readUInt16(List<String> addresses)
读取UInt16 2字节数据列表
|
List<Integer> |
readUInt16(String... address)
读取UInt16 2字节数据列表
|
int |
readUInt16(String address)
读取一个UInt16 2字节数据
|
List<Long> |
readUInt32(List<String> addresses)
读取UInt32 4字节数据列表
|
List<Long> |
readUInt32(String... address)
读取UInt32 4字节数据列表
|
long |
readUInt32(String address)
读取一个UInt32 4字节数据
|
int |
readWorkMode()
工作模式的请求,0:JOG, 1:MDA, 2:AUTO, 其他
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 00 00 0C 00 00 04 01 12 08 82 21 00 03 00 01 7F 01 接收[27]:03 00 00 1B 02 F0 80 32 03 00 00 00 00 00 02 00 06 00 00 04 01 FF 09 00 02 00 00 |
void |
writeBoolean(String address,
boolean data)
写入boolean数据
|
void |
writeByte(String address,
byte data)
写入字节数据
|
void |
writeByte(String address,
byte[] data)
写入字节列表数据
|
void |
writeDate(String address,
java.time.LocalDate date)
读取日期
|
void |
writeDTL(String address,
java.time.LocalDateTime dateTime)
写入具体的时间
|
void |
writeFloat32(String address,
float data)
写入Float32数据
|
void |
writeFloat64(String address,
double data)
写入Float64数据
|
void |
writeInt16(String address,
short data)
写入Int16数据
|
void |
writeInt32(String address,
int data)
写入Int32数据
|
void |
writeMultiData(MultiAddressWrite addressWrite)
多地址写入数据
|
void |
writeRaw(EParamVariableType variableType,
int count,
EArea area,
int dbNumber,
int byteAddress,
int bitAddress,
EDataVariableType dataVariableType,
byte[] data)
最原始的方式写入生数据
|
void |
writeString(String address,
String data)
写入字符串数据
String(字符串)数据类型存储一串单字节字符,
String提供了多大256个字节,前两个字节分别表示字节中最大的字符数和当前的字符数,定义字符串的最大长度可以减少它的占用存储空间
S1200:数据类型为 string 的操作数可存储多个字符,最多可包括 254 个字符。
|
void |
writeTime(String address,
long time)
写入时间,时间为毫秒时间,ms
|
void |
writeTimeOfDay(String address,
java.time.LocalTime time)
写入一天中的时间
|
void |
writeUInt16(String address,
int data)
写入UInt16数据
|
void |
writeUInt32(String address,
long data)
写入UInt32数据
|
connect, doAfterConnected, downloadFile, getPduLength, getPlcType, getRack, getSlot, isPersistence, readFromServerByPersistence, readFromServerByPersistence, readS7Data, readS7Data, readS7NckData, readS7NckData, setComCallback, setPersistence, uploadFile, writeS7Data, writeS7DatacheckConnected, close, getAvailableSocket, getConnectTimeout, getReceiveTimeout, getSocketAddress, isEnableReconnect, read, read, read, read, read, read, setConnectTimeout, setEnableReconnect, setReceiveTimeout, write, write, writepublic static final int PORT
public static final int DEFAULT_PDU_LENGTH
public S7PLC()
public S7PLC(EPlcType plcType)
public byte[] readRaw(EParamVariableType variableType, int count, EArea area, int dbNumber, int byteAddress, int bitAddress)
variableType - 参数类型count - 数据个数area - 区域dbNumber - DB块编号byteAddress - 字节地址bitAddress - 位地址public List<byte[]> readMultiByte(MultiAddressRead addressRead)
addressRead - 地址包装列表public byte[] readByte(String address, int count)
address - 地址count - 字节个数public byte readByte(String address)
address - 地址public boolean readBoolean(String address)
address - 地址public List<Boolean> readBoolean(String... address)
address - 地址public List<Boolean> readBoolean(List<String> addresses)
addresses - 地址列表public short readInt16(String address)
address - 地址public List<Short> readInt16(String... address)
address - 地址public List<Short> readInt16(List<String> addresses)
addresses - 地址列表public int readUInt16(String address)
address - 地址public List<Integer> readUInt16(String... address)
address - 地址public List<Integer> readUInt16(List<String> addresses)
addresses - 地址列表public int readInt32(String address)
address - 地址public List<Integer> readInt32(String... address)
address - 地址public List<Integer> readInt32(List<String> addresses)
addresses - 地址列表public long readUInt32(String address)
address - 地址public List<Long> readUInt32(String... address)
address - 地址public List<Long> readUInt32(List<String> addresses)
addresses - 地址列表public float readFloat32(String address)
address - 地址public List<Float> readFloat32(String... address)
address - 地址public List<Float> readFloat32(List<String> addresses)
addresses - 地址列表public double readFloat64(String address)
address - 地址public List<Double> readFloat64(String... address)
address - 多个地址public List<Double> readFloat64(List<String> addresses)
addresses - 地址列表public String readString(String address)
address - 地址public String readString(String address, int length)
address - 地址length - 字符串长度public long readTime(String address)
address - 地址public java.time.LocalDate readDate(String address)
address - 地址public java.time.LocalTime readTimeOfDay(String address)
address - 地址public java.time.LocalDateTime readDTL(String address)
address - 地址public void writeRaw(EParamVariableType variableType, int count, EArea area, int dbNumber, int byteAddress, int bitAddress, EDataVariableType dataVariableType, byte[] data)
variableType - 参数类型count - 数据个数area - 区域dbNumber - DB块编号byteAddress - 字节地址bitAddress - 位地址dataVariableType - 数据变量类型data - 数据字节数组public void writeBoolean(String address, boolean data)
address - 地址data - boolean数据public void writeByte(String address, byte data)
address - 地址data - 字节数据public void writeByte(String address, byte[] data)
address - 地址data - 字节列表数据public void writeUInt16(String address, int data)
address - 地址data - UInt16数据public void writeInt16(String address, short data)
address - 地址data - Int16数据public void writeUInt32(String address, long data)
address - 地址data - UInt32数据public void writeInt32(String address, int data)
address - 地址data - Int32数据public void writeFloat32(String address, float data)
address - 地址data - Float32数据public void writeFloat64(String address, double data)
address - 地址data - Float64数据public void writeMultiData(MultiAddressWrite addressWrite)
addressWrite - 数据public void writeString(String address, String data)
address - 地址data - 字符串数据public void writeTime(String address, long time)
address - 地址time - 时间,mspublic void writeDate(String address, java.time.LocalDate date)
address - 地址date - 日期public void writeTimeOfDay(String address, java.time.LocalTime time)
address - 地址time - 时间public void writeDTL(String address, java.time.LocalDateTime dateTime)
address - 地址dateTime - LocalDateTime对象public void hotRestart()
public void coldRestart()
public void plcStop()
public void copyRamToRom()
public void compress()
public void insert(EFileBlockType blockType, int blockNumber)
blockType - 块类型blockNumber - 块编号public String readCncId()
public String readCncVersion()
public String readCncType1()
public String readCncManufactureDate()
public String readCncType()
public List<Double> readMachinePosition()
另一种方式也可以一个request,lineCount=3,结果有3个数据
发送[29]:03 00 00 1D 02 F0 80 32 01 00 00 00 02 00 0C 00 00 04 01 12 08 82 41 00 02 00 01 74 03
接收[49]:03 00 00 31 02 F0 80 32 03 00 00 00 02 00 02 00 1C 00 00 04 01 FF 09 00 18 D8 B6 28 B3 41 26 69 3F 2D 43 1C EB E2 36 3A BF E7 52 5C 55 F6 5D 41 3F
public List<Double> readRelativePosition()
public List<Double> readRemainPosition()
public List<Double> readTWorkPiecePosition()
public int readToolRadiusCompensationNumber()
public int readToolNumber()
public double readActSpindleSpeed()
public double readSetSpindleSpeed()
public double readSpindleRate()
public double readFeedRate()
public double readSetFeedRate()
public double readActFeedRate()
public int readWorkMode()
public int readStatus()
public double readRunTime()
public double readRemainTime()
public String readProgramName()
public int readAlarmNumber()
public long readAlarmInfo()
Copyright © 2024. All rights reserved.