SerialStream usage

Discuss OrbForms Designer and PocketC Architect

Postby lazarus on Thu Aug 11, 2005 4:58 am

I am trying to use the SerialStream object for serial port data acquisition. My test setup includes a PDA and a computer. I can write from the PDA to the computer, but I have not been able to receive any data from the computer back to the PDA. I ran a separate serial app to verify the computer was sending information.
My code looks as follows:

// Create the serial port object.
Serial oSerial;
SerialStream serStream;

// mainform.oc
// Created for mainForm

handler mainForm.onopen() {
// Use the timer to repeat the polling cycle.,9600);
serStream.serial = oSerial;

// Start the forms timer handler.

handler mainForm.ontimer() {
string strIO;

// Write to the serial stream.

// Repeat every 2 seconds.
sleep (2000);

// Read from the serial stream.

// Update the field.
fldSerialInput.text = strIO;


// Reset the auto off timer.

One other hint. I displayed the result from the serStream, and it always returned 0, or false indicating some sort of error. Has anybody tried using the SerialStream with success? Thanks.
Posts: 8
Joined: Sun Jul 24, 2005 9:23 pm

Postby lazarus on Sun Aug 14, 2005 11:46 pm

Here is a workaround for using the SerialStream object. I never could get the "readString" function to work. However, the "read" function did work, with just a little extra work.

handler mainForm.ontimer() {
char c[512];
char* pc;

pc = c;

// Read from the serial stream. The default serial object buffer size is 512 bytes.,typeof(*pc),512);
fldSerialInput.text = strctos(pc);

// Repeat every 2 seconds.

// Write to the serial stream.

// Reset the auto off timer.

I switched from the "sleep" to the "timer" function to prevent unwanted "hang ups". Also note that I correctly set the nticks value in the "timer" function this time (1 tick = 1/100 sec.). If anyone uses the "readString" function with a string type variable, please post it so I can see what I was doing wrong.
Posts: 8
Joined: Sun Jul 24, 2005 9:23 pm

Postby dewey on Wed Aug 17, 2005 3:49 am

Stream.readString() reads until it gets a NULL character, not end-of-line. So, it was probably timing out.
Site Admin
Posts: 749
Joined: Sun Oct 21, 2007 5:12 am

Postby md10bldr on Tue Aug 30, 2005 7:25 pm

So I've messed with the serStream.readString and serStream.writeString commands, and can get my PC(with Palm emulator) to send and receive serial data to/from an external PPC. I do have a couple of questions though.
1.) The example code above is basically polling the serial port. I've searched through the help file, but haven't seen anything that would indicate that receipt of serial data (Comm, BT, or IR) triggers any kind of system event that would go to an event handler. Is this true?

2.) The addition of the (null) to the end of a string when using "readstring" - As a relatively inexperienced programmer, is this something I'm suppose to know (something associated with the use of streams)? Since there's nothing in the help file, I doubt I would have ever gotten this working without the forum. How many more things like this are there?
Posts: 17
Joined: Wed Dec 04, 2002 6:55 pm

Return to OrbForms Designer and PocketC Architect

Who is online

Users browsing this forum: No registered users and 2 guests