feat: 大屏改为纯流式自适应布局,新增KPI带与产线动态拓扑地图
This commit is contained in:
@@ -78,6 +78,20 @@ func (m *mockClient) QueryDockPallet(_ context.Context, dockCode string) (bool,
|
||||
return m.dockPallet[dockCode], nil
|
||||
}
|
||||
|
||||
// ReadMWBlock 批量读连续 MW(mock:逐地址查模拟寄存器表,缺省 0)。
|
||||
func (m *mockClient) ReadMWBlock(_ context.Context, start, count int) ([]int, error) {
|
||||
if start < 0 || count <= 0 || start+count > 65536 {
|
||||
return nil, errors.New("非法 MW 批量读区间")
|
||||
}
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
out := make([]int, count)
|
||||
for i := 0; i < count; i++ {
|
||||
out[i] = m.mw[start+i]
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// QueryStationPallet 读工位托盘位(mock):返回置位值,默认无件。
|
||||
func (m *mockClient) QueryStationPallet(_ context.Context, stationNo int) (bool, error) {
|
||||
m.mu.RLock()
|
||||
|
||||
@@ -37,6 +37,10 @@ type Client interface {
|
||||
ReadBits(ctx context.Context) ([]bool, error)
|
||||
// ReadMW 读取 16 位寄存器(MW)当前值(大端)。用于监控页读 MW800~MW886。
|
||||
ReadMW(ctx context.Context, addr int) (int, error)
|
||||
// ReadMWBlock 批量读取连续 MW 寄存器(大端),返回 [start..start+count-1] 每地址的 16 位值。
|
||||
// 真实 S7 一次 AGReadMB 读 count*2 字节;看板快照用它一次取 MW800..MW887(44 个路由寄存器),
|
||||
// 避免 44 次 ReadMW = 88 次 TCP 往返阻塞 PLC 连接。
|
||||
ReadMWBlock(ctx context.Context, start, count int) ([]int, error)
|
||||
// WriteMW 向 16 位寄存器(MW)写入值(大端)。用于手动下发路径指令、在途指令清零。
|
||||
WriteMW(ctx context.Context, addr, value int) error
|
||||
}
|
||||
@@ -93,6 +97,13 @@ func (m *Manager) ReadMW(ctx context.Context, addr int) (int, error) {
|
||||
return v, err
|
||||
}
|
||||
|
||||
// ReadMWBlock 批量读连续 MW 寄存器(带恢复检测)。
|
||||
func (m *Manager) ReadMWBlock(ctx context.Context, start, count int) ([]int, error) {
|
||||
v, err := m.client.ReadMWBlock(ctx, start, count)
|
||||
m.track(err)
|
||||
return v, err
|
||||
}
|
||||
|
||||
// WriteMW 写 16 位寄存器(带恢复检测)。
|
||||
func (m *Manager) WriteMW(ctx context.Context, addr, value int) error {
|
||||
err := m.client.WriteMW(ctx, addr, value)
|
||||
|
||||
@@ -89,28 +89,40 @@ func (s *s7Real) readBlock(ctx context.Context) ([]byte, error) {
|
||||
|
||||
// readByte 读取单个 Merker 字节(用于 48 位块之外的完成信号位等)。
|
||||
func (s *s7Real) readByte(ctx context.Context, byteOffset int) (byte, error) {
|
||||
buf, err := s.readBytes(ctx, byteOffset, 1)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return buf[0], nil
|
||||
}
|
||||
|
||||
// readBytes 读任意 Merker 字节区间(带惰性连接与断线重连),供 ReadMWBlock 等批量读使用。
|
||||
func (s *s7Real) readBytes(ctx context.Context, byteOffset, length int) ([]byte, error) {
|
||||
if byteOffset < 0 || length <= 0 {
|
||||
return nil, fmt.Errorf("非法读区间: offset=%d len=%d", byteOffset, length)
|
||||
}
|
||||
s.mu.Lock()
|
||||
if err := s.ensure(); err != nil {
|
||||
s.mu.Unlock()
|
||||
return 0, err
|
||||
return nil, err
|
||||
}
|
||||
cl := s.client
|
||||
s.mu.Unlock()
|
||||
buf := make([]byte, 1)
|
||||
buf := make([]byte, length)
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- cl.AGReadMB(byteOffset, 1, buf) }()
|
||||
go func() { done <- cl.AGReadMB(byteOffset, length, buf) }()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return 0, ctx.Err()
|
||||
return nil, ctx.Err()
|
||||
case err := <-done:
|
||||
if err != nil {
|
||||
s.mu.Lock()
|
||||
_ = s.handler.Close()
|
||||
s.client = nil
|
||||
s.mu.Unlock()
|
||||
return 0, err
|
||||
return nil, err
|
||||
}
|
||||
return buf[0], nil
|
||||
return buf, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,6 +252,23 @@ func (t *tcpClient) ReadMW(ctx context.Context, addr int) (int, error) {
|
||||
return int(hi)<<8 | int(lo), nil
|
||||
}
|
||||
|
||||
// ReadMWBlock 批量读连续 MW 寄存器(大端):一次 AGReadMB 读 count*2 字节,
|
||||
// 避免逐地址读造成的 2*count 次 TCP 往返(看板快照用,MW800..MW887 一次取完)。
|
||||
func (t *tcpClient) ReadMWBlock(ctx context.Context, start, count int) ([]int, error) {
|
||||
if start < 0 || count <= 0 || start+count*2 > 65536 {
|
||||
return nil, fmt.Errorf("非法 MW 批量读区间: start=%d count=%d", start, count)
|
||||
}
|
||||
buf, err := t.real.readBytes(ctx, start, count*2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]int, count)
|
||||
for i := 0; i < count; i++ {
|
||||
out[i] = int(buf[i*2])<<8 | int(buf[i*2+1])
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// WriteMW 写 16 位寄存器(MW,大端):高字节写 addr、低字节写 addr+1。
|
||||
func (t *tcpClient) WriteMW(ctx context.Context, addr, value int) error {
|
||||
buf := []byte{byte(value >> 8), byte(value & 0xff)}
|
||||
|
||||
Reference in New Issue
Block a user