Below is some code that I use to read info from my WaterRower. I have fully tested on Mac with no problems, if your code looks correct check your hardware usually the next major cause of problems.
dev:wxSerialPort = New wxSerialPort.Create()
?win32
devname = "COM1:"
?MacOS
devname = wxChooseSerialPort()
?
If dev.Open(devname) < 0
'
wxMessageBox("Cannot open " + devname )
dev.free()
Else
' set the baudrate
dev.SetBaudRate(baudrate)
' dev.SetTimeOut(timeout)
m_timer = New wxTimer.Create(Self)
m_timer.Start(120)
EndIf
Connect(wxID_ANY, wxEVT_TIMER, OnTimer)
and now a couple of methods from a wxFrame type
'---------------------------------------------------------------------
Method readCh:Byte()
'---------------------------------------------------------------------
?WRower
Local char:Byte[1]
While dev.read(char,1) = 0
Wend
Return char[0]
?Not WRower
Local c:Byte
Local b:Int[] = [$FF,$14,$21,$FE,$21,$FD,$33,$44,$FE,$22,$FD,$33,$44,$FE,$23,$FE,$24,$FC]
c = b[m_readch]
m_readch :+ 1
If m_readch = 5 Then wxSleep(3) 'Delay(3000)
If m_readch = 0 Then wxSleep(3) 'Delay(3400)
If m_readch > 18-1 Then m_readch = 0
Return c
?
End Method
'
'---------------------------------------------------------------------
Function OnTimer(event:wxEvent)
'---------------------------------------------------------------------
myFrame(event.parent)._OnTimer(wxCommandEvent(Event))
End Function
'---------------------------------------------------------------------
Method _OnTimer(event:wxCommandEvent)
'---------------------------------------------------------------------
Local char:Byte[1]
Select readCh()
Case STARTSTROKE ' FF
m_CSPM = readCh()
m_CS = readCh()
Case DISTANCE ' FE
m_dist :+ Double(readch()) / Double(10.00)
If m_dist < 1.00
m_dist = 0.00
EndIf
Case VELOCITY ' FD series III only
readCh()
readCh()
Case ENDSTROKE ' FC
doVelocityS4()
doEndStroke()
Case HEARTRATE 'FB
m_HR = readCh()
Default
End Select
If m_HR
DebugLog "HR = " + m_HR + " SPM = " + m_CSPM + " CS = " + m_CS + " DIST =" + m_dist
WriteLine outfile,"HR = " + m_HR + " SPM = " + m_CSPM + " CS = " + m_CS + " DIST =" + m_dist
Else
DebugLog " SPM = " + m_CSPM + " CS = " + m_CS + " DIST =" + m_dist
WriteLine outfile," SPM = " + m_CSPM + " CS = " + m_CS + " DIST =" + m_dist
EndIf
EndMethod
|