"Fossies" - the Fresh Open Source Software Archive

Member "gambas-3.16.2/app/examples/Networking/SerialPort/.src/Module_RS232.module" (6 Jul 2021, 2267 Bytes) of package /linux/misc/gambas-3.16.2.tar.bz2:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 ' Gambas module file
    2 
    3 Public Sub EnumerateSerialInterfaces()
    4   
    5   Dim i As Integer
    6   
    7   With FMain
    8     
    9     'Set operational parameters (used for testing only) 
   10     .SerialPort1.Speed = "19200"
   11     .SerialPort1.Parity = 0
   12     .SerialPort1.DataBits = "8"
   13     .SerialPort1.StopBits = "1"
   14     .SerialPort1.FlowControl = 0
   15     
   16     'Clear Device Combo
   17     FMain.ComboPortDeviceName.Clear()
   18     
   19     'Standard USB Ports
   20     For i = 0 To 8
   21       .SerialPort1.PortName = "/dev/ttyS" & Format(i, "0")
   22       Try .SerialPort1.Open
   23       If Not Error 
   24         .ComboPortDeviceName.Add(.SerialPort1.PortName) 
   25         .SerialPort1.close
   26       Endif
   27     Next
   28     
   29     'USB based ports
   30     For i = 0 To 8
   31       .SerialPort1.PortName = "/dev/ttyUSB" & Format(i, "0")
   32       Try .SerialPort1.Open
   33       If Not Error 
   34         .ComboPortDeviceName.Add(.SerialPort1.PortName) 
   35         .SerialPort1.close
   36       Endif
   37     Next
   38     
   39   End With
   40   
   41 End
   42 
   43 Public Sub DisplaySerialInput(RX As String)
   44   'This Routine displays serial data
   45   
   46   Dim R As String
   47   Dim i As Integer
   48   
   49   With FMain 
   50     
   51     'Set cursor to the end of the text
   52     .TextArea1.Pos = .TextArea1.Length
   53     
   54     'CR is ommited because the TextArea control displays it as CR+LF 
   55     For i = 1 To Len(RX)
   56       R = Mid$(RX, i, 1)
   57       If R <> Chr$(13) Then
   58         'Amend character
   59         .TextArea1.insert(R)
   60       Endif
   61     Next  
   62     
   63     ' 'Use the following alternatively to the above. It displays ASCII-values in [] if it is a control character (ASCII-value < 32)
   64     ' For i = 1 To Len(RX)
   65     '   R = Mid$(RX, i, 1)
   66     '   If Asc(R) > 31 Then
   67     '     .TextArea1.insert(R)
   68     '   Else
   69     '     If R <> Chr$(13) 'Ommit CR because the TextArea control display it as CR+LF
   70     '       .TextArea1.insert("[" & Format(Asc(R), "0") & "]" & R)
   71     '     Else
   72     '       .TextArea1.insert("[" & Format(Asc(R), "0") & "]")
   73     '     Endif
   74     '   Endif
   75     ' Next
   76     
   77   End With
   78   
   79 End
   80 
   81 Public Sub CheckRS232Status()
   82   'This dipslays the status of the RS232 handshake lines
   83   
   84   With FMain.SerialPort1  
   85     FMain.CheckDSR.Value = .DSR
   86     FMain.CheckDTR.Value = .DTR
   87     FMain.CheckCTS.Value = .CTS
   88     FMain.CheckRTS.Value = .RTS
   89     FMain.CheckDCD.Value = .DCD
   90     FMain.CheckRNG.Value = .RNG
   91   End With 
   92   
   93 End