修改:1、修改打开lua脚本的方式
This commit is contained in:
commit
c1aae080ea
|
@ -65,16 +65,20 @@ func (c *CommunicationIoInTemplate) WriteData(data []byte) int {
|
|||
func (c *CommunicationIoInTemplate) ReadData(data []byte) int {
|
||||
|
||||
if c.Param.FD != nil {
|
||||
_, err := c.Param.FD.Seek(0, 0)
|
||||
if err != nil {
|
||||
setting.Logger.Errorf("IoIn seek err,%v", err)
|
||||
}
|
||||
cnt, err := c.Param.FD.Read(data)
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
setting.Logger.Errorf("IoIn read err,%v", err)
|
||||
}
|
||||
}
|
||||
if cnt > 0 {
|
||||
setting.Logger.Errorf("IoIn read data,%v", data[:cnt])
|
||||
}
|
||||
return 0
|
||||
//if cnt > 0 {
|
||||
// setting.Logger.Errorf("IoIn read data,%v", data[:cnt])
|
||||
//}
|
||||
return cnt
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -95,8 +95,8 @@ func (c *CommunicationManageTemplate) AnalysisRx() {
|
|||
//阻塞读
|
||||
rxBufCnt = c.CollInterface.CommInterface.ReadData(rxBuf)
|
||||
if rxBufCnt > 0 {
|
||||
setting.Logger.Debugf("curRxBufCnt %v,", rxBufCnt)
|
||||
setting.Logger.Debugf("CurRxBuf %X\n", rxBuf[:rxBufCnt])
|
||||
//setting.Logger.Debugf("curRxBufCnt %v,", rxBufCnt)
|
||||
//setting.Logger.Debugf("CurRxBuf %X\n", rxBuf[:rxBufCnt])
|
||||
|
||||
//rxTotalBufCnt += rxBufCnt
|
||||
//追加接收的数据到接收缓冲区
|
||||
|
|
|
@ -92,16 +92,60 @@ func ReadDeviceNodeTypeMap() bool {
|
|||
return false
|
||||
}
|
||||
for _, v := range fileInfoMap {
|
||||
setting.Logger.Debugf("fileInfo %v", v.Name())
|
||||
if v.IsDir() == false {
|
||||
fileFullName := pluginPath + "/" + v.Name()
|
||||
setting.Logger.Debugf("fileFullName %v", fileFullName)
|
||||
if strings.Contains(v.Name(), ".json") {
|
||||
//log.Println("fullName ",fullName)
|
||||
//文件夹
|
||||
if v.IsDir() == true {
|
||||
setting.Logger.Debugf("fileDirInfo %v", v.Name())
|
||||
fileDirName := pluginPath + "/" + v.Name()
|
||||
fileMap, err := ioutil.ReadDir(fileDirName)
|
||||
if err != nil {
|
||||
log.Println("readDir err,", err)
|
||||
return false
|
||||
}
|
||||
for _, f := range fileMap {
|
||||
setting.Logger.Debugf("fileName %v", f.Name())
|
||||
fileFullName := fileDirName + "/" + f.Name()
|
||||
if strings.Contains(f.Name(), ".json") {
|
||||
fp, err := os.OpenFile(fileFullName, os.O_RDONLY, 0777)
|
||||
if err != nil {
|
||||
setting.Logger.Errorf("open %s err", f)
|
||||
return false
|
||||
}
|
||||
defer fp.Close()
|
||||
|
||||
} else if strings.Contains(v.Name(), ".lua") {
|
||||
//log.Println("fullName ",fullName)
|
||||
data := make([]byte, 2048)
|
||||
dataCnt, err := fp.Read(data)
|
||||
|
||||
err = json.Unmarshal(data[:dataCnt], &deviceTypeTemplate)
|
||||
if err != nil {
|
||||
log.Println("deviceTypeTemplate unmarshal err", err)
|
||||
return false
|
||||
}
|
||||
|
||||
nodeType := DeviceNodeTypeTemplate{}
|
||||
nodeType.TemplateID = len(DeviceNodeTypeMap.DeviceNodeType)
|
||||
nodeType.TemplateType = deviceTypeTemplate.TemplateType
|
||||
nodeType.TemplateName = deviceTypeTemplate.TemplateName
|
||||
nodeType.TemplateMessage = deviceTypeTemplate.TemplateMessage
|
||||
|
||||
DeviceNodeTypeMap.DeviceNodeType = append(DeviceNodeTypeMap.DeviceNodeType, nodeType)
|
||||
} else if strings.Contains(f.Name(), ".lua") {
|
||||
if strings.Contains(f.Name(), v.Name()) == true {
|
||||
template, err := setting.LuaOpenFile(fileFullName)
|
||||
if err != nil {
|
||||
setting.Logger.Errorf("openPlug %s err,%s\n", v.Name(), err)
|
||||
} else {
|
||||
setting.Logger.Debugf("openPlug %s ok\n", f.Name())
|
||||
}
|
||||
for k, d := range DeviceNodeTypeMap.DeviceNodeType {
|
||||
//setting.Logger.Debugf("DeviceNodeType %v", nodeType)
|
||||
if d.TemplateName == v.Name() {
|
||||
DeviceTypePluginMap[k] = template
|
||||
DeviceTypePluginMap[k].SetGlobal("GetCRCModbus", DeviceTypePluginMap[k].NewFunction(setting.GetCRCModbus))
|
||||
DeviceTypePluginMap[k].SetGlobal("CheckCRCModbus", DeviceTypePluginMap[k].NewFunction(setting.CheckCRCModbus))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue