zhangqian
2023-09-05 49e90e5de2e7166e74e26102dff9064b933fc5fd
service/plc.go
@@ -8,7 +8,6 @@
   "encoding/binary"
   "errors"
   "fmt"
   "sync"
)
func PlcRead(plcConfig *model.DevicePlc, fieldType constvar.PlcStartAddressType) (val interface{}, err error) {
@@ -85,42 +84,4 @@
   }
   logx.Infof("plc write ok, address: %v, value: %v, result: %v", startAddress, value, result)
   return
}
type CacheStore struct {
   cache map[string]interface{}
   mu    sync.Mutex
}
var defaultCacheStore *CacheStore
func init() {
   defaultCacheStore = newCacheManager()
}
func newCacheManager() *CacheStore {
   return &CacheStore{
      cache: make(map[string]interface{}),
   }
}
func (cm *CacheStore) Get(key string) (interface{}, bool) {
   cm.mu.Lock()
   defer cm.mu.Unlock()
   conn, ok := cm.cache[key]
   return conn, ok
}
func (cm *CacheStore) Add(key string, value interface{}) {
   cm.mu.Lock()
   defer cm.mu.Unlock()
   cm.cache[key] = value
}
func PlcCacheGet(key string) (interface{}, bool) {
   return defaultCacheStore.Get(key)
}
func PlcCacheSet(key string, value interface{}) {
   defaultCacheStore.Add(key, value)
}