Skip to content

Commit

Permalink
Merge pull request #1 from siyka-au/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
l1va authored Aug 1, 2018
2 parents d43fa07 + 60b9db9 commit 5b5efc9
Show file tree
Hide file tree
Showing 17 changed files with 1,242 additions and 272 deletions.
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
example/debug

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

*.idea
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# gofins
# GoFINS

[![Build Status](https://travis-ci.org/l1va/gofins.svg?branch=master)](https://travis-ci.org/l1va/gofins)


This is fins command client written by Go.

The library support communication to omron PLC from Go application.

Ideas were taken from https://github.com/hiroeorz/omron-fins-go and https://github.com/patrick--/node-omron-fins

Library was tested with <b>Omron PLC NJ501-1300</b>. Mean time of the cycle request-response is 4ms.
Additional work in the siyka-au repository was tested against a CP1L-EM.

Feel free to ask questions, raise issues and make pull requests!


<b>PS. Build is ok</b> but Travis is randomly failing to run tests with <b>go 1.10</b>
(with earlier go versions tests are passed too): [travis](https://travis-ci.org/l1va/gofins)
```
Expand Down
86 changes: 54 additions & 32 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,69 @@ package main

import (
"fmt"
"log"
"github.com/l1va/gofins/fins"
"net"

"github.com/siyka-au/gofins/fins"
)

func main() {
plcAddr := "192.168.250.1:9600"

c := fins.NewClient(plcAddr)
defer c.CloseConnection()

err := c.WriteDAsync(100, []uint16{5, 4, 3, 2, 1}, func(fins.Response) {
log.Println("writing done!")
})
if err != nil {
log.Println("writing request failed:", err)
localClientAddr := &net.UDPAddr{
IP: net.ParseIP("192.168.250.2"),
Port: 9600,
}

err = c.ReadDAsync(100, 5, func(r fins.Response) {
log.Println("readed values: ", r.Data)
})
if err != nil {
log.Println("reading request failed:", err)
// localServerAddr := &net.UDPAddr{
// IP: net.ParseIP("192.168.250.3"),
// Port: 9600,
// }
plcAddr := &net.UDPAddr{
IP: net.ParseIP("192.168.250.10"),
Port: 9600,
}

for i := 0; i < 10; i += 1 {
t := uint16(i * 5)
err := c.WriteD(200+t, []uint16{t, t + 1, t + 2, t + 3, t + 4})
if err != nil {
log.Fatal(err)
}
c, e := fins.NewClient(localClientAddr, plcAddr, fins.NewAddress(0, 10, 0), fins.NewAddress(0, 2, 0))
defer c.Close()
if e != nil {
panic(e)
}

err = c.WriteDNoResponse(200, []uint16{5, 4, 3, 2, 1})
if err != nil {
log.Println("writing request without response failed:", err)
}
// s, e := fins.NewServer(localServerAddr, fins.NewAddress(0, 3, 0))
// if e != nil {
// panic(e)
// }

vals, err := c.ReadD(200, 50)
if err != nil {
log.Fatal(err)
}
defer c.Close()
// defer s.Close()

z, _ := c.ReadWords(fins.MemoryAreaDMWord, 10000, 500)
fmt.Println(z)

fmt.Println(vals)
// s, _ := c.ReadString(fins.MemoryAreaDMWord, 10000, 10)
// fmt.Println(s)
// fmt.Println(len(s))

// b, _ := c.ReadBits(fins.MemoryAreaDMWord, 10473, 2, 1)
// fmt.Println(b)
// fmt.Println(len(b))

// c.WriteWords(fins.MemoryAreaDMWord, 24000, []uint16{z[0] + 1, z[1] - 1})
// c.WriteBits(fins.MemoryAreaDMBit, 24002, 0, []bool{false, false, false, true,
// true, false, false, true,
// false, false, false, false,
// true, true, true, true})
// c.SetBit(fins.MemoryAreaDMBit, 24003, 1)
// c.ResetBit(fins.MemoryAreaDMBit, 24003, 0)
// c.ToggleBit(fins.MemoryAreaDMBit, 24003, 2)

// cron := cron.New()
// s := rasc.NewShelter()
// cron.AddFunc("*/5 * * * * *", func() {
// t, _ := c.ReadClock()
// fmt.Printf("Setting PLC time to: %s\n", t.Format(time.RFC3339))
// c.WriteString(fins.MemoryAreaDMWord, 10000, 10, t.Format(time.RFC3339))
// })
// cron.Start()

for {
}
}
28 changes: 28 additions & 0 deletions fins/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package fins

// Address A FINS device address
type Address struct {
network byte
node byte
unit byte
}

func NewAddress(network byte, node byte, unit byte) *Address {
a := new(Address)
a.network = network
a.node = node
a.unit = unit
return a
}

func (a *Address) Network() byte {
return a.network
}

func (a *Address) Node() byte {
return a.node
}

func (a *Address) Unit() byte {
return a.unit
}
Loading

0 comments on commit 5b5efc9

Please sign in to comment.