[Gambas-user] [Gambas Bug Tracker] Bug #960: Cannot get dynamically created SerialPort control events to raise.

bugtracker at ...3416... bugtracker at ...3416...
Fri Jul 1 13:47:19 CEST 2016


http://gambaswiki.org/bugtracker/edit?object=BUG.960&from=L21haW4-

zxMarce reported a new bug.

Summary
-------

Cannot get dynamically created SerialPort control events to raise.

Type             : Bug
Priority         : Medium
Gambas version   : 3.8
Product          : Networking components


Description
-----------

Put simply, I need to control one of a class of serial devices that perform the same task with different protocols, so I'm using a class per device type. These classes are created on-demand from the main app and used with a standard interface. They have all the same public calls so the app can call any one with a standard set of properties/methods and get the result no matter how different the underlying protocol/hardware is.
To this end, I'm using a USB-4xRS232 hub for convenience. The hardware set works properly under a virtual Win7-32bit using VB6 in the same Ubuntu host machine, so hardware is not suspect.

The problem is that I cannot get the dynamically created serial port to raise events in the class (not a form).

Class declarations for one device (tried declaring $tty as Public and Private with same result):

  Private Const TEST_TX As String = "ø1"  'Chr(&H02) & Chr(&HF8) & Chr(&H31) & Chr(&H03), or "STX-0xF8-0x31-ETX" (invalid command for device, on purpose)
  Private Const TEST_RX As String = ""  'Chr(&H02) & Chr(&H15) & Chr(&H03), or "STX-0x15-ETX" (means 'Error')
  Private $tty As SerialPort
  'Public $tty As SerialPort
  Private $rxBuff As String = Null


I create the serial port as follows in a Function Create() (take your pick, used both methods with the same result):

  'Instance serial port, make it raise local events as "SerPort" (but this does NOT raise events for unknown reasons!)
  $tty = New SerialPort As "SerPort"

  'Alternate way to instance would be like follows (also does NOT raise events!)
  '$tty = New SerialPort
  'Object.Attach($tty, Me, "SerPort")


Then, if Create() above returned TRUE, the moment comes to check whether the hardware device is present calling Function Test():

  Public Function Test() As Boolean

    Dim tOut As Date = DateAdd(Now, gb.Second, 2)

    'Reset RX Buffer, send test command and check for timeout/response
    $tty.Drop              'Kill remaining send data
    $tty.Begin()           'Start buffering
    Write #$tty, TEST_TX   'Add to send buffer
    $rxBuff = Null         'Kill cumulative RX buffer
    $tty.Send()            'Send buffer

    While (Now < tOut) And ($rxBuff <> TEST_RX)

      'Yield some processing time
      Sleep 0.1

      'Next IF is necessary because SerPort_Read() does not trigger by itself.
      'When the IF is commented out, the event does not trigger even having ($tty.InputBufferSize > 0).
      If $tty.InputBufferSize > 0 Then
        SerPort_Read()
      Endif

    Wend

    Finally
      Return ($rxBuff = TEST_RX)

    Catch
      Message.Error("Error '" & Error.Text & "' occurred in " & Error.Where)

  End


And this next is what is never called when data is available unless called by hand like in the IF in Test():

  Public Sub SerPort_Read()

    Dim dLen As Integer = $tty.InputBufferSize
    Dim sgmnt As New Byte[]

    'Data should be available in the serial port buffer
    sgmnt.Resize(dLen)
    sgmnt.Read($tty)
    $rxBuff &= sgmnt.ToString()

  End


I guess I might be missing something, but cannot see what. This is my first try with dynamically created objects. Maybe I have to fine-tune some serial port property (even tried playing with the .Blocking property, but nothing changed). Examples on the 'net have not been useful, and I think I did it the right way as per available docs.

Is this a problem in Gambas, or am I doing something obviously wrong?

TIA,
zxMarce.


System information
------------------

[System]
Gambas=3.8.4
OperatingSystem=Linux
Kernel=3.16.0-76-generic
Architecture=x86_64
Distribution=Ubuntu 14.04.4 LTS
Desktop=GNOME
Theme=Gtk
Language=en_US.UTF-8
Memory=11890M

[Libraries]
Cairo=libcairo.so.2.11301.0
Curl=libcurl.so.4.3.0
DBus=libdbus-1.so.3.7.6
GStreamer=libgstreamer-0.10.so.0.30.0
GStreamer=libgstreamer-1.0.so.0.204.0
GTK+2=libgtk-x11-2.0.so.0.2400.23
GTK+3=libgtk-3.so.0.1000.8
OpenGL=libGL.so.1.2.0
Poppler=libpoppler.so.44.0.0
QT4=libQtCore.so.4.8.6
QT5=libQt5Core.so.5.2.1
SDL=libSDL-1.2.so.0.11.4

[Environment]
CLUTTER_IM_MODULE=xim
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-thQOWqILYl,guid=4c9ff4d218e83a7a2b9fe46057739c84
DEFAULTS_PATH=/usr/share/gconf/cairo-dock.default.path
DESKTOP_AUTOSTART_ID=104c7ac2ed18f5e28d146719450163479400000027220002
DESKTOP_SESSION=cairo-dock
DISPLAY=:0
GB_GUI=gb.qt4
GDMSESSION=cairo-dock
GDM_LANG=en_US
GIO_LAUNCHED_DESKTOP_FILE=/usr/share/applications/cairo-dock.desktop
GIO_LAUNCHED_DESKTOP_FILE_PID=2952
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
GNOME_KEYRING_CONTROL=/run/user/1000/keyring-9DfVcF
GNOME_KEYRING_PID=2720
GPG_AGENT_INFO=/run/user/1000/keyring-9DfVcF/gpg:0:1
GTK_IM_MODULE=ibus
GTK_MODULES=overlay-scrollbar
HOME=<home>
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_ADDRESS=es_AR.UTF-8
LC_IDENTIFICATION=es_AR.UTF-8
LC_MEASUREMENT=es_AR.UTF-8
LC_MONETARY=es_AR.UTF-8
LC_NAME=es_AR.UTF-8
LC_NUMERIC=es_AR.UTF-8
LC_PAPER=es_AR.UTF-8
LC_TELEPHONE=es_AR.UTF-8
LC_TIME=en_DK.UTF-8
LOGNAME=<user>
MANDATORY_PATH=/usr/share/gconf/cairo-dock.mandatory.path
PATH=<home>/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
PWD=<home>
QT4_IM_MODULE=xim
QT_IM_MODULE=ibus
QT_QPA_PLATFORMTHEME=appmenu-qt5
SESSION_MANAGER=local/<hostname>:@/tmp/.ICE-unix/2722,unix/<hostname>:/tmp/.ICE-unix/2722
SHELL=/bin/bash
SHLVL=0
SSH_AGENT_PID=2781
SSH_AUTH_SOCK=/run/user/1000/keyring-9DfVcF/ssh
TEXTDOMAIN=im-config
TEXTDOMAINDIR=/usr/share/locale/
TZ=:/etc/localtime
USER=<user>
XAUTHORITY=<home>/.Xauthority
XDG_CONFIG_DIRS=/etc/xdg/xdg-cairo-dock:/etc/xdg
XDG_CURRENT_DESKTOP=Unity
XDG_DATA_DIRS=/usr/share/cairo-dock:/usr/share/gnome:/usr/local/share/:/usr/share/
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/<user>
XDG_MENU_PREFIX=gnome-
XDG_RUNTIME_DIR=/run/user/1000
XDG_SEAT=seat0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_SESSION_ID=c2
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_VTNR=7
XMODIFIERS=@...3498...=ibus






More information about the User mailing list