PDA

View Full Version : HSERIN qualifier



Charles Linquis
- 13th December 2009, 23:44
I have never used the DEC and HEX qualifiers in the HSERIN command.

If I issue the command

HSERIN [HEX X]

Does that convert a received "A2" received as two ASCII characters into
binary %10100010 and put that in the variable X?

Or - does it just filter out any ASCII character that isn't in the range of "0" to "9" or "A" to "F" and save a "0" as 0x30 to X?

Just what does it do?

mackrackit
- 14th December 2009, 01:18
Basically the modifiers tell PBP what to expect.
With out a modifier PBP will treat the input as a Display Key:
A2 will be broke into 65 and 50.


HSERIN [X]
HSEROUT [DEC X,13,10]

The above will, if sent A2 will output to a terminal


65
50
13

If the BIN modifier is used PBP will do nothing with A2 because A2 is not binary.
If A1 or A0 is received with
HSERIN [BIN X]
Then
HSEROUT [DEC X,13,10]
will return
1 or 0
The A is ignored.

Charles Linquis
- 14th December 2009, 02:38
Thanks!

I already have a short routine that converts ASCII HEX into binary ("A" "2" = %10100010), but I thought if PBP did it automagically, I would use that routine instead. Oh well.

Darrel Taylor
- 14th December 2009, 05:59
It most certainly will.

HSERIN [HEX2 X]

Will receive "A2" as %10100010 or $A2.

It's easiest to have a fixed length field.
So 2 would be sent as "02".

hth,

mackrackit
- 14th December 2009, 11:30
HSERIN [HEX X]
HSEROUT [DEC X.7,13]
HSEROUT [DEC X.6,13]
HSEROUT [DEC X.5,13]
HSEROUT [DEC X.4,13]
HSEROUT [DEC X.3,13]
HSEROUT [DEC X.2,13]
HSEROUT [DEC X.1,13]
HSEROUT [DEC X.0,13]
HSEROUT ["BIN",13]
HSEROUT [BIN X,13]

http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3825&stc=1&d=1260790030

Charles Linquis
- 14th December 2009, 11:53
Thanks guys,

The routine below is supposed to take comma-delimited strings and convert them to binary. It should handle the sequence 02,A,A2 for example, properly.




Preparser:
HSERIN [Wait (":")] ; wait for colon to start
GrabAscii:

HSERIN 500,NoMoreInput,[ASCIN [Y]] ; Load it into small array, first char goes into element zero

IF ASCIN [Y] = "," THEN ; Found a comma This will never be in element zero , but
; may exist in element 1

SELECT CASE Y
CASE 1
MSB = 0
LSB = ASCIN[Y-1]
CASE 2
MSB = ASCIN[Y-2]
LSB = ASCIN[Y-1]
CASE ELSE
HSEROUT ["INPUT ERROR"]
PAUSE 2500
END SELECT

GOSUB IHEX2BIN

OUTARRAY[Z] = ByteVal ; load variable into array
Z = Z + 1
Y = 0 ; Clear Y if we found a comma
ENDIF
Y = Y + 1

Goto GrabAscii


NOMoreInput:

......


';************************************************ **************
'; Routine takes HEX Ascii chars
'; and converts to BIN
'; Inputs MSB, LSB ("0" to "F")
'; Outputs ByteVal
';************************************************ ***************
IHEX2BIN:
LOOKDOWN MSB,["0123456789ABCDEF"],ByteValH
LOOKDOWN LSB,["0123456789ABCDEF"],ByteValL
ByteVal = (ByteValH << 4) + ByteValL
RETURN
';************************************************ ***************





It is nearly 4 A.M here in CA. Time to go to work and see how the code works!