[Gambas-user] FW: Serial and Multiserial Problem

Jussi Lahtinen jussi.lahtinen at ...626...
Sun Jan 13 21:11:15 CET 2013


Hmmmm.... maybe 300 ms is more than enough to fill some buffer --> lost
data?

Jussi



On Sun, Jan 13, 2013 at 10:08 PM, Jussi Lahtinen
<jussi.lahtinen at ...626...>wrote:

> Can you send the whole runnable project (or small demonstration project)?
> It's bit difficult to get the proper picture from that. Missing
> declarations, etc.
>
> I didn't quite understand why you rejected model based on Sport_read()
> event..?
>
> Jussi
>
>
>
>
>
> On Sun, Jan 13, 2013 at 12:19 PM, dimitris tsiou <dgtsiou at ...67...>wrote:
>
>>
>>
>>
>>
>>
>> Thank you for the answer. I had the same problem with 2.24 so I downgrade
>> gambas version to 2.21.
>>
>> This is a code snippet of what I wrote.
>>
>>
>> PUBLIC CTimeOut AS Timer
>>
>>
>> PUBLIC FUNCTION initialize() AS Boolean
>>     DIM s AS String
>>     DIM Derror AS Integer = 0
>>     DIM i AS Integer = 0
>>     DIM sout AS String = ""
>>
>>     CTimeOut = NEW Timer AS "CTimeOut"
>>     CTimeOut.Delay = 300
>>
>>     FMain.ProgressBarTest.value = 0.00
>>     FMain.TextAreaInformation.Background = &HFFFF00&
>>     FMain.TextAreaInformation.Text = "\n\n\n\n\n\t\t\t" & "Init...\n"
>>     FMain.TextAreaInformation.Font.Size = 15
>>
>>
>>     'Init Controller Module (AVR)
>>
>>     IF Settings["Station/Init"] = TRUE THEN
>>         sout = MStation.init()
>>         IF sout = NULL THEN Error.Raise("STATION")
>>         FMain.TextAreaTrace.Text = Format(Now(), "hh:nn:ssuuuu: ") & "STA
>> > " & sout & FMain.TextAreaTrace.Text
>>     ENDIF
>>
>>     CTimeOut.Start()
>>     WAIT 1
>>     MStation.reset()
>>     WAIT 0.4
>>
>>
>>     RETURN TRUE
>>
>>   CATCH
>>    s = "\n" & Format(Now(), "hh:nn:ssuuuu") & " - " & "Error during
>> Initialization...\n" &
>>    "Process Error: " & Error.Class.Name & "\n" &
>>    "Error Text: " & Error.Text & "\n" &
>>    "Error Code: " & Derror & "\n"
>>
>>    FMain.TextAreaInformation.Text = FMain.TextAreaInformation.Text & s
>>    FMain.TextAreaTrace.Text = FMain.TextAreaTrace.Text & s
>>    FMain.TextAreaInformation.Background = &HFF0000&
>>    FMain.TextAreaError.Text = FMain.TextAreaError.Text & s
>>    DEBUG s
>>
>>    RETURN FALSE
>> END
>>
>>
>>
>> PUBLIC SUB CTimeOut_Timer()
>>
>>   CTimeOut.Stop()
>>   MStation.CDataRead()
>>   CTimeOut.Start()
>>
>> END
>>
>>
>>
>> PUBLIC FUNCTION CDataRead() AS String
>>    DIM i AS Integer = 0
>>    DIM index AS Integer
>>    DIM Derror AS Integer
>>    DIM buf AS String = ""
>>    DIM sout AS String= ""
>>    DIM StationStatus AS String = ""
>>    DIM StationError AS String = ""
>>
>>
>>    CurrentPortByte = ""
>>
>>    TRY READ #SPort, buf, Lof(SPort)
>>    RxSport &= buf
>>
>>
>>    WHILE TRUE
>>       i = InStr(RxSport, "\n", 1)
>>       IF i = 0 THEN BREAK
>>       buf = Left(RxSport, i)
>>       RxSport = Right(RxSport, Len(RxSport) - i)
>>       FMain.TextAreaTrace.Text = Format(Now(), "hh:nn:ssuuuu: ") & "STA >
>> " & buf & FMain.TextAreaTrace.Text
>>
>>       '------ Manipulate Controller's data -------'
>>
>>       'Port Signals
>>       IF buf = "F?\n" THEN
>>           CurrentPortByte = Left(RxSport, 2)
>>           PRINT Left(buf, 2) & " --> PORTF: " & CurrentPortByte
>>       ENDIF
>>
>>       IF buf = "C?\n" THEN
>>           CurrentPortByte = Left(RxSport, 2)
>>           PRINT Left(buf, 2) & " --> PORTC: " & CurrentPortByte
>>       ENDIF
>>
>>       'Inputs
>>       IF InStr(buf, "inputs:") <> 0 THEN
>>           PRINT buf
>>       ENDIF
>>
>>       'Status
>>       IF InStr(buf, "status:") <> 0 THEN
>>           index = InStr(buf, "s:", 1)
>>           StationStatus = Mid(buf, index + 2, 1)
>>           PRINT "StationStatus: " & StationStatus
>>
>>           IF StationStatus = "5" THEN
>>               sout = "New device\n"
>>               FMain.TextAreaTrace.Text = Format(Now(), "hh:nn:ssuuuu: ")
>> & "STA > " & sout & FMain.TextAreaTrace.Text
>>               FMain.TextAreaSpec.Text = ""
>>               FMain.TextAreaInformation.Text = sout
>>               FMain.TextAreaInformation.Background = Color.Yellow
>>           ENDIF
>>
>>           IF StationStatus = "7" AND IsTestRunning = FALSE THEN
>>                 IsTestRunning = TRUE
>>
>>                 sout = "New Test\n"
>>                 FMain.TextAreaInformation.Text &= sout
>>                 FMain.TextAreaTrace.Text = Format(Now(), "hh:nn:ssuuuu:
>> ") & "STA > " & sout & FMain.TextAreaTrace.Text
>>                 TestMod.TestExec()
>>            ENDIF
>>       ENDIF
>>
>>       'Errors
>>       IF InStr(buf, "error!:") <> 0 THEN
>>           index = InStr(buf, "or!:", 1)
>>           StationError = Mid(buf, index + 4, 1)
>>           PRINT "StationError: " & StationError
>>
>>           IF StationError = "@" THEN
>>             sout = "Error: Overflow\n."
>>           ENDIF
>>
>>           IF StationError = "A"
>>             sout = "Error (A)"
>>           ENDIF
>>
>>           IF StationError = "C"
>>             sout = "Error (C)\n"
>>           ENDIF
>>
>>           IF StationError = "F"
>>             sout = "Error (F)\n"
>>           ENDIF
>>
>>           IF StationError = "G"
>>             sout = "Error (G)\n"
>>           ENDIF
>>
>>           IF StationError = "H"
>>             sout = "Error (H)\n"
>>           ENDIF
>>
>>           IF StationError = "Q"
>>             sout = "Error (Q)\n"
>>           ENDIF
>>
>>           FMain.TextAreaError.Text = Format(Now(), "hh:nn:ssuuuu: ") &
>> "STA > " & Settings["Station/" & Mid(buf, 8, 1)] & "\n\r" &
>> FMain.TextAreaError.Text
>>           FMain.TextAreaError.Text = Format(Now(), "hh:nn:ssuuuu: ") &
>> "STA > " & Left(buf, 8) & FMain.TextAreaError.Text
>>           FMain.TextAreaError.Text = Format(Now(), "hh:nn:ssuuuu: ") &
>> "STA > " & sout & FMain.TextAreaError.Text
>>           FMain.TextAreaTrace.Text = Format(Now(), "hh:nn:ssuuuu: ") &
>> "STA > " & Settings["Station/" & Mid(buf, 8, 1)] & "\n\r" &
>> FMain.TextAreaTrace.Text
>>           FMain.TextAreaTrace.Text = Format(Now(), "hh:nn:ssuuuu: ") &
>> "STA > " & Left(buf, 8) & FMain.TextAreaTrace.Text
>>           FMain.TextAreaTrace.Text = Format(Now(), "hh:nn:ssuuuu: ") &
>> "STA > " & sout & FMain.TextAreaTrace.Text
>>           FMain.TextAreaInformation.Text = FMain.TextAreaInformation.Text
>> & Format(Now(), "hh:nn:ssuuuu: ") & Settings["Station/" & Mid(buf, 8, 1)]
>> &"\n\r" & sout
>>           FMain.TextAreaInformation.Background = Color.Red
>>
>>           IF FStation.Visible THEN
>>               FStation.TextAreaRx.Text = "@" & Sport.PortName & ">: " &
>> Settings["Station/" & Mid(buf, 8, 1)] & "\n\r" & FStation.TextAreaRx.Text
>>           ENDIF
>>       ENDIF
>>
>>       buf = ""
>>   WEND
>>
>>   CATCH
>>        'Error.Raise("CDataRead(): " & Error.Text)
>> END
>>
>>
>>
>>
>> Is it possible that the timer event every 300ms is responsible for data
>> corruption?
>>
>> Thanks again.
>>
>>
>>
>>
>>
>>
>>
>> From: dgtsiou at ...67...
>> To: gambas-user at lists.sourceforge.net
>> Subject: Serial and Multiserial Problem
>> Date: Fri, 11 Jan 2013 13:47:39 +0000
>>
>>
>>
>>
>>
>> Hello to everyone, I wish you a happy new Year!
>>
>> I am gambas user at about 4 months and I am developing a system for
>> control automation on a Ubuntu 10.04. I'm using the Gambas 2.21 runtime. I
>> have also tried Ubuntu 11.04 for my application. The problem's description
>> is as follows:
>>
>> An AVR micro polls for some sensor signals and sends asynchronous msgs to
>> the ubuntu PC via /dev/ttyS0. The PC is also communicates with other
>> devices via serial port lines using a multi-serial 4-port RS-232 (PCI card).
>>
>> After 2-3 hours of normal operation the Control program, running on the
>> ubuntu PC, receives corrupted/no data from the micro. Initially, I was
>> using the event based mechanism for the data reception with Sport_read()
>> event. When the aforementioned problem was raised, I changed my design and
>> I removed the Sport_read by creating an idle event (with a timer event
>> every 300 msecs) and executing READ calls in order to receive micro's data.
>> After Read, the data manipulation is following.
>> Unfortunately the same problem remains with data received by gambas
>> application. I have already checked the messages transmitted from the micro
>> with cutecom/minicom and it seems that everything is ok (messages
>> successfully delivered).
>>
>> When I restart the PC (Not the application!) then everything works fine
>> again for another time interval of 3-4 hours.
>>
>> Has anyone an idea why this happens? Every answer will be really valuable
>> for me.
>>
>> Thank you in advance
>>
>>
>> ------------------------------------------------------------------------------
>> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
>> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
>> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
>> MVPs and experts. ON SALE this month only -- learn more at:
>> http://p.sf.net/sfu/learnmore_123012
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
>



More information about the User mailing list