1 Star 0 Fork 0

灵狐/gos7

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
datetime.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
robinson 提交于 2018-02-01 16:01 . Initial commit
package gos7
// Copyright 2018 Trung Hieu Le. All rights reserved.
// This software may be modified and distributed under the terms
// of the BSD license. See the LICENSE file for details.
import (
"encoding/binary"
"fmt"
"time"
)
//implement GetPLCDateTime
func (mb *client) PGClockWrite() (datetime time.Time, err error) {
requestData := make([]byte, len(s7GetDatetimeTelegram))
copy(requestData, s7GetDatetimeTelegram)
request := NewProtocolDataUnit(requestData)
//send
response, err := mb.send(&request)
if length := len(response.Data); length > 30 {
if (binary.BigEndian.Uint16(response.Data[27:]) == 0) && (response.Data[29] == 0xFF) {
var s7 Helper
datetime = s7.GetDateTimeAt(response.Data, 35)
} else {
err = fmt.Errorf(ErrorText(errCliInvalidPlcAnswer))
}
} else {
err = fmt.Errorf(ErrorText(errIsoInvalidPDU))
}
return
}
//implement SetPLCDateTime
func (mb *client) PGClockRead(datetime time.Time) (err error) {
requestData := make([]byte, len(s7SetDatetimeTelegram))
copy(requestData, s7SetDatetimeTelegram)
var s7 Helper
s7.SetDateTimeAt(requestData, 32, datetime)
request := NewProtocolDataUnit(requestData)
//send
response, err := mb.send(&request)
if length := len(response.Data); length > 30 {
if binary.BigEndian.Uint16(response.Data[27:]) != 0 {
err = fmt.Errorf(ErrorText(errCliInvalidPlcAnswer))
}
} else {
err = fmt.Errorf(ErrorText(errIsoInvalidPDU))
}
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fierce_wolf/gos7.git
git@gitee.com:fierce_wolf/gos7.git
fierce_wolf
gos7
gos7
v1.0.2

搜索帮助