Port status

GETPORTSTATUS

This function gets the communication status of a handle. The most common return values are described below, other values are representing internal errors.

Input Type Description
HANDLEIO.COMMHANDLEParameters of the current communication
OutputTypeDescription
INT 0 (OK)
25 (port could not be opened)
31 (empty buffer)
34 (busy - data are being sent)
PROGRAM main
(program's body)
 var
 def : string;
 handle : io.commhandle;
 state : int := 0;
 data : array[0..31] of byte;
 dataRecv : array[0..31] of byte;
 received : int;
 end_var
case state of
    0: 
        (*def := 'tcp:192.168.1.4:7';*)
        (*def := 'udp:192.168.1.4:7';*)
        def := 'serial:10:9600,8,N,1';
        handle := io.openport(def);
        if handle >= 0 then
            state := 1;
        end_if;
    1:
         if io.getportstatus(handle) = 0 then (* OperationStatus_Ok *)
             (* connection established *)
             data[0] := 5;
             data[1] := 10;
             data[2] := 6;
             data[3] := 11;
             if io.writeport(handle, adr data[0], 10) then
                 state := 2;
             end_if;
         end_if;
     2:
         if io.getportstatus(handle) = 0 then (* OperationStatus_Ok *)
             (* all data sent *)
            state := 3;
         end_if;
     3:
         received := io.readport(handle, adr dataRecv[0], 20);
         if received > 0 then
             (* some data received *)
             io.closeport(handle);
             state := 4;
         else
             io.getportstatus(handle);
         end_if;
     else
         state := 4;
end_case;
END_PROGRAM
  • © Energocentrum Plus, s.r.o. 2017 - 2024