io.writeport TCP
-
Hello all!
I'm trying to implement a very simple ASCII tcp protocoll to control some ali-express ethernet relais.
The protocoll is very very easy, no security.ASCII string: 11 pulls relay 1
ASCII string: 21 releases relay 1So, this works when using packetsender from my phone, works when using packetsender from my laptop. But it doesn't work using io.writeport from a ST file.
Using wireshark i found out that communication is working, but the packets are not valid (len=0). So i'm doing something wrong.
The code sending the string is as follows:
FUNCTION_BLOCK EthernetRelais (* EXTENDS //base type IMPLEMENTS //interface type list *) VAR connection : string; conn_handle : io.commhandle; fsm : int := 0; command : array[0..10] of byte; local_state : byte := 0; initial : bool := 1; portstatus : int; timeout : int; i : int; (* add local variables here *) END_VAR VAR_INPUT (* add in variables here *) state : bool; END_VAR VAR_OUTPUT (* add out variables here *) current_state : bool; END_VAR case fsm OF 0: if state <> local_state or initial THEN local_state := state; fsm := 1; initial := false; timeout := 1000; END_IF; 1: connection := 'tcp:192.168.1.5:6722'; conn_handle := io.openport(connection); fsm := 2; 2: portstatus := io.getportstatus(conn_handle); if portstatus = 0 THEN fsm := 3; END_IF; timeout := timeout -1; if timeout = 0 THEN io.closeport(conn_handle); fsm := 0; END_IF; 3: if local_state = 1 THEN command[0] := 49; command[1] := 49; ELSE command[0] := 50; command[1] := 49; END_IF; io.writeport(conn_handle,adr command[0],10); io.closeport(conn_handle); fsm := 0; ELSE fsm := 0; end_case; (* METHOD abc //: return type // method's body END_METHOD *) (*function block body*) END_FUNCTION_BLOCKThis is the output of wireshark:
192.168.1.5 is my laptop
192.168.1.7 is my unipi
This is the communication of the ST code only. No idea why everything has zero length. And my data is nowhere to be found in the packages.
Any help would be appreciated!
Regards,
Jasper Jackson
-
@jasperjackson said in io.writeport TCP:
io.writeport(conn_handle,adr command[0],10);
Got it... one has to keep calling
io.writeport(conn_handle,adr command[0],10);
until it returns true :)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login