Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How connect s7 smart200 plc #60

Closed
Ri0nGo opened this issue Jun 15, 2023 · 5 comments
Closed

How connect s7 smart200 plc #60

Ri0nGo opened this issue Jun 15, 2023 · 5 comments

Comments

@Ri0nGo
Copy link

Ri0nGo commented Jun 15, 2023

hi,I can't to connect s7 smart200 plc.
This my code:

func main() {
	handler := gos7.NewTCPClientHandler("192.168.2.123", 2, 0)
	handler.Timeout = 10 * time.Second
	err := handler.Connect()
	if err != nil {
		log.Printf("connect failed, device error: %s\n", err)
		panic(err)
	}
}

error info:
2023/06/15 19:38:16 *net.OpError read tcp 192.168.1.36:62273->192.168.2.123:102: wsarecv: An existing connection was forcibly closed by the remote host.
2023/06/15 19:38:16 connect failed, device error: ISO : Invalid PDU received
panic: ISO : Invalid PDU received

Using other client connections can succeed. May I ask if it was written incorrectly?
Looking forward to your reply, thanks.

@Ri0nGo Ri0nGo closed this as completed Jun 19, 2023
@Ri0nGo
Copy link
Author

Ri0nGo commented Jun 19, 2023

I konw how to connect smart200

@iicanf
Copy link

iicanf commented Sep 5, 2023

@Ri0nGo same error, how to connect?

@Ri0nGo
Copy link
Author

Ri0nGo commented Sep 5, 2023

修改源码,@iicanf

// NewTCPClientHandlerWithConnType allocates a new TCPClientHandler By Connection type
func NewTCPClientHandlerWithConnType(address string, rack int, slot int, ct string) *TCPClientHandler {
	h := &TCPClientHandler{}
	h.Address = address
	h.Timeout = tcpTimeout
	h.IdleTimeout = tcpIdleTimeout
	h.ConnectionType = connectionTypeOP
	//h.ConnectionType = connectionTypePG // Connect to the PLC as a PG

	remoteTSAP := uint16(h.ConnectionType)<<8 + (uint16(rack) * 0x20) + uint16(slot)
	h.setConnectionParameters(address, 0x0100, remoteTSAP)
	return h
}

@iicanf
Copy link

iicanf commented Sep 6, 2023

@Ri0nGo 谢谢,好使

@SaltySooda
Copy link

same issue!that works!
ps:
you also have to make sure that rack and slot number is right(gos7.NewTCPClientHandlerWithConnectType("127.0.0.1", 0, 0, 2)),i use 0,0 for new smart200 plc。
you will get ISO : Invalid PDU received if you set that wrong。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants