SERIN question
I have a question that someone probably has run into before:
I'm using SERIN to send commands to a BS2sx from a PC. I send a single character "b" to start execution and then I would like to send a single character· "c" to stop.
Starting is easy, I just do like this:
To stop I have tried this (placed in a loop that is repeated once every second):
It works but the stop command must come exactly when·the BS2sx·looks for it. The PC must send it over and over again for one second to make sure that·execution stops (goes to "command".
Can I make this smarter? That is, the PC can send the "c" only once and still be sure to stop execution?
·
I'm using SERIN to send commands to a BS2sx from a PC. I send a single character "b" to start execution and then I would like to send a single character· "c" to stop.
Starting is easy, I just do like this:
'Wait for command to start command: SERIN 16, 16624, [noparse][[/noparse]c] IF c<>98 THEN command 'Invalid command 'Execution starts..
To stop I have tried this (placed in a loop that is repeated once every second):
'Look for stop command SERIN 16, 16624, 300, jump, [noparse][[/noparse]c] 'Look for command, with timeout IF c=99 THEN command 'Stop command received, stop execution jump: 'Continue execution...
It works but the stop command must come exactly when·the BS2sx·looks for it. The PC must send it over and over again for one second to make sure that·execution stops (goes to "command".
Can I make this smarter? That is, the PC can send the "c" only once and still be sure to stop execution?
·
Comments
The first receives an input, performs a task 1 time, and goes back to looking for another input.
The second is a modification of the first. It continues looping a task until it receives a stop command.
I'm not a PBasic expert, so these probably aren't the most efficient algorithms. If anybody has improvements, please post them.
The "serin_sample2.bs2" program has a structure similar to my program. But (as far as I can tell) it has the same problem as mine = the stop command must come within a short period of time.
Your code:
BStamp has limitations; First of all it has no buffer for serial indata. Secondly it has not real interrupt. In all, it's not able to do what I want (react directly to an asyncronous serial command).
Or am I wrong? Perhaps POLLIN could be used in some clever way?
I would, of course, be possible to add a UART with buffer (like MAX3100) but I'd rather not do that as I try to keep it simple.
·
I can't help you with poll mode, but for the example that I posted, changing the TIMEOUT2 value will adjust howw long the BS2 waits for the stop command before going on to WhatNext.