mc

package module
v0.0.0-...-98f0ce0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2024 License: MIT Imports: 9 Imported by: 0

README

Mitsubishi PLC Protocol Library

This Go library provides an implementation of Mitsubishi PLC communication protocols, specifically the A_1E and Qna_3E protocols. The library currently supports reading and writing methods for these protocols. Batch read/write methods and support for the 4E protocol are planned but not yet implemented.

Features

  • A_1E Protocol: Implemented methods for reading and writing data.
  • Qna_3E Protocol: Implemented methods for reading and writing data.
  • Batch Operations: Planned for future implementation.
  • 4E Protocol: Planned for future implementation.

Installation

To install this library, you can use the following go get command:

go get -u github.com/wang-laoban/mcprotocol

Usage

Below is an example of how to use this library to connect to a Mitsubishi PLC using the Qna_3E protocol, read a boolean value from a specific memory address, and print the result.

package main

import (
	"fmt"
	mc "github.com/wang-laoban/mcprotocol"
)

func main() {
	// Initialize a new Mitsubishi client for the Qna_3E protocol
	client, err := mc.NewMitsubishiClient(mc.Qna_3E, "127.0.0.1", 6000, 0)
	if err != nil {
		panic(err)
	}

	fmt.Println("Start Connecting")
	err = client.Connect()
	if err != nil {
		panic(err)
	}

	// Read a boolean value from memory address M100
	v, err := client.ReadBool("M100")
	if err != nil {
		panic(err)
	}

	fmt.Println("Read bool:", v)
}

Functions and Methods

Connecting to PLC
  • NewMitsubishiClient(protocol string, ip string, port int, timeout int): Initializes a new Mitsubishi client with the specified protocol, IP address, port, and timeout.
  • Connect() error: Establishes a connection to the PLC.
Reading and Writing Data
  • ReadBool(address string) (bool, error): Reads a boolean value from the specified memory address.

  • WriteBool(address string, value bool) error: Writes a boolean value to the specified memory address.

Contribution

Contributions to the library are welcome. If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetReadCommand_A_1E

func GetReadCommand_A_1E(address MitsubishiMCAddress, length uint16, isBit bool) []byte

func GetReadCommand_Qna_3E

func GetReadCommand_Qna_3E(address MitsubishiMCAddress, length uint16, isBit bool) []byte

func GetWriteCommand_A_1E

func GetWriteCommand_A_1E(address MitsubishiMCAddress, data []byte, isBit bool) []byte

func GetWriteCommand_Qna_3E

func GetWriteCommand_Qna_3E(address MitsubishiMCAddress, data []byte, isBit bool) []byte

func PrintBuff

func PrintBuff(str string, buff []byte)

Types

type MitsubishiClient

type MitsubishiClient struct {
	Conn net.Conn
	// contains filtered or unexported fields
}

func NewMitsubishiClient

func NewMitsubishiClient(version MitsubishiVersion, ip string, port int, timeout time.Duration) (*MitsubishiClient, error)

func (*MitsubishiClient) Close

func (client *MitsubishiClient) Close() error

func (*MitsubishiClient) Connect

func (client *MitsubishiClient) Connect() error

func (*MitsubishiClient) Connected

func (client *MitsubishiClient) Connected() bool

func (*MitsubishiClient) ReConnect

func (client *MitsubishiClient) ReConnect()

func (*MitsubishiClient) Read

func (client *MitsubishiClient) Read(address string, length uint16, isBit bool) ([]byte, error)

func (*MitsubishiClient) ReadBool

func (client *MitsubishiClient) ReadBool(address string) (bool, error)

func (*MitsubishiClient) ReadFloat32

func (client *MitsubishiClient) ReadFloat32(address string) (float32, error)

func (*MitsubishiClient) ReadFloat64

func (client *MitsubishiClient) ReadFloat64(address string) (float64, error)

func (*MitsubishiClient) ReadInt16

func (client *MitsubishiClient) ReadInt16(address string) (int16, error)

func (*MitsubishiClient) ReadInt32

func (client *MitsubishiClient) ReadInt32(address string) (int32, error)

func (*MitsubishiClient) ReadInt64

func (client *MitsubishiClient) ReadInt64(address string) (int64, error)

func (*MitsubishiClient) ReadUInt16

func (client *MitsubishiClient) ReadUInt16(address string) (uint16, error)

func (*MitsubishiClient) ReadUInt32

func (client *MitsubishiClient) ReadUInt32(address string) (uint32, error)

func (*MitsubishiClient) ReadUInt64

func (client *MitsubishiClient) ReadUInt64(address string) (uint64, error)

func (*MitsubishiClient) SendPackageReliable

func (client *MitsubishiClient) SendPackageReliable(command []byte) ([]byte, error)

func (*MitsubishiClient) SendPackageSingle

func (client *MitsubishiClient) SendPackageSingle(command []byte, receiveCount int) ([]byte, error)

func (*MitsubishiClient) Write

func (client *MitsubishiClient) Write(address string, data []byte, isBit bool) ([]byte, error)

func (*MitsubishiClient) WriteValue

func (client *MitsubishiClient) WriteValue(address string, value interface{}) (err error)

type MitsubishiMCAddress

type MitsubishiMCAddress struct {
	TypeCode     []byte
	BitType      byte
	Format       int
	BeginAddress int
	TypeChar     string
}

func ConvertArg_A_1E

func ConvertArg_A_1E(address string) MitsubishiMCAddress

func ConvertArg_Qna_3E

func ConvertArg_Qna_3E(address string) MitsubishiMCAddress

type MitsubishiVersion

type MitsubishiVersion int

MitsubishiVersion is an enum type for the different versions of the Mitsubishi protocol.

const (
	Undefined MitsubishiVersion = iota
	A_1E
	Qna_3E
)

Directories

Path Synopsis
cmd
example command
sample command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL