Serial Port Events

Questions regarding syntax

Serial Port Events

Postby tseyfarth » Thu Dec 09, 2010 4:42 am

Hello all.

What are the events that can take place in SerialPort1_OnComm()?

I tried using the ones from VB:
Code: Select all
         Select Case SerialPort1_OnComm  '.CommEvent
            Case comEvSend
                  er=er     
            Case comEvReceive
                  er=er
            Case comEventBreak
                er = comEventBreak
            Case comEventFrame
                er = comEventFrame
            Case comEventOverrun
                er = comEventOverrun
            Case comEventRxOver
                er = comEventRxOver
            Case comEventRxParity
                er = comEventRxParity
            Case comEventTxFull
                er = comEventTxFull
            Case comEventDCB
                er = comEventDCB
        End Select



But none of these would compile!
Please advise... anyone?

Thank you
Tim
tseyfarth
 
Posts: 101
Joined: Mon Aug 02, 2010 10:11 am

Re: Serial Port Events

Postby berndnoetscher » Thu Dec 09, 2010 9:07 am

Where did you read about "comEvSend" and the other commands?

The only docu about serial port for KBasic is:
http://www.kbasic.com/doku.php?id=controls#serialport

I am sorry that I cannot help you, because I am not able to test the serial port without have a real device.
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: Serial Port Events

Postby tseyfarth » Thu Dec 09, 2010 5:54 pm

comEvSend is in the VB6 Docs under MSCOMM Events

In your docs, there is nothing listed other than

Events are

*
Sub OnEvent()



So nothing listed showing what to expect in the OnEvent(). This BTW is the same problem I had in Q7B, nothing listed for that either, although I realize that is newer. However, since it follows the KB, if you add it here in KB, it is done for both?

Tim
tseyfarth
 
Posts: 101
Joined: Mon Aug 02, 2010 10:11 am

Re: Serial Port Events

Postby Henning » Fri Dec 10, 2010 8:26 pm

Air code, from how I read the above link, trying to get you going. There are lots of Functions listed in the link above.

@B, the part on ReadData() is a little cryptic...

Code: Select all
Sub sp_OnEvent()
  Dim tmp As String
  If sp.BytesAvailable > 0 Then
    sp.ReadData(tmp)
    Buffer = Buffer & tmp
  End If

  tmp = sp.LastError()
  Select Case tmp
  Case "NO_ERROR"
    ....
  Case "INVALID_FD"
    ....
  Case "BREAK_CONDITION"
    ....
  Case "FRAMING_ERROR"
    ....
  ....
  ....
  Case Else
    ....
  End Select

  If sp.IsCTS() Then
    ....
  ElseIf sp.IsDCD() Then
    ....
  End If
End Sub


Most Functions can be used outside the OnEvent Sub.

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: Serial Port Events

Postby tseyfarth » Sat Dec 11, 2010 5:54 pm

Hi Henning.

What is "Air code"? Thanks for sending that info. The problem is, these are not really "events" but Functions that can be accessed from anywhere. What I am really really looking for is the "event" that tells when the last byte has been shifted out of the buffer into hardware, and when a byte has entered the Rxd buffer. Note that in the "Events Are" section, again there are no events listed. Probably because Mr B never instituted this feature in QextSerial (I think that is the name of it).

What I am looking for CAN be done by using a polling method where you periodically call the function bytesAvailable to see if there is anything in the Rxd buffer, or the function AtEnd() which is a bit confusing, with its teminology "This function will return true if the input buffer is empty (or on error), and false otherwise. " Wherein the "input buffer" could be either the buffer from Txd or Rxd I am not sure. The problem with this, is that it requires periodic "checking" and therefore will not be as fast as it could be.

In any case, none of these are events. The LastErrorText will allow you to find what the last error was but again, is not an event, and LastError are all functions.

Anyway, I really do appreciate your response and effort!

Tim
tseyfarth
 
Posts: 101
Joined: Mon Aug 02, 2010 10:11 am

Re: Serial Port Events

Postby Henning » Sat Dec 11, 2010 8:47 pm

Air Code is something one posts without even trying to compile it, written out of the head.

The comEvSend is neither an Event, it triggers the OnComm eventhandler. Without testing I belived that sp_OnEvent will trigger the same way.
If that is not the case, then I don't recall what it is good for at all, and can understand youre frustration.

I will test it as soon as can.

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: Serial Port Events

Postby tseyfarth » Sat Dec 11, 2010 9:11 pm

Thank you for the clarity. Not really frustrated, just confused and challenged to find the answer :)

According to the MSDN:
comEvSend 1 There are fewer than Sthreshold number of characters in the transmit buffer.
comEvReceive 2 Received Rthreshold number of characters. This event is generated continuously until you use the Input property to remove the data from the receive buffer.

These both are constants representing the value of 1 and 2 respectively. So when the MSCOMM object fires an event, if it is a 1, it is the fact that the number of chars is < Sthreshold. Anyway,

For the QExtSerialPort events, there apparantly are other parameters that have to be set:
"SerialPort.setQueryMode( QextSerialBase::EventDriven );"

where this parameter has to be set to either poll or event mode. But I have never seen anything in the properties of KB to set this either. I have also not been able to find the events that are fired in the QExtSerialPort docs.

There is a work around using the polling method, just perhaps not as "clean".

Tim
tseyfarth
 
Posts: 101
Joined: Mon Aug 02, 2010 10:11 am

Re: Serial Port Events

Postby Henning » Sat Dec 11, 2010 9:52 pm

I posted this in the Q7B forum, don't know if it has any relevance here (or there) ;)

I did some more changes to the SerialPort example code. It compiles, but I can't test at the moment.

In the Declares I added:
Declare Sub "Q7BSerialPort" void setQueryMode(QueryMode mode);

In MainWindow I changed to:
Event Init()
sp!setQueryMode = 1
sp.SetBaudRate("Baud4800")
sp.Open()
' MsgBox(sp.BaudRate())
End Event

Signal sp_OnEvent()
Simulate()
End Signal

Since Polled and EventDriven are in an Enum, just guessing EventDriven = 1.


/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: Serial Port Events

Postby tseyfarth » Sat Dec 11, 2010 10:01 pm

According to Mr B, it has relevance in BOTH places. Q7b uses the same source as KB.
What was the date or can you give me the link to that? I just looked and could not find it for some reason!

I'll test your code.

Tim
tseyfarth
 
Posts: 101
Joined: Mon Aug 02, 2010 10:11 am

Re: Serial Port Events

Postby Henning » Sat Dec 11, 2010 10:31 pm

It was as a reply to you ;)

[url]
http://www.q7basic.org/forum/viewtopic. ... 0&start=10
[/url]

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Next

Return to Coding Questions

cron