Port Communication (Serial & TCP)Port Communication (Serial & TCP)

This page is part of an incremental translation project. Body text not yet translated to Turkish falls back to English even in TR mode.

TROIA Platformu, serial port'lar üzerinden data gönderme/alma işlemlerini destekler. Ayrıca TCP Protocol kullanarak TCP port'ları üzerinden iletişim kurmak da mümkündür. Bu bölüm, serial ve TCP port'lar üzerinden iletişim kurmayı tanıtmayı amaçlarTROIA Platform supports sending/recieving data over serial ports. Also its possible to communicate over TCP ports using TCP Protocol. This sections aims to introduce communicating over serial and TCP ports

GirişIntroduction

Serial Port'ları Açma/KapatmaOpening/Closing Serial Ports

..serial port..serial port

OPENPORT {port} {portname} [ PARAMETERS [BAUDRATE {baudrate}]
                        [DATABITS {databits}]
                        [STOPBITS {stopbits}]
                        [PARITY NONE|ODD|EVEN|MARK|SPACE]
                        [FLOWCONTROL NONE|RTSCTSIN|RTSCTSOUT|XONXOFFIN|XONXOFFOUT]
                        [RTS {rts}]
                        [DTR {dtr}]
                        [ENCODING {encoding}]
                        [DEBUG TRUE|FALSE] ];
CLOSEPORT {portname};

Client'ta COM1 port'unu Aç/Kapat:Open/Close COM1 port on client:

OBJECT:
        STRING PORT,
        STRING PORTNAME;

PORTNAME = '*PORT';
PORT = 'COM1';
OPENPORT PORT PORTNAME PARAMETERS BAUDRATE '9600'
                                        DATABITS '8' STOPBITS '1' PARITY NONE;

CLOSEPORT PORTNAME;

TCP Port'larını Açma/KapatmaOpening/Closing TCP Ports

OPENPORT TCP {portname} PORT {portnumber} [IPADDRESS {ipaddress}] [ENCODING {encoding}];
CLOSEPORT {portname};

192.168.5.114'e bir tcp port'u açopen a tcp port to 192.168.5.114

OBJECT:
        STRING PORTNAME;

PORTNAME = '*PORTNAME';
OPENPORT TCP PORTNAME PORT 4848 IPADDRESS '192.168.5.114';
CLOSEPORT PORTNAME;

localhost'ta bir tcp port'u açopen a tcp port on localhost

OBJECT:
        STRING PORTNAME;

PORTNAME = '*PORTNAME';
OPENPORT TCP PORTNAME PORT 4848;

CLOSEPORT PORTNAME;

Port'tan Data OkumaReading Data From Port

READFROMPORT {portname} INTO {variable};

bir serial port'tan okuma.read from a serial port.

OBJECT:
        STRING PORT,
        STRING PORTNAME
        STRING RESULT;

PORTNAME = '*PORT';
PORT = 'COM1';
OPENPORT PORT PORTNAME PARAMETERS BAUDRATE '9600'
                                        DATABITS '8' STOPBITS '1' PARITY NONE;
INTEGERVAR1 = 0;
STRINGVAR3 = '';
RESULT  = '' ;

WHILE INTEGERVAR1 < 100
BEGIN
        READFROMPORT PORTNAME INTO RESULT;
        IF RESULT != '' THEN
                STRINGVAR3 = RESULT;
        ENDIF;
        DELAY 100;
        INTEGERVAR1 = INTEGERVAR1 + 1;
ENDWHILE;

CLOSEPORT PORTNAME;

bir tcp port'tan data okumaread data from a tcp port

OBJECT:
        STRING STRINGVAR3,
        STRING PORTNAME;

PORTNAME = '*PORTNAME';
OPENPORT TCP PORTNAME PORT 4848 IPADDRESS '192.168.5.114';
READFROMPORT PORTNAME TO STRINGVAR3;
CLOSEPORT PORTNAME;

Port'a Data YazmaWriting Data To Port

SENDTOPORT {portname} {content} [{timetowait}];

bir tcp port'a data yazmawrite data to a tcp port

OBJECT:
        STRING PORTNAME;

PORTNAME = '*PORTNAME';
OPENPORT TCP PORTNAME PORT 4848;
SENDTOPORT PORTNAME 'Hello World!';
CLOSEPORT PORTNAME;

Örnek 1: Socket Üzerinden Dosya AktarmaExample 1: Transfering File through Socket

Bu örnek, iki canias client arasında bir TCP connection üzerinden bir dosyanın tek bir satırını aktarır.This example transfers a single line of a file between two canias client through a TCP connection.

İşte transmitter için kod; bu transmitter tüm dosyayı okur ve receiver'a geçirir.Here is the code for transmitter, this transmitter reads the entire file and pass it to receiver.

OPEN FILE '*C:\TMP\tcp-example\korean.txt';
GETBLOCK STRINGVAR3,'' CODEPAGE 'ISO8859_9';
CLOSE FILE;

OBJECT:
        STRING PORTNAME;

PORTNAME = '*PORT1';
OPENPORT TCP PORTNAME PORT 50507 IPADDRESS '192.168.5.164' ENCODING 'ISO8859_9';
STRINGVAR1 = SYS_STATUS;
SENDTOPORT PORTNAME STRINGVAR3;
STRINGVAR2 = SYS_STATUS;
CLOSEPORT PORTNAME;

Ve receiver için kod; bu receiver tek bir satır okur ve tcp connection'ı keser, ardından satırı target dosyaya yazar.And the code for the receiver, this receiver reads a single line and breaks tcp connection, then writes the line to target file.

OBJECT:
        STRING PORTNAME;

PORTNAME = '*PORT1';
OPENPORT TCP PORTNAME PORT 50507 ENCODING 'ISO8859_9';

STRINGVAR3 = '';
WHILE 1 == 1
BEGIN
        READFROMPORT PORTNAME INTO STRINGVAR3;

        IF STRINGVAR3 != '' THEN
                BREAK;
        ENDIF;
ENDWHILE;
CLOSEPORT PORTNAME;

OPEN FILE '*C:\TMP\tcp-example\target.txt' FORNEW;
PUT STRINGVAR3,'' CODEPAGE 'ISO8859_9';
CLOSE FILE;