syntax of hserin command

JSDL

Senior Member
Hi everyone, I am trying to convert the following code using serin/serout to hserin/hserout but am having trouble with the qualifier and such. Have tried many things but no luck. Any help would be greatly appreciated:

Code:
Setfreq M8


symbol rx = c.2
symbol tx = c.1


high tx
pause 100

main:

serin rx, t9600_8,("set"),#b0

select case b0
case 1
	high b.1
	serout tx, t9600_8,("ON",cr,lf)
case 0
	low b.1
	serout tx, t9600_8,("OFF",cr,lf)
end select

goto main
 

srnet

Senior Member
Note from the manual that the qualifier for HSERIN is a single byte;

hserin
Syntax (X2 parts):
HSERIN spaddress, count {,(qualifier)}
HSERIN [timeout, address], spaddress, count {,(qualifier)}
- Qualifier is an optional single variable/constant (0-255) which must be
received before subsequent bytes can be received and stored in scratchpad


So a qualifier of "OFF", which is not a single constant is not supported.
 

inglewoodpete

Senior Member
Further srnet's reply, a couple of questions. What PICAXE model are you using?

When starting with serial comms, it may be better to comment-out the case structure and use the command SerTxd ("Rec'd: ", #b0, CR, LF) so that you know exactly what is being received on the pin.
 

hippy

Technical Support
Staff member
As noted, HSERIN has fewer in-built parsing capabilities than SERIN, so it can be difficult to translate SERIN code to use HSERIN. There is only a single character qualifier allowed and no numeric string input supported, so you will have issues with both "set" and #b0.

An alternative could be to redesign the protocol you are using so neither qualifiers nor numeric string parsing is necessary. For example you could control your output by sending "H" or "L" commands for high and low respectively.

Using just a single byte isn't as limiting as it may appear and can allow 256 commands controlling one thing through to two commands controlling 128 things.
 

JSDL

Senior Member
the model Picaxe I am using is a 20M2. So would something like this work?

Code:
setfreq m8

main:
hsersetup b9600_8, %00

hserin b0

if b0="H" then
	high b.7
	else
	low b.7
endif
goto main
 
Last edited:

hippy

Technical Support
Staff member
Probably. A more robust and easier to enhance structure would be -

Code:
#Picaxe 20M2
SetFreq M8
HSerSetup B9600_8, %000
Do
  b1 = 1
  Do
    HSerIn w0
  Loop Until b1 = 0
  Select Case b0
    Case "H" : High B.7
    Case "L" : Low  B.7
  End Select
Loop
 

JSDL

Senior Member
ok, so I switched to an 08M2 chip and all of a sudden it works! I can now send text to an LCD display wirelessly. Would still like to know why the same code didn't work on the 20M2, but at least I got it working.
 

JSDL

Senior Member
just out of curiosity, why use a word variable (W0) instead of byte variable in this case? Also, what is the purpose of the loop, to check when nothing has been entered?
 

hippy

Technical Support
Staff member
ok, so I switched to an 08M2 chip and all of a sudden it works! I can now send text to an LCD display wirelessly. Would still like to know why the same code didn't work on the 20M2, but at least I got it working.
Perhaps post your code then members can assess why that may be the case.

just out of curiosity, why use a word variable (W0) instead of byte variable in this case? Also, what is the purpose of the loop, to check when nothing has been entered?
The loop is to ensure something has been received, and w0 is used so the full range of character values 0 to 255 can be received. The w0 is set to a value outside the 0 to 255 range (MSB<>0), and as HSERIN only updates w0 if there is a character, 0 to 255 indicates a character received (MSB=0), otherwise not. The MSB of w0 is b1 the LSB is b0.
 
Top