HOw pulling data from TCP Connection?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

HOw pulling data from TCP Connection?

Post by gilar » Sun Sep 02, 2018 11:56 am

I'm trying to get Data from Race Timing System (Elite V3 Software)
which is this data will sent by "Elite V3 Sofware" periodically

Then i'm buld Client software with TCP connection
I've succeeded connect "Elite V3 Software" and Data sent to Livecode Client into my Log
Data sent periodically into a text field

this data on log sent would be like this
***** PASING BEGIN *****
1;2A;GILAR KADARSAH;2;345.56;2;50
2;7B;FAJAR RIFAI;3;112.23;1;76
***** PASING END *****
(*Separe by ;)

What i'm asking is
Could we pulling this data every time Passing begin
1;2A;GILAR KADARSAH;2;345.56;2;50
2;7B;FAJAR RIFAI;3;112.23;1;76
and put it into Data Grid

Comment and Help would be appreciate



Best Regards



Gilar Kadarsah
Gilar | from INDONESIA

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: HOw pulling data from TCP Connection?

Post by Klaus » Sun Sep 02, 2018 3:43 pm

Hi Gilar,

if the date will go into a field then you could maybe use the "textchanged" message in the field?
Out of my head, script of text field:

Code: Select all

on textchanged
  ## Ignore first and last line:
  put line 2 to -2 of me into tData
  replace ";" with TAB in tData
  set the dgText of grp "Your datagrid here" to tData
end textchanged
If that is not what you want, please explain.


Best

Klaus

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: HOw pulling data from TCP Connection?

Post by gilar » Sun Sep 02, 2018 6:10 pm

Hi Klause .... Thank you for replay

On TextChanged seem not works form me ....
As far as I know, ontextchanged will apply when we type something on text field
then script will work. Please corect me if i'm wrong.

this message is automatically put by TCP connection into a text field
***** PASING BEGIN *****
1;2A;GILAR KADARSAH;2;345.56;2;50
2;7B;FAJAR RIFAI;3;112.23;1;76
***** PASING END *****

and also i want to know if client received message 2,3, or 4 times
Can i use this code

Code: Select all

 ## Ignore first and last line:
  put line 2 to -2 of me into tData
I mean the message on Log (a textfield)
would be like this

Code: Select all

***** PASING BEGIN *****
2A;GILAR KADARSAH;1;50.256
7B;FAJAR RIFAI;1;51.123
***** PASING END *****
***** PASING BEGIN *****
2A;GILAR KADARSAH;2;51.457
7B;FAJAR RIFAI;2;52.012
***** PASING END *****
***** PASING BEGIN *****
2A;GILAR KADARSAH;3;53.225
7B;FAJAR RIFAI;3;54.021
***** PASING END *****
Gilar | from INDONESIA

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: HOw pulling data from TCP Connection?

Post by Klaus » Sun Sep 02, 2018 6:27 pm

Hi Gilar,
Klause
sigh...
On TextChanged seem not works form me ....
As far as I know, ontextchanged will apply when we type something on text field
then script will work. Please correct me if i'm wrong.
Yes, true, sorry, my fault.
Then use the handler which writes the data to the field to "trigger" your action.
and also i want to know if client received message 2,3, or 4 times
Count the "#### Begin..." lines:
...
put fld "whatever" into tData
filter tData with "***** PASING BEGIN *****"
answer" User received message" &&the num of lines of tData && "times."
...
Best

Klaus (with no E!)

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: HOw pulling data from TCP Connection?

Post by gilar » Sun Sep 02, 2018 6:48 pm

Hi Klaus :) ..... Thanks for Quick Replay...
Then i'll try of what you say ... doing some trial and error too.
Thanks for guiding me into right direction.
God bless you ...
Gilar | from INDONESIA

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: HOw pulling data from TCP Connection?

Post by gilar » Mon Sep 03, 2018 3:38 am

Hi ... Klaus
Then use the handler which writes the data to the field to "trigger" your action.
Sorry could you explain more about this. or give an examlpe.
FYI, my Livecode Client only receive Data from Elite. and I can not manipulate Incoming text on Log.
...
put fld "whatever" into tData
filter tData with "***** PASING BEGIN *****"
answer" User received message" &&the num of lines of tData && "times."
...
Sorry, It seem is not what i need... maybe a litle bit miss understand.


Imagine a race ......
We have about 20-30 racer
And we put a transponder into every racer
Then when the racer passes our detector,
Transponder will send data into Race Timing System and
then sent it into Livecode Client.

This is the Data which sent by Racer (Transponder)

Code: Select all

*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
13A;OKTAVIANO RIZQY;1;33393
*** PASSINGS END ***
On Livecode Client LOG (a text field)
This data is always change (dynamic), the text will increase, NOT replace the old one.
data will incoming ... incoming ... incoming again

this is the original Data which copied from Livecode Client.

Code: Select all

*** MESSAGE BEGIN ***
06:23:18>GREEN FLAG 
*** MESSAGE END ***
*** RACE INFORMATION BEGIN ***
WARM UP;11. ALL NEW R15 IDEMITSU JUNIOR PRO;0;0;600000;10;GREEN FLAG;636715525985245868;86ef01c3-43f6-44e2-84d5-302a06857e8c;b2d03d9d-e3d6-4d7c-924c-0ab42a21ad8f;0;YELLOW TURN
*** RACE INFORMATION END ***
*** FOLDER INFORMATION BEGIN ***
86ef01c3-43f6-44e2-84d5-302a06857e8c;SENTUL INTL CIRCUIT - BOGOR (3.95 km)
0;1;1;0;1;1;0;2;1;;;;;;
;;;;0;;;;;0;;;;;0;;;;;0;;;;;0;;;;;0;;;;;0;;;;;0;;;;;0;;;;;0
*** FOLDER INFORMATION END ***
*** RACE INFORMATION BEGIN ***
WARM UP;11. ALL NEW R15 IDEMITSU JUNIOR PRO;5008;0;594992;10;GREEN FLAG;636715526035325868;86ef01c3-43f6-44e2-84d5-302a06857e8c;b2d03d9d-e3d6-4d7c-924c-0ab42a21ad8f;0;YELLOW TURN
*** RACE INFORMATION END ***
*** RACE INFORMATION BEGIN ***
WARM UP;11. ALL NEW R15 IDEMITSU JUNIOR PRO;5008;1;594992;10;GREEN FLAG;636715526035325868;86ef01c3-43f6-44e2-84d5-302a06857e8c;b2d03d9d-e3d6-4d7c-924c-0ab42a21ad8f;0;YELLOW TURN
*** RACE INFORMATION END ***
*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
1A;WAHYU NUGROHO;1;2459
*** PASSINGS END ***
*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
2A;MUHAMMAD SAIRAJI;1;6425
*** PASSINGS END ***
*** RACE INFORMATION BEGIN ***
WARM UP;11. ALL NEW R15 IDEMITSU JUNIOR PRO;11000;1;589000;10;GREEN FLAG;636715526095245868;86ef01c3-43f6-44e2-84d5-302a06857e8c;b2d03d9d-e3d6-4d7c-924c-0ab42a21ad8f;0;YELLOW TURN
*** RACE INFORMATION END ***
*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
4A;M. GILANG AKBAR ROLAND;1;9295
*** PASSINGS END ***
*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
6A;BONE FIZER MIOLO;1;13204
*** PASSINGS END ***
*** RACE INFORMATION BEGIN ***
WARM UP;11. ALL NEW R15 IDEMITSU JUNIOR PRO;16995;1;583005;10;GREEN FLAG;636715526155195868;86ef01c3-43f6-44e2-84d5-302a06857e8c;b2d03d9d-e3d6-4d7c-924c-0ab42a21ad8f;0;YELLOW TURN
*** RACE INFORMATION END ***
*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
8A;NIA RAMADHANI;1;16427
*** PASSINGS END ***
*** RACE INFORMATION BEGIN ***
WARM UP;11. ALL NEW R15 IDEMITSU JUNIOR PRO;22996;1;577004;10;GREEN FLAG;636715526215205868;86ef01c3-43f6-44e2-84d5-302a06857e8c;b2d03d9d-e3d6-4d7c-924c-0ab42a21ad8f;0;YELLOW TURN
*** RACE INFORMATION END ***
*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
7A;ADITYA DWI CAHYADI;1;19954
*** PASSINGS END ***
*** RACE INFORMATION BEGIN ***
WARM UP;11. ALL NEW R15 IDEMITSU JUNIOR PRO;28992;1;571008;10;GREEN FLAG;636715526275165868;86ef01c3-43f6-44e2-84d5-302a06857e8c;b2d03d9d-e3d6-4d7c-924c-0ab42a21ad8f;0;YELLOW TURN
*** RACE INFORMATION END ***
*** RACE INFORMATION BEGIN ***
WARM UP;11. ALL NEW R15 IDEMITSU JUNIOR PRO;34986;1;565014;10;GREEN FLAG;636715526335105868;86ef01c3-43f6-44e2-84d5-302a06857e8c;b2d03d9d-e3d6-4d7c-924c-0ab42a21ad8f;0;YELLOW TURN
*** RACE INFORMATION END ***
*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
13A;OKTAVIANO RIZQY;1;33393
*** PASSINGS END ***
*** RACE INFORMATION BEGIN ***
WARM UP;11. ALL NEW R15 IDEMITSU JUNIOR PRO;39991;1;560009;10;GREEN FLAG;636715526385155868;86ef01c3-43f6-44e2-84d5-302a06857e8c;b2d03d9d-e3d6-4d7c-924c-0ab42a21ad8f;0;YELLOW TURN
*** RACE INFORMATION END ***
*** RACE INFORMATION BEGIN ***
WARM UP;11. ALL NEW R15 IDEMITSU JUNIOR PRO;43986;1;556014;10;GREEN FLAG;636715526425105868;86ef01c3-43f6-44e2-84d5-302a06857e8c;b2d03d9d-e3d6-4d7c-924c-0ab42a21ad8f;0;YELLOW TURN
*** RACE INFORMATION END ***
*** RESULTS BEGIN *** (20)
Numero;Nom;TotalNbTour;TotalTpsCumule;TpsPiste;TriMulti;Groupe;Categorie;Classe
1A;WAHYU NUGROHO;1;2459;2459;;YMH YAMALUBE NHK IRC DID NISSIN NGK BAHTERA RT;JATENG;
2A;MUHAMMAD SAIRAJI;1;6425;6425;;BOB's R7 RACING SCHOOL;;
4A;M. GILANG AKBAR ROLAND;1;9295;9295;;YMH ADITAMA ANTASARI STICKER RT;KALTIM;
6A;BONE FIZER MIOLO;1;13204;13204;;HENDRIANSYAH RACING SCHOOL;DKI;
8A;NIA RAMADHANI;1;16427;16427;;N'RPM YAMAHA ALFA SCORPII NHK IRC;SUMUT;
7A;ADITYA DWI CAHYADI;1;19954;19954;;D45 RACING ACADEMY;JATIM;
13A;OKTAVIANO RIZQY;1;33393;33393;;REY RACING SCHOOL;DKI;
3A;MUHAMAD ANDRIAS LUKITO;0;2000000000;0;;YMH YAMALUBE ORYZA NISSIN IRC DID KYT;JATENG;
5A;ARYASENA ARJUNA SETYAJI;0;2000000000;0;;REY RACING SCHOOL;JABAR;
9A;SEPTA PUTRA EKA JATI;0;2000000000;0;;REY RACING SCHOOL;;
10A;CANDRA HERMAWAN;0;2000000000;0;;PUJI RAHAYU MELINDO EDOMIX D45 RACING ACADEMY;JATIM;
11A;MUHAMMAD RESKI AWAL;0;2000000000;0;;BOB's R7 RACING SCHOOL;SULSEL;
12A;MUHAMMAD FAIZ ZULFIKAR;0;2000000000;0;;BOB's R7 RACING SCHOOL;KALTIM;
14A;KIKI ARANXA;0;2000000000;0;;BOB's R7 RACING SCHOOL;JATIM;
15A;FAHMI BASAM;0;2000000000;0;;YAMAHA PRS OYEHE NABIRE;SULSEL;
16A;MUHAMAD ILHAM EFENDI;0;2000000000;0;;D45 RACING ACADEMY;JATENG;
17A;MOHD SILMI HELSINKY;0;2000000000;0;;BOB's R7 RACING SCHOOL;ACEH;
18A;ANDI MAHMUD MAPPEGANTI Y;0;2000000000;0;;AKAIJAYA RT;SULTENG;
19A;MUHAMMAD RIDWAN;0;2000000000;0;;REY RACING SCHOOL;JABAR;
20A;M IRGI SEPTDAJI PUTRA;0;2000000000;0;;REY RACING SCHOOL;JABAR;
*** RESULTS END ***
After livecode client received data from Racer (Transponder)
I have to put it into DataGrid again ... and again ... and again
Any idea how to filter and grab it it ...

Sorry for my English and hope you could understand what i mean....
I'll explain more if necessary ...


Best Regards


Gilar Kadarsah
Gilar | from INDONESIA

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How pulling data from TCP Connection?

Post by Klaus » Mon Sep 03, 2018 11:50 am

Hi Gilar,
gilar wrote:
Mon Sep 03, 2018 3:38 am
Then use the handler which writes the data to the field to "trigger" your action.
Sorry could you explain more about this. or give an examlpe.
FYI, my Livecode Client only receive Data from Elite. and I can not manipulate Incoming text on Log.
so there is no Livecode script involded? The data magically appear in that field? Really?
...
put fld "whatever" into tData
filter tData with "***** PASING BEGIN *****"
answer" User received message" &&the num of lines of tData && "times."
...
Sorry, It seem is not what i need... maybe a litle bit miss understand.
Simply because you did not provide sufficient info, the log below looks a lot different than the one you posted first! 8)

What exactly do you need to count?
We now have "MESSAGE", "PASSING", "FOLDER INFORMATION", "RESULTS" and "RACE INFORMATION"!
In any case you need to count the lines with "***** XYZ BEGIN *****" in it with FILTER like in my first example.

And which of these data do you need to put into the datagrid?


Best

Klaus

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: How pulling data from TCP Connection?

Post by gilar » Tue Sep 04, 2018 1:17 am

Hi again Kalus ....
Thank you for being patient for me .... :)
so there is no Livecode script involded? The data magically appear in that field? Really?
:) Sorry ... it comes from TCP connection, I just not clearly understand where and put the script.
What exactly do you need to count?
Sorry... not count, but replace old data with the new one

Let say in log incoming data

Code: Select all

13A;OKTAVIANO RIZQY;1;33393
this is about recording time and laps

Than when this data incoming again at second time (but it does not need to count)

Code: Select all

13A;OKTAVIANO RIZQY;2;54687
I want replace the old one with new one
We now have "MESSAGE", "PASSING", "FOLDER INFORMATION", "RESULTS" and "RACE INFORMATION"!
In any case you need to count the lines with "***** XYZ BEGIN *****" in it with FILTER like in my first example.

And which of these data do you need to put into the datagrid?
this Data

Code: Select all

13A;OKTAVIANO RIZQY;1;33393 
and this Data

Code: Select all

1A;WAHYU NUGROHO;1;2459;2459;;YMH YAMALUBE NHK IRC DID NISSIN NGK BAHTERA RT;JATENG;
2A;MUHAMMAD SAIRAJI;1;6425;6425;;BOB's R7 RACING SCHOOL;;
4A;M. GILANG AKBAR ROLAND;1;9295;9295;;YMH ADITAMA ANTASARI STICKER RT;KALTIM;
6A;BONE FIZER MIOLO;1;13204;13204;;HENDRIANSYAH RACING SCHOOL;DKI;
8A;NIA RAMADHANI;1;16427;16427;;N'RPM YAMAHA ALFA SCORPII NHK IRC;SUMUT;
7A;ADITYA DWI CAHYADI;1;19954;19954;;D45 RACING ACADEMY;JATIM;
13A;OKTAVIANO RIZQY;1;33393;33393;;REY RACING SCHOOL;DKI;
3A;MUHAMAD ANDRIAS LUKITO;0;2000000000;0;;YMH YAMALUBE ORYZA NISSIN IRC DID KYT;JATENG;
5A;ARYASENA ARJUNA SETYAJI;0;2000000000;0;;REY RACING SCHOOL;JABAR;
9A;SEPTA PUTRA EKA JATI;0;2000000000;0;;REY RACING SCHOOL;;
10A;CANDRA HERMAWAN;0;2000000000;0;;PUJI RAHAYU MELINDO EDOMIX D45 RACING ACADEMY;JATIM;
11A;MUHAMMAD RESKI AWAL;0;2000000000;0;;BOB's R7 RACING SCHOOL;SULSEL;
12A;MUHAMMAD FAIZ ZULFIKAR;0;2000000000;0;;BOB's R7 RACING SCHOOL;KALTIM;
14A;KIKI ARANXA;0;2000000000;0;;BOB's R7 RACING SCHOOL;JATIM;
15A;FAHMI BASAM;0;2000000000;0;;YAMAHA PRS OYEHE NABIRE;SULSEL;
16A;MUHAMAD ILHAM EFENDI;0;2000000000;0;;D45 RACING ACADEMY;JATENG;
17A;MOHD SILMI HELSINKY;0;2000000000;0;;BOB's R7 RACING SCHOOL;ACEH;
18A;ANDI MAHMUD MAPPEGANTI Y;0;2000000000;0;;AKAIJAYA RT;SULTENG;
19A;MUHAMMAD RIDWAN;0;2000000000;0;;REY RACING SCHOOL;JABAR;
20A;M IRGI SEPTDAJI PUTRA;0;2000000000;0;;REY RACING SCHOOL;JABAR;
here i create video that showing the LOG TEXT FIELD
https://www.youtube.com/watch?v=Em520_tO6Y4
Hope it'll explain more ....


Best Regards


Gilar Kadarsah
Gilar | from INDONESIA

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: HOw pulling data from TCP Connection?

Post by Klaus » Tue Sep 04, 2018 8:57 am

Hi Gilar,
so there is no Livecode script involded? The data magically appear in that field? Really?
Sorry ... it comes from TCP connection,...
please answer my questions, or I cannot help you!
Does an external application (NOT Livecode) fill the "LOG" field in your Livecode application?
If yes, how?
What exactly do you need to count?
Sorry... not count, but replace old data with the new one
Are you sure, in every posting you seem to tell me something different?
I have no idea what, when and where to replace.

I think the first questions above are the most important ones!


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: HOw pulling data from TCP Connection?

Post by jacque » Tue Sep 04, 2018 4:18 pm

Welcome Gilar,

You said you were able to get the data into a LC field. How did you do that? Did you write a script in the LC stack? How did you connect the Elite software to the stack?

The video looks like you are just copying and pasting text manually. Is that true? If so then the solution is different from automatic entries. But first we need to know how the data gets from the framework to the stack.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: How to pulling data from TCP Connection?

Post by gilar » Tue Sep 04, 2018 7:18 pm

Hi Klaus
please answer my questions, or I cannot help you!
Does an external application (NOT Livecode) fill the "LOG" field in your Livecode application?
If yes, how?
Yes an external aplication fill the "LOG" field on my Livecode applicaion.
Live Code application connect to esternal application with TCP connection
Then external application passing data into the "LOG"

here is the TCP code

Code: Select all

on openStack

end openStack

command connectIt
   if field IP is among the lines of the opensockets then
      close socket field IP
      set the label of button "Connect" to "Connect"
      set the backgroundcolor of button "Connect" to red
   else
      open socket to field IP
            set the label of button "Connect" to "Disconnect"
            set the backgroundcolor of button "Connect" to green
      if the Result <> "" then
         put "result:" && the result
      else
         readLoop
      end if
   end if
end connectIt

command readLoop
   if field IP is among the lines of the opensockets then
      read from socket field IP until empty
      put it after field "logField"
      ---
      write "$3"  & format("\r\n") to socket field IP of card setting_crd
      ----
      send "readLoop" to me in 50 milliseconds
   end if
end readLoop
Are you sure, in every posting you seem to tell me something different?
Yup, sorry ... i can explain good enaugh in English.
I have no idea what, when and where to replace.
every time external application passing this data:

Code: Select all

*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
1A;WAHYU NUGROHO;1;2459
*** PASSINGS END ***
I want to Grab and put it into Data Grid
1A;WAHYU NUGROHO;1;2459
Notes: This is Racer Data Time Record
1A = Motor Number
WAHYU NUGROHO = Racer Name
1 = Number of Laps
2459 = Time

There are about 20-30 racer ....
every time racer passes the start line ( let say this race has 20 laps)
external application will passing data into the "LOG" field in livecode application

So what livecode must do when external application passing data into the "LOG" is ....
1. On first lap
- Grab and put every racer Data into DataGrid / Table
There are 20-30 racer, so it'll be about 20-30 line in DataGrid

2. On 2nd, 3rd, 4th ..... 20th lap
- Update time record and laps number for every racer


Best Regards


Gilar Kadarsah
Gilar | from INDONESIA

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: HOw pulling data from TCP Connection?

Post by Klaus » Tue Sep 04, 2018 7:37 pm

Hi Gilar,

AHA, we are getting nearer! :D

OK, so your Livecode application receives the data and of course processes it!
Thank you for this info, although it was really hard to get it. 8)

Okie Dokie, we need to "hook" into your "readLoop" handler right before putting IT into your log field.

Code: Select all

command readLoop

  ## Get used to put QUOTES around object names, if you don't, this may BITE you some day!
   if field "IP" is among the lines of the opensockets then
      read from socket field "IP" until empty

     ## I put the data into a variable, since IT will change
     put it into tData

     ## Now process the data and put it into (or AFTER) the datagrid, see handler below:
     put_into_datagrid tData
     
     put tData after field "logField"
...

Code: Select all

command put_into_datagrid tData
   ## First check if we have a PASSING BEGIN data
   ## get rid of possible empty lines:
   filter tData without empty
   
   ## Now check for PASSING:
   if NOT (line 1 of tData begins with "*** PASSINGS BEGIN ***") then
      exit put_into_datagrid
   end if
   
   ## Now ignore line 1 and 2 and the LAST line
   put line 3 to -2 of tData into tData2
   
   ## Make data Datagrid ready:
   replace ";" with TAB in tData2
   put the dgtext of grp "your dg here..." into tDGT
   if tDGT = EMTPY then
      
      ## DG emtpy, put into DG:
      put tData2 into tDGT
   else
      
      ## Append data:
      put CR & tData2 after tDGT
   end if
   set the dgtext of grp "your dg here..." to tDGT
end put_into_datagrid
Out of my head, so please check for typos, but in general that should work for you.
If you have problems with the rest, please ask!

P.S.
The missing infos did not have to do anything with your english! 8)


Best

Klaus

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: HOw pulling data from TCP Connection?

Post by gilar » Tue Sep 04, 2018 8:45 pm

Hi Klaus .....
Your code works like a charm ...
Thank You very much ....
but it still have a problem for me ...

On update for 2nd, 3rd, 4th etc. Laps
It mean on 2nd, 3rd, 4nd passing ....
In DataGrid there is double name or more
https://drive.google.com/open?id=13u9eq ... 4pjA04nsUo
what i want is only update number of laps and time record

And also there is an empty space on table
Is that any way to fix it?

Best Regards


Gilar Kadarsah
Gilar | from INDONESIA

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How pulling data from TCP Connection?

Post by Klaus » Tue Sep 04, 2018 9:17 pm

Hi Gilar,
gilar wrote:
Tue Sep 04, 2018 8:45 pm
...
On update for 2nd, 3rd, 4th etc. Laps
It mean on 2nd, 3rd, 4nd passing ....
In DataGrid there is double name or more
https://drive.google.com/open?id=13u9eq ... 4pjA04nsUo
what i want is only update number of laps and time record
hm, I really like to help, but don't you think that this is going a bit too far for a "little help in the forum"?

I ususally do this kind of work, and what you ask for is a bit more complex than my other script, for a living, means for money!

Hints:
Extract the NAME from tData and look for this name in the data of the datagrid -> tDGT
Maybe with lineoffset, then do your thing with the found line if any, means update the ITEMS of that line with the new number of laps etc. before writing the data back into the datagrid.

All this should happen in my "put_into-datagrid" handler, of course!
gilar wrote:
Tue Sep 04, 2018 8:45 pm
And also there is an empty space on table
Is that any way to fix it?
Are you sure that there is no SPACE or any invisible character in the data?
Because my script explicitely filters out empty lines.

Maybe there is a CRLF instead of a simple CR, which may result in empty lines.
Add this to my handler to be sure:

Code: Select all

command put_into_datagrid tData
   replace CRLF with CR in tData

   ## First check if we have a PASSING BEGIN data
   ## get rid of possible empty lines:
   filter tData without empty
...
Best

Klaus

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: HOw pulling data from TCP Connection?

Post by jiml » Tue Sep 04, 2018 11:54 pm

Gilar,

You might want to use an array variable in memory to store the most recent data for each racer.
For example when this is received:
*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
13A;OKTAVIANO RIZQY;1;33393
*** PASSINGS END ***
The array could be structured with the value of Numero as the main Key.
So, parse this way:

Code: Select all

put "OKTAVIANO RIZQY" into raceArray["13A"]["Nom"]
put "1" into gRaceArray["13A"]["TotalNbTour"]
put "33393" into gRaceArray["13A"]["TotalTpsCumule"]
Then later when this comes in:
*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
13A;OKTAVIANO RIZQY;2;54687
*** PASSINGS END ***

Code: Select all

put "OKTAVIANO RIZQY" into raceArray["13A"]["Nom"]
put "2" into gRaceArray["13A"]["TotalNbTour"]
put "54687" into gRaceArray["13A"]["TotalTpsCumule"]
There will still only be one entry for 13A but TotalNbTour and TotalTpsCumule will be updated with the new data.
Since this variable is in memory and not in a datagrid of field it will update more quickly.
You can then transfer the data to a field or datagrid.

You also have the advantage of quickly getting any particular bit of information about a racer:

Code: Select all

put gRaceArray["13A"]["TotalTpsCumule"]
would return

Code: Select all

 54687
Say you received this:
*** PASSINGS BEGIN *** (1)
Numero;Nom;TotalNbTour;TotalTpsCumule
2A;GILAR KADARSAH;1;50.256
7B;FAJAR RIFAI;2;51.123
13A;OKTAVIANO RIZQY;3;54687
*** PASSINGS END ***

Code: Select all

global gRaceArray
on parsePassings receivedText
   set the itemdelimiter to ";"
   put line 2 of receivedText into pAttributes
   delete line 1 to 2 of receivedText
   delete line -1 of receivedText
   repeat for each line cRacer in receivedText
      repeat with x = 2 to the number of items of pAttributes
         put item x of cRacer into gRaceArray[item 1 of cRacer][item x of pAttributes]
      end repeat
   end repeat
end parsePassings
will give you an array of the current passings for every racer.

Hope this helps.
And welcome to the forum!

Jim Lambert

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”