Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Can't get the hang of reading Com port

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-10-2009, 12:53 AM
Basic4ppc Veteran
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 271
Awards Showcase
Beta Tester 
Total Awards: 1
Default Can't get the hang of reading Com port

I have a piece of calibration equipment that I'm attempting to write a desktop application to read from its Com port. The calibration equipment will either send its datastream when a button is pressed on its front panel, or when RTS is asserted. The manual states it may service up to 5 requests per second. If RTS is asserted (and remains so), it will only send one reading, it has to be cancelled and reasserted again for the next one.

Fairly regularly I get gobbledegook in the textbox - but I'm sure its because I'm not reading the incomming stream properly. I have to use an 'OnComm' event for the times the front panel button is pressed. I've never quite understood the triggering of OnComm: instuctions in the OnComm may be being executed as more data is arriving in the buffer(?)

Parameters are fixed at 1200,8,N,1

'TWA1000Sim' is a simulator of the calibration equipment and behaves exactly the same. (The big 'O' button simulates the on/off switch ) I compile this for the Device and run it on my TDS Recon connected via RS232 to the desktop. It will compile for the desktop too.
Attached Files
File Type: zip TWA.zip (2.2 KB, 14 views)
Reply With Quote
  #2 (permalink)  
Old 03-10-2009, 02:14 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

The OnCom is fired only when the buffer state changes from empty buffer to buffer with some data.
Make sure that the buffer is empty before leaving the OnCom event sub.
Reply With Quote
  #3 (permalink)  
Old 03-10-2009, 02:29 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by Zenerdiode View Post
I but I'm sure its because I'm not reading the incomming stream properly.
That's correct!
Quote:
I have to use an 'OnComm' event for the times the front panel button is pressed.
No, you can use it all the time. Just waggle RTS and OnNCom will collect the data.
Quote:
I've never quite understood the triggering of OnComm: instuctions in the OnComm may be being executed as more data is arriving in the buffer(?)
OnCom is raised when data is available. As the OS buffers the Serial Port for you it can collect more data while your OnCom code runs so you don't lose any characters. You need to realise that data won't necessarily arrive in neat ready parsed lumps. Try changing your Label1 to a great big multiline textbox and do this
Code:
Sub Port_OnCom
  ReceivedString=ReceivedString&Port.InputString
  TextBox1.Text = ReceivedString
End Sub
You will see the regular stuff coming from waggling RTS and the extra when you press the button, all arriving correctly interleaved. You just need to parse this incoming stream properly.
Reply With Quote
  #4 (permalink)  
Old 03-16-2009, 12:58 PM
Basic4ppc Veteran
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 271
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by agraham View Post
Try changing your Label1 to a great big multiline textbox and do this
Code:
Sub Port_OnCom
  ReceivedString=ReceivedString&Port.InputString
  TextBox1.Text = ReceivedString
End Sub
You will see the regular stuff coming from waggling RTS and the extra when you press the button...
I tried that and after many, many ours of different fixes in my code and using a Comtest RS232 Line Monitor, I loaded the test application onto a computer that has a legacy RS232 Com port - instead of the USB>RS232 lead I had been using on my modern laptop - and it works perfectly.

I know USB>RS232 ports have an increased latency, but I didn't think it would affect my simple program(!) It didn't like the RTS being changed too quickly. If I waggled RTS once every two seconds; the data read by OnCom would be fine, but increasing the sampling to once a second started to corrupt data. If the RTS was left alone and data was 'gunned' at it, the OnCom handled it well. Because my application will eventually run on a Desktop (thankfully with a legacy port) I can now sample at a rate of 500ms.

The data returned from the measurement equipment is only a maximum of 16 bytes @ 1200 Baud per request so I've been carefull not to oversample.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading binary files jgm Questions (Windows Mobile) 5 05-28-2008 10:09 AM
Reading config file Mr_Gee Questions (Windows Mobile) 6 03-15-2008 11:00 AM
reading and editing registry Dr. Feelgood Questions (Windows Mobile) 3 02-16-2008 07:18 AM
Reading MP3 ID3 tags, any ideas??? kronos79 Forum Discussion 2 11-10-2007 10:57 AM
Reading status of CTS Paul Questions (Windows Mobile) 2 06-19-2007 08:34 AM


All times are GMT. The time now is 04:03 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0