Serial communications memory use increases with time

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 22
Joined: Tue May 06, 2008 5:33 am
Location: Las Vegas
Contact:

Serial communications memory use increases with time

Post by tcbcats » Wed Jan 20, 2016 5:06 am

I am receiving a 40 byte serial packet at 9600 baud into my live code app every second.
I have used 5.5.3 through 7.1 and have observed what looks like a memory leak when the application is running and receiving serial data.
The same memory increase happens in development mode and in my stand alone application.
If the program is left to run it ends up hanging when the memory use increases 150 M bytes larger than the starting size.
The memory usage increases about 30 to 40 K in size with each packet received.
The application is not storing anything so the size of the program space should not increase with time. It is acting like some sort of log for all the received serial data is being generated internally.
I have confirmed that I am reading all serial data in the windows OS serial buffer and that I am reading the serial data faster than the incoming packet stream.
I am using a USB to serial adapter that I see as COM4 in the windows XP OS system. I don't think the USB dongle is at fault because other programs using the same dongle are stable in memory usage.
I use the windows task manager to monitor the application size in system memory.
Has anyone here checked the memory usage when receiving serial COM port data on an application in LC?
tcbcats

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

Re: Serial communications memory use increases with time

Post by jacque » Wed Jan 20, 2016 6:40 pm

What does the app do with the data when it's received? Are you running any kind of continuous repeat loop?

If you can post the relevant parts of the script we may be able to spot something.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 22
Joined: Tue May 06, 2008 5:33 am
Location: Las Vegas
Contact:

Re: Serial communications memory use increases with time

Post by tcbcats » Thu Jan 21, 2016 10:14 pm

This is the code in question.
The memory usage keeps increasing as the app runs.
It works the same on 7.0 through 8.0
I have tried several parse methods that all work. The leak seems to be coming from the read file for 1 part of the code.
The serial packet begins with a * and ends with a #.

Code: Select all

on readPort
     --set the backgroundColor of button RX1 to "red"
   put empty into TestNum
   put empty into TempChar
   --put empty into thePort
   
   if the hilite of btn "Port open" = true then
      put the label of btn "Port" into thePort
  
      read from file thePort for 1   -- looking for * as first chr of packet.
      put it into TempChar
   end if

      If TempChar = "*" then
         --lock screen
         put empty into TempChar         --clear TempChar var
         put empty into fld "recField"      -- clear recField
         set the backgroundColor of button RX to "green"
         
         put it after fld "recField"             -- this is first chr of RX packet. Should be chr *
         --lock screen
                  repeat with X= 0 to 65    --end chr is #
            read from file thePort for 1   -- read another one byte from serial port
            put it after fld "recField"       -- add to display window "recField" after last received byte
            put it into TestNum             -- value of last veceived char
            If TestNum = "#" then exit repeat
         end repeat
         
         --repeat until TestNum = "#"    --end chr is #
            --read from file thePort for 1   -- read another one byte from serial port
            --put it after fld "recField"       -- add to display window "recField" after last received byte
            --put it into TestNum             -- value of last veceived char
            
               set the backgroundColor of button RX to "white"
               
         --end repeat    --RX string is now captured. Start chr is *... end chr is #
         --wait 10 milliseconds with messages
         --unlock screen
            
            
               --set the backgroundColor of button RX1 to "red"
               --wait 2 milliseconds with messages
   
         put item 2 of fld "recField" into fld field1        --SPEED.
         
         put item 3 of fld "recField" into fld field2        --Turbo heatsink temperature
         
         put item 4 of fld "recField" into fld field3        --Hub heatsink temperature
         
         put item 5 of fld "recField" into fld field4        --Turbo motor temperature
         
         put item 6 of fld "recField" into fld field5        --Hub heatsink temperature
         
         put item 7 of fld "recField" into fld field6       --Hub motor temerature
         
         put item 8 of fld "recField" into fld field7       --Brake status
         put item 9 of fld "recField" into fld field13       --Battry voltage
         
         put item 15 of fld "recField" into fld field8
         put item 16 of fld "recField" into fld field9       --MODE
         
         --If item 6 of fld "recField" = 1  then        --Show ststus of China mode... on or off
         --put "ON" into fld C0
         --set the backgroundColor of fld "C0" to "green"
         --end if
         
         
         --******* STOP AND CLOSE SERIAL PORT AT THIS BYTE COUNT ****
         add 1 to field "DataCount"
         --if field "DataCount" >= 500 then      -- close serial port on this count
         --put empty into field "DataCount"
         --send MouseUp to button "Close Serial Port"
         --end if
         ---------------------------------------------------------------------------------------
         
         --put item 6 of fld "recField" into fld field5       --Show ststus of China mode... on or off
         
         --If item 6 of fld "recField" = 0  then --Turn off China mode
         --set the label of button "C0" to "Off"
         
         --put item 10 of fld "recField" into fld field10       --Filtered output out
         
         --put item 8 of fld "recField" into fld field11       --Raw Hall output
         
         --If item 10 of fld "recField" > 41  then
         -- set the backgroundColor of fld "Field10" to "green"
         --end if
         
         --If item 10 of fld "recField" <= 40  then
         --set the backgroundColor of fld "Field10" to "gray"
         --end if
         
         --If item 8 of fld "recField" > 41  then
         --set the backgroundColor of fld "Field11" to "green"
         --end if
         
         --If item 8 of fld "recField" <= 40  then
         --set the backgroundColor of fld "Field11" to "gray"
         --end if
         
         --put item 9 of fld "recField" into fld field8            --Volts
         
         --put Item 8 of fld "recField" into MyPowerHall      --Raw Hall output
         --put Item 7 of fld "recField" into MyPowerTH       -- Manual throttle output
         
         
         --put Item 10 of fld "recField" into MyPowerOut    --Filtered output
         --put Item 11 of fld "recField" into fld fieldA    --Sleep Time
         --put Item 12 of fld "recField" into fld field13    --Crank Speed
         --put Item 13 of fld "recField" into fld fieldM    --Ext Mag Pickup
         --put Item 14 of fld "recField" into fld field14    --Max Volts Out
         --put Item 15 of fld "recField" into fld field15    --Min Volts Out
         --put Item 16 of fld "recField" into fld field16    --Crank RPM Setting
         --put Item 17 of fld "recField" into fld field17    --Ext Mag Sense RPM
         --put Item 18 of fld "recField" into fld field18    --Sleep Time Seconds
         --put Item 19 of fld "recField" into fld field19    --Data Last field
         --put Item 20 of fld "recField" into fld field20    --Sleep Down Ticker
         --put Item 21 of fld "recField" into fld field21    --UNUSED Field
         --put Item 22 of fld "recField" into fld field22    --UNUSED Field
         --put Item 23 of fld "recField" into fld field23    --Max output flag message
         --put Item 24 of fld "recField" into fld field24    --UNUSED Field
         
         --Set the thumbpos of scrollbar "ProgressBarOut" to MyPowerOut 
         --Set the thumbpos of scrollbar "ProgressBarTH" to MyPowerTH
         --Set the thumbpos of scrollbar "ProgressBarHall" to MyPowerHall
         --put item 8 of fld "recField" into fld field6
         
         
         
         --if Item 23 of fld "recField" contains "AT"  then  --- Are we at full scale?
         --put item 23 of fld "recField" into fld field12
         --set the backgroundColor of fld "Field12" to "red"
         
         --if Item 12 of fld "recField" contains "AT"  then  --- Are we at full scale?
         --put item 12 of fld "recField" into fld field12
         --set the backgroundColor of fld "Field12" to "red"
         --else
         --put "Sensor in linear range output" into fld Field12
         --set the backgroundColor of fld "Field12" to "green"
         --end if
         
         
         --HUB ONLY
         If last char of fld "Field9" = "-"  then
            set the backgroundColor of button HubOnly to "green"
            set the label of button "HubOnly" to "OFF"
         end if
         
         If last char of fld "Field9" = "+"  then
            set the backgroundColor of button HubOnly to "red"
            set the label of button "HubOnly" to "ON"
         end if
         
         
         
         --TURBO ONLY
         If last char of fld "Field8" = "-"  then
            set the backgroundColor of button TurboOnly to "green"
            set the label of button "TurboOnly" to "OFF"
         end if
         
         If last char of fld "Field8" = "+"  then
            set the backgroundColor of button TurboOnly to "red"
            set the label of button "TurboOnly" to "ON"
         end if
         
                                    --BRAKE FIELD COLOR
                                     If last char of fld "Field7" = 0  then
                                        set the backgroundColor of field "field7" to "gray"
                                     end if
         
                                     If last char of fld "Field7" = 1  then
                                       set the backgroundColor of field "field7" to "red"
                                      end if
         
                                     
                                     --THROTTLE FIELD COLOR
                                       If last char of fld "Field2" = 0  then
                                          set the backgroundColor of field "field2" to "gray"
                                       end if
         
                                      If the value of fld "Field2" >= 1  then
                                        set the backgroundColor of field "field2" to "green"
                                     end if
                                     
                                     --set the backgroundColor of button RX1 to "white"
                      end if       -- skip above if TempChar was not  *
      
      
      --send readPort to me in 2 milliseconds    -- Serial Read loop speed
      
      
                   --end if    --LOOP if the hilite of btn "Port open" = true
   send readPort to me in 1 millisecond    -- Serial Read loop speed
   
end readPort
tcbcats

tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 22
Joined: Tue May 06, 2008 5:33 am
Location: Las Vegas
Contact:

Re: Serial communications memory use increases with time

Post by tcbcats » Sat Jan 23, 2016 4:35 am

Code: Select all

on readPort

   
   if the hilite of btn "Port open" = true then
      put the label of btn "Port" into thePort
      
      read from file thePort for 1   -- looking for * as first chr of packet.
      If it = "*" then
         --lock screen
         put empty into fld "recField"      -- clear recField
         set the backgroundColor of button RX to "green"
         put it after fld "recField"             -- this is first chr of RX packet. Should be chr *
         --lock screen
         repeat                                  --end chr is #
            read from file thePort for 1   -- read another one byte from serial port
            put it after fld "recField"       -- add to display window "recField" after last received byte
            If it = "#" then exit repeat
         end repeat                            --RX string is now captured. Start chr is *... end chr is #
         
               set the backgroundColor of button RX to "white"
               --unlock screen
               
  --put empty into fld "field1"
  --put empty into fld "field2"
  --put empty into fld "field3"
  --put empty into fld "field4"
  --put empty into fld "field5"
  --put empty into fld "field6"
  --put empty into fld "field7"
  --put empty into fld "field8"
  --put empty into fld "field9"
  --put empty into fld "field13"
            
               --set the backgroundColor of button RX1 to "red"
               --wait 2 milliseconds with messages
   
               put item 2 of fld "recField" into fld field1        --SPEED.
               put item 3 of fld "recField" into fld field2        --Turbo heatsink temperature
               put item 4 of fld "recField" into fld field3        --Hub heatsink temperature
               put item 5 of fld "recField" into fld field4        --Turbo motor temperature
               put item 6 of fld "recField" into fld field5        --Hub heatsink temperature
               put item 7 of fld "recField" into fld field6       --Hub motor temerature
               put item 8 of fld "recField" into fld field7       --Brake status
               put item 9 of fld "recField" into fld field13       --Battry voltage
               put item 15 of fld "recField" into fld field10       --Turbo Current Overload
               put item 16 of fld "recField" into fld field11       --Hub Current Overload
               put item 17 of fld "recField" into fld field8
               put item 18 of fld "recField" into fld field9       --Mode

         --If item 6 of fld "recField" = 1  then        --Show ststus of China mode... on or off
         --put "ON" into fld C0
         --set the backgroundColor of fld "C0" to "green"
         --end if
         
         
         --******* STOP AND CLOSE SERIAL PORT AT THIS BYTE COUNT ****
         add 1 to field "DataCount"
         --if field "DataCount" >= 500 then      -- close serial port on this count
         --put empty into field "DataCount"
         --send MouseUp to button "Close Serial Port"
         --end if
         ---------------------------------------------------------------------------------------
         
         --put item 6 of fld "recField" into fld field5       --Show ststus of China mode... on or off
         
         --If item 6 of fld "recField" = 0  then --Turn off China mode
         --set the label of button "C0" to "Off"
         
         --put item 10 of fld "recField" into fld field10       --Filtered output out
         
         --put item 8 of fld "recField" into fld field11       --Raw Hall output
         
         --If item 10 of fld "recField" > 41  then
         -- set the backgroundColor of fld "Field10" to "green"
         --end if
         
         --If item 10 of fld "recField" <= 40  then
         --set the backgroundColor of fld "Field10" to "gray"
         --end if
         
         --If item 8 of fld "recField" > 41  then
         --set the backgroundColor of fld "Field11" to "green"
         --end if
         
         --If item 8 of fld "recField" <= 40  then
         --set the backgroundColor of fld "Field11" to "gray"
         --end if
         
         --put item 9 of fld "recField" into fld field8            --Volts
         
         --put Item 8 of fld "recField" into MyPowerHall      --Raw Hall output
         --put Item 7 of fld "recField" into MyPowerTH       -- Manual throttle output
         
         
         --put Item 10 of fld "recField" into MyPowerOut    --Filtered output

         
         --Set the thumbpos of scrollbar "ProgressBarOut" to MyPowerOut 
         --Set the thumbpos of scrollbar "ProgressBarTH" to MyPowerTH
         --Set the thumbpos of scrollbar "ProgressBarHall" to MyPowerHall
         --put item 8 of fld "recField" into fld field6
         
         
         
         --if Item 23 of fld "recField" contains "AT"  then  --- Are we at full scale?
         --put item 23 of fld "recField" into fld field12
         --set the backgroundColor of fld "Field12" to "red"
         
         --if Item 12 of fld "recField" contains "AT"  then  --- Are we at full scale?
         --put item 12 of fld "recField" into fld field12
         --set the backgroundColor of fld "Field12" to "red"
         --else
         --put "Sensor in linear range output" into fld Field12
         --set the backgroundColor of fld "Field12" to "green"
         --end if
         
         -- FLAG MOTOR CURRENT LIMITS
         if Item 15 of fld "recField" contains "*"  then  --- Is the turbo motor in current limit?
            set the backgroundColor of fld "Field10" to "red"
         else
         set the backgroundColor of fld "Field10" to "green"
      end if
      
               if Item 16 of fld "recField" contains "*"  then  --- Is the turbo motor in current limit?
            set the backgroundColor of fld "Field11" to "red"
         else
         set the backgroundColor of fld "Field11" to "green"
         end if
         
         
         
         
         
         --HUB ONLY
         If last char of fld "Field9" = "-"  then
            set the backgroundColor of button HubOnly to "green"
            set the label of button "HubOnly" to "OFF"
         end if
         
         If last char of fld "Field9" = "+"  then
            set the backgroundColor of button HubOnly to "red"
            set the label of button "HubOnly" to "ON"
         end if
         
         
         
         --TURBO ONLY
         If last char of fld "Field8" = "-"  then
            set the backgroundColor of button TurboOnly to "green"
            set the label of button "TurboOnly" to "OFF"
         end if
         
         If last char of fld "Field8" = "+"  then
            set the backgroundColor of button TurboOnly to "red"
            set the label of button "TurboOnly" to "ON"
         end if
         
                                    --BRAKE FIELD COLOR
                                     If last char of fld "Field7" = 0  then
                                        set the backgroundColor of field "field7" to "gray"
                                     end if
         
                                     If last char of fld "Field7" = 1  then
                                       set the backgroundColor of field "field7" to "red"
                                      end if
         
                                     
                                     --THROTTLE FIELD COLOR
                                       If last char of fld "Field2" = 0  then
                                          set the backgroundColor of field "field2" to "gray"
                                       end if
         
                                      If the value of fld "Field2" >= 1  then
                                        set the backgroundColor of field "field2" to "green"
                                     end if
                                     
                      end if       -- skip above if TempChar was not  *
      
      
      
                   end if    --LOOP if the hilite of btn "Port open" = true
   send readPort to me in 50 milliseconds    -- Serial Read loop speed
   
end readPort




This is the serial read and parse code that works in LC 5.5.3... no memory leak and works as it should in XP and Win7
If compiled or run in any higher version, It has a memory leak (Size of app will double every 1000 or so serial reads.) and will run very slow on a netbook XP or any machine that is not at least a 3 gig machine.
I have never been able to get a stable fast 9600 baud com port read on any LC version greater than 5.5.3
In reading the bug listings related to reading a serial port, I suspect that the LC team has no way to actually test real or USB serial port LC applications. That would account for "read from file" related bug reports being "fixed" and then coming back again in another form on later updates.

My application also will sometimes not close properly when quitting. (I do close the used serial port before closing the app.) The task manager keeps the app active no matter what method is used to close the stand alone app. I have to manually delete the app in the task manager or reboot the OS. I am still looking for the cause of this feature.
Perhaps only a few of us are using continuous serial port reads in our applications... it is kind of old school stuff...
tcbcats

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

Re: Serial communications memory use increases with time

Post by jacque » Sat Jan 23, 2016 8:24 pm

LiveCode only does garbage collection during an idle event; it keeps all its internal workings in RAM until there's a chance to do its housekeeping. What I think is happening is that the script isn't giving LC any time to do cleanup, so the engine is storing up a lot of internal data. You need to give it a breather so it can remove the garbage it's been collecting.

You've commented out the "wait 2 milliseconds with messages" line, which would give LC a chance to do that. But a better method would be to use a "send ... in time" structure to repeatedly read the port because LC will handle cleanup consistently if you do that. It isn't clear from what you've posted how you are managing calls to readPort. If you're doing it inside a repeat loop then you've locked up the engine and prevented it from flushing all the cruft out of RAM.

The ideal way to manage it is:

Code: Select all

on mouseUp
  readPort -- starts the process
end mouseUp

on readPort
  if the hilite of btn "port open" = true then
    -- all the code here
     send "readPort" to me in 1 millisecond
  end if
end readPort
In between "sends" LiveCode will clean up after itself.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 22
Joined: Tue May 06, 2008 5:33 am
Location: Las Vegas
Contact:

Re: Serial communications memory use increases with time

Post by tcbcats » Sat Jan 23, 2016 9:41 pm

Thank you for the reply.
Yes I am in a read loop where I read the com port for 1 until I get the start chr of "*"... Then I read in a loop to collect the serial packet of 50 characters or so until I get the end chr "#. Then I start over because the next packet will arrive in about 300 milliseconds.
I will play with your information on the structure to see if I can get it to be stable on higher versions of LC.

BTW.. I found the problem with the stand alone not closing in the Task manager. I was using the rev speech in the app to do a beep sound and failed to place the "revUnloadSpeech" command in the card close script. This left the Windows text to speech code in memory and caused my app to keep an instance of itself in memory each time it was closed.
Thanks again for your comments.
Cheers...
tcbcats

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

Re: Serial communications memory use increases with time

Post by jacque » Sun Jan 24, 2016 7:10 pm

The loops that are internal to readPort shouldn't cause much trouble but if you're calling readPort inside a repeat loop in another handler, that's where the lockup could occur.

Did you know there's a "beep" command?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 22
Joined: Tue May 06, 2008 5:33 am
Location: Las Vegas
Contact:

Re: Serial communications memory use increases with time

Post by tcbcats » Sun Jan 24, 2016 9:41 pm

I do use the beep command on a button that opens the serial port and starts the readport code that is posted here.
When you use the beep in LC, the standalone app also adds the revspeech to the build and you have to remember to close it down when you exit the application. I use the "revUnloadSpeech" command in the shutdown code.
This allows windows to clear the app from memory.

This code works fine in LC 5.5.3 but runs about 5X slower in any build from later versions of LC. Builds also generate added memory usage in the higher versions of LC.
For now, I will just have to stick to LC 5.5.3 for all my builds that use the read from file and use the serial port.
I played with some wait's in the code but it did not change the issues in the later builds through 8.0.

I did not try closing the serial port and re opening in each read loop... This structure should not be needed unless I am missing something.

Code: Select all

on readPort    --(THIS IS CALLED FROM A START BUTTON THAT OPENS THE SERIAL PORT FOR BINARY READ AND STARTS THIS PROCESS LOOP. THE RECEIVED TEXT CHAR'S ARE JUST PLACED INTO A TEXT FIELD AND THEN CLEARED)
   
   if the hilite of btn "Port open" = true then
      put the label of btn "Port" into thePort
      
      read from file thePort for 1   -- looking for * as first chr of packet.
      
      If it = "*" then
         --lock screen
                       put empty into fld "recField"      -- clear recField
                       set the backgroundColor of button RX to "green"
                       put it after fld "recField"             -- this is first chr of RX packet. Should be chr *
         --lock screen
         repeat                                  --end chr is #
            read from file thePort for 1   -- read another one byte from serial port
            put it after fld "recField"       -- add to display window "recField" after last received byte
            If it = "#" then exit repeat
         end repeat                            --RX string is now captured. Start chr is *... end chr is #
         
         set the backgroundColor of button RX to "white"
         
         set the backgroundColor of button RX1 to "green"
         --unlock screen

         put item 2 of fld "recField" into fld field1        --SPEED.
         put item 3 of fld "recField" into fld field2        --Turbo heatsink temperature
         put item 4 of fld "recField" into fld field3        --Hub heatsink temperature
         put item 5 of fld "recField" into fld field4        --Turbo motor temperature
         put item 6 of fld "recField" into fld field5        --Hub heatsink temperature
         put item 7 of fld "recField" into fld field6       --Hub motor temerature
         put item 8 of fld "recField" into fld field7       --Brake status
         put item 9 of fld "recField" into fld field13       --Battry voltage
         put item 15 of fld "recField" into fld field10       --Turbo Current Overload
         put item 16 of fld "recField" into fld field11       --Hub Current Overload
         put item 17 of fld "recField" into fld field8
         put item 18 of fld "recField" into fld field9       --Mode
         
         add 1 to field "DataCount"
         
         --if field "DataCount" >= 500 then      -- close serial port on this count
         --put empty into field "DataCount"
         --send MouseUp to button "Close Serial Port"
         --end if
         ---------------------------------------------------------------------------------------

         
         --put Item 8 of fld "recField" into MyPowerHall      --Raw Hall output
         --put Item 7 of fld "recField" into MyPowerTH       -- Manual throttle output
         
         
         --put Item 10 of fld "recField" into MyPowerOut    --Filtered output
         
         
         --Set the thumbpos of scrollbar "ProgressBarOut" to MyPowerOut 
         --Set the thumbpos of scrollbar "ProgressBarTH" to MyPowerTH
         --Set the thumbpos of scrollbar "ProgressBarHall" to MyPowerHall
         --put item 8 of fld "recField" into fld field6
         
         
         
         --if Item 23 of fld "recField" contains "AT"  then  --- Are we at full scale?
         --put item 23 of fld "recField" into fld field12
         --set the backgroundColor of fld "Field12" to "red"
         
         --if Item 12 of fld "recField" contains "AT"  then  --- Are we at full scale?
         --put item 12 of fld "recField" into fld field12
         --set the backgroundColor of fld "Field12" to "red"
         --else
         --put "Sensor in linear range output" into fld Field12
         --set the backgroundColor of fld "Field12" to "green"
         --end if
         
         -- FLAG MOTOR CURRENT LIMITS
         if Item 15 of fld "recField" contains "*"  then  --- Is the turbo motor in current limit?
            set the backgroundColor of fld "Field10" to "red"
         else
            set the backgroundColor of fld "Field10" to "green"
         end if
         
         if Item 16 of fld "recField" contains "*"  then  --- Is the turbo motor in current limit?
            set the backgroundColor of fld "Field11" to "red"
         else
            set the backgroundColor of fld "Field11" to "green"
         end if
         
         
                                      --HUB ONLY
                                If last char of fld "Field9" = "-"  then
                                set the backgroundColor of button HubOnly to "green"
                                set the label of button "HubOnly" to "OFF"
                                end if
         
                                 If last char of fld "Field9" = "+"  then
                                 set the backgroundColor of button HubOnly to "red"
                                 set the label of button "HubOnly" to "ON"
                                end if
         
         
         
         
                              --TURBO ONLY
                        If last char of fld "Field8" = "-"  then
                        set the backgroundColor of button TurboOnly to "green"
                        set the label of button "TurboOnly" to "OFF"
                        end if
         
                         If last char of fld "Field8" = "+"  then
                         set the backgroundColor of button TurboOnly to "red"
                         set the label of button "TurboOnly" to "ON"
                         end if
         
                           --BRAKE FIELD COLOR
                        If last char of fld "Field7" = 0  then
                        set the backgroundColor of field "field7" to "gray"
                        end if
         
                        If last char of fld "Field7" = 1  then
                         set the backgroundColor of field "field7" to "red"
                         end if
         
         
                                  --THROTTLE FIELD COLOR
                              If last char of fld "Field2" = 0  then
                               set the backgroundColor of field "field2" to "gray"
                               end if
         
                                        If the value of fld "Field2" >= 1  then
                                         set the backgroundColor of field "field2" to "green"
                                         end if
         
                                         wait 10 milliseconds with messages
                                         set the backgroundColor of button RX1 to "white"
      end if       -- Packet was captured OK
      
   end if    --LOOP if the hilite of btn "Port open" = true
   wait 5 milliseconds with messages
   send readPort to me in 10 milliseconds    -- Serial Read loop speed
   --send mouseUp to me in 50 mlliseconds
end readPort




tcbcats

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

Re: Serial communications memory use increases with time

Post by jacque » Tue Jan 26, 2016 5:29 am

Interesting...if the beep command requires revSpeech (and I can't imagine why it would) then that's something new. I'd check the standalone settings to make sure that the speech library isn't included. Beep didn't require that library in the past, it's just a system call.

I don't see anything in your last posted handler that would cause a memory leak per se. It could be there's a bug somewhere, but to make sure, I wonder what you'd see if you removed all the field and button updates, and just ran only the part that deals with reading the port. If that runs okay then the problem lies elsewhere. If it doesn't, there's an engine leak.

If I did it right, that would be only this part, which collects the data in a local script variable and puts it into the message box so you can see what was captured:

Code: Select all

local sMsg

on readPort 
  if the hilite of btn "Port open" = true then
    put the label of btn "Port" into thePort
          
    read from file thePort for 1   -- looking for * as first chr of packet.
          
    If it = "*" then
      put empty into sMsg
      put it after sMsg 
      repeat                         
        read from file thePort for 1  
        put it after sMsg  
        If it = "#" then exit repeat
      end repeat    --RX string is now captured. Start chr is *... end chr is #
      put sMsg -- to message box
      wait 10 milliseconds with messages
    end if  -- Packet was captured OK
          
  end if    --LOOP if the hilite of btn "Port open" = true
  wait 5 milliseconds with messages
  send readPort to me in 10 milliseconds    -- Serial Read loop speed
end readPort
I wasn't able to test that, but it should at least give you an idea of how to test. If it still leaks, you've found a bug.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 22
Joined: Tue May 06, 2008 5:33 am
Location: Las Vegas
Contact:

Re: Serial communications memory use increases with time

Post by tcbcats » Wed Jan 27, 2016 8:23 am

If I uncheck the search for required inclusions in the "stand alone app settings" My app saves without the rev speech dll in the stand alone application.
If I ask the save to look for the external helper files, it adds the rev speech thingy to every one of my application standalone s.
I have no idea why my LC dev system does this... It does it on all versions of LC.

Yes, I have confirmed that the beep command does not use or need the rev speech stuff.
At one time a long time ago I did use the rev speech for some testing so maybe something got stuck in the tools and did not get removed. That old code is no longer on my machine.

Can you do a program with rev speech activated and compile for windows standalone and then remove the rev speech and compile again and see if it gets removed from the standalone?
I can't do it here because I have no PC that has a virgin LC install.
I can't see any other settings in the tools where the rev speech could be included other than the normal manual selection of the externals.

I am still working on the read from file for X. It does not look like it is paying attention to the modifier options on the X part.
"Read from file for 1 char".... reads many bytes. "Read from file for 1" reads the same thing (all the characters in the serial buffer) I cannot make it just read one character or byte at a time so I can test a single character read result. It looks like it just reads from the file until the end on each read. All reads read till the EOF no matter what the modifier. That makes the "it" contain a string instead of a single byte or character. This may be unique to reading a comm port as a file per the instructions.
I tried many variations of the open file for binary update and other defines but they all give the same result when reading a comm port instead of reading a real file. The help files are really no help because they are missing examples using all the modifier options.

I did remove all my button pretty stuff in my code and it did not change the speed or behavior of the serial port read.
I'm glad I am retired and have the time to play.
Tom
***
tcbcats

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

Re: Serial communications memory use increases with time

Post by jacque » Wed Jan 27, 2016 9:34 pm

Standalone settings are stored in a custom property in the stack, and it sounds like it isn't always accurately refreshed when using "search for required inclusions." I suspect you can clear the setting by choosing to manually set inclusions, and toggling the speech library on and off again.

If that doesn't work, you can delete the setting from the custom property itself. It is not visible by default. Do this:
  • Choose "LiveCode UI elements in lists" from the View menu.
    Open the stack property inspector and go to the Custom Properties pane.
    In the "Set" popdown, choose "revStandaloneSettings"
    Look for the revSpeech library and delete that line
You'll probably want to turn off "Choose "LiveCode UI elements in lists" when you're done or all kinds of IDE things will clutter up the App and Project browsers.

I think you may have found a bug with the serial port reads, and you should probably report it. A workaround would be to parse the entire block of returned data and extract the characters between the two markers. That would probably be pretty easy to do.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 22
Joined: Tue May 06, 2008 5:33 am
Location: Las Vegas
Contact:

Re: Serial communications memory use increases with time

Post by tcbcats » Wed Jan 27, 2016 10:12 pm

I am going to play with real file reads vs comm port file reads an see what I can find.
If I can get real files to read one char at a time, then I will report the problem.
I also want to see if the memory gain issue happens on real file reads like the comm port reads.
Thanks for your help.
Tom
***
tcbcats

tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 22
Joined: Tue May 06, 2008 5:33 am
Location: Las Vegas
Contact:

Re: Serial communications memory use increases with time

Post by tcbcats » Thu Jan 28, 2016 5:25 am

I did some file read tests as in the code below.
The read from a normal file works but reading from a com port file does not follow the read defines in the same way.
The memory leak is only there on LC ver 7.04 and above when reading continuous serial data.
I would sure like to get some input from anyone else that is actually reading data from a com port in Windows.
I'm not ready to submit to Bugzilla yet but getting close.... just looking to see if others have had the same problems.
Cheers,
Tom
***

Code: Select all

on mouseUp
   
-- ******* This is not a com: port read in this example  *****
   Put empty into field FYY     --Clear my text message fiels on start.
      open file "text11" for text write
      --if the result is not empty then
         --answer the result
         
      write "hello world" to file "text11"   --this file will be created in the default LC folder if it does not exist.
      close file "text11"                         -- Close the file so I can read it in the following code.
      wait 100 milliseconds with messages   -- just in case something bad happens.
      
      open file "text11" for text read
      --*******************************************************
      --All of these FILE READ defines below work on a real file in LC
      -- They do not work if the file is defined as a COM: port file as instructed in the LC Dictionary
      --COM: port reads can only be read as a string with the "until empty" or EOF defines and not as single characters.
      --It looks like the only way to read a com: port file in LC is to collect all the characters in the file as a variable and then to parse
      --the characters from the collected variable.
      --I still think reading the serial ports in LC has memory leaks and the newer LC engine is suspect. The memory leaks do not occur
      --in LC 5.5.3 or lower.... Also, LC 5.5.3 is 5 X faster than later versions in reading the same com port file.
      --My application receives serial packets of 60 text bytes @ 9600 baud every second or so. The memory leak in this mode is
      --slow but consistant so that the application grows in memory with no limit from around 70 MB to over 200 Mb until the
      --Windows PC hangs.
      -- This test code is just to see if normal file reads work with the read defind parameters shown in the dictionary.
      --********************************************************
      
      --read from file "text11" for 1  -- looking for one chr read from file.
      --read from file "text11" for 2  -- looking for only 2 chr"s  read from file.
       read from file "text11" until EOF  -- looking for all the char's in the file (string).
      --read from file "text11" until empty  -- looking for all the char's in the file (string).
      
       --*******************************************************
       --********************************************************
     
Put " Got...   " after field FYY
      Put it after field FYY
      
      close file "text11"   ---Close the file
      beep 1
      
      wait 3000 milliseconds with messages    --delay befoer clearing message window
      
      Put "STOP" into field FYY     --Ending text in message window.
      beep 1
      --STOP HERE
      
end mouseUp
tcbcats

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

Re: Serial communications memory use increases with time

Post by jacque » Thu Jan 28, 2016 7:33 am

Wish I could help, but I don't have a device to hook up to a com port...hope someone will chime in. But there's no harm in submitting a bug anyway, your tests seem to show pretty clearly there's something odd going on.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 22
Joined: Tue May 06, 2008 5:33 am
Location: Las Vegas
Contact:

Re: Serial communications memory use increases with time

Post by tcbcats » Sun Feb 21, 2016 1:06 am

I added a note to pending bug report # 14612 about serial port read not working.
This bug report is related to this issue and it looks like it is still under review.
I should get an Email if someone responds or adds to the bug report.
Tom
Las Vegas
***
tcbcats

Post Reply

Return to “Windows”