Skip to content

Commit

Permalink
Merge pull request #3 from mariomoureperez/master
Browse files Browse the repository at this point in the history
Use custom port
  • Loading branch information
xtrinch committed Sep 15, 2017
2 parents f70b415 + c605530 commit 15ea932
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/com/sourceforge/snap7/moka7/S7Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class S7Client
private DataOutputStream OutStream = null;

private String IPAddress;
private int TCPPort;

private byte LocalTSAP_HI;
private byte LocalTSAP_LO;
Expand Down Expand Up @@ -340,7 +341,7 @@ public static String ErrorText(int Error)

private int TCPConnect()
{
SocketAddress sockaddr = new InetSocketAddress(IPAddress, ISOTCP);
SocketAddress sockaddr = new InetSocketAddress(IPAddress, TCPPort);
LastError=0;
try {
TCPSocket = new Socket();
Expand Down Expand Up @@ -582,10 +583,15 @@ public void Disconnect()
}
}

public int ConnectTo(String Address, int Rack, int Slot)
public int ConnectTo(String Address, int Rack, int Slot) {
//Use the default port
return ConnectTo(Address, Rack, Slot, ISOTCP);
}

public int ConnectTo(String Address, int Rack, int Slot,int Port)
{
int RemoteTSAP=(ConnType<<8)+ (Rack * 0x20) + Slot;
SetConnectionParams(Address, 0x0100, RemoteTSAP);
SetConnectionParams(Address, Port, 0x0100, RemoteTSAP);
return Connect();
}

Expand All @@ -594,11 +600,15 @@ public int PDULength()
return _PDULength;
}

public void SetConnectionParams(String Address, int LocalTSAP, int RemoteTSAP)
public void SetConnectionParams(String Address, int LocalTSAP, int RemoteTSAP) {
SetConnectionParams(Address, ISOTCP, LocalTSAP, RemoteTSAP);
}
public void SetConnectionParams(String Address, int Port, int LocalTSAP, int RemoteTSAP)
{
int LocTSAP = LocalTSAP & 0x0000FFFF;
int RemTSAP = RemoteTSAP & 0x0000FFFF;
IPAddress = Address;
TCPPort = Port;
LocalTSAP_HI = (byte) (LocTSAP>>8);
LocalTSAP_LO = (byte) (LocTSAP & 0x00FF);
RemoteTSAP_HI= (byte) (RemTSAP>>8);
Expand Down

0 comments on commit 15ea932

Please sign in to comment.