RobotStudio event

S4C + PC serial communication

Options
Hello everyone,

i have a S4C controller with a IRB1400 M97A and i want read information from PC by RS232.

i allready instaled Advanced Functions but i can't create instruction like VAR or OPEN or etc.

Someone can help me with sequence to create simple program to read from RS232?


thanks,
Emanuel Machado

Answers

  • Micky
    Micky ✭✭✭
    Options
    Hello,
    here are some examples to read data from a serial port.

      VAR iodev deRS232;

      Open "sio1:", deRS232\Read;

      stData:=ReadStr(deRS232\Time:=30);

      nData:=ReadNum(deRS232\Time:=30);

      Close deRS232;


    You could aslo read and write binary data via the same channel:

    Sending  "Hello world" to the partner.


      VAR iodev deRS232;

      VAR num nOutBuffer{20};

      VAR num nInput;

      Open "sio1:", deRS232\Bin;

      nOutBuffer {1} := 5;  !( ENQ )

      WriteBin deRS232, nOutBuffer, 1;

      nInput := ReadBin (deRS232\Time:= 0.1);

      IF nInput = 6 THEN  !( ACK )

        nOutBuffer {1} := 2; ! ( STX )

        nOutBuffer {2} := 72; !( ’H’ )

        nOutBuffer {3} := 101; ! ( ’e’ )

        nOutBuffer {4} := 108;  !( ’l’ )

        nOutBuffer {5} := 108;  !( ’l’ )

        nOutBuffer {6} := 111;  !( ’o’ )

        nOutBuffer {7} := 32;  !( ’ ’ )

        nOutBuffer {8} := StrToByte("w"\Char);  !( ’w’ )

        nOutBuffer {9} := StrToByte("o"\Char);  !( ’o’ )

        nOutBuffer {10} := StrToByte("r"\Char);  !( ’r’ )

        nOutBuffer {11} := StrToByte("l"\Char);  !( ’l’ )

        nOutBuffer {12} := StrToByte("d"\Char);  !( ’d’ )

        nOutBuffer {13} := 3;  ( ETX )

        WriteBin deRS232, nOutBuffer, 13;

      ENDIF

      Close deRS232;


    Besrt regards
    Micky