SERIN input formatting
deans
Posts: 9
I am trying to split serial input into different variables.
From the reference I can not decipher how to do this correctly.
I would like to send a text followed by a number that determines the number of characters of the text.
eg. Hello 5
I thought I would do it like this:
Hello*_5
storing Hello into serStr and 5 into lim, using code along these lines:
SERIN 16, 16468, [STR serStr\"*", WAIT("_"), DEC2 lim]
But this is not working, why?
Also, I dont like having to use the WAIT command, is there another way to do this?
Best wishes
Dean
From the reference I can not decipher how to do this correctly.
I would like to send a text followed by a number that determines the number of characters of the text.
eg. Hello 5
I thought I would do it like this:
Hello*_5
storing Hello into serStr and 5 into lim, using code along these lines:
SERIN 16, 16468, [STR serStr\"*", WAIT("_"), DEC2 lim]
But this is not working, why?
Also, I dont like having to use the WAIT command, is there another way to do this?
Best wishes
Dean
Comments
SERIN 16, 16468, [STR serStr\"*", DEC lim]
to read:
Hello*5,
where "," could be any non-digit delimiter
Thank you for your input. I have tried your code. Unfortunately, for some reason it does not work as intended.
I then also tried:
' {$STAMP BS2}
' {$PBASIC 2.5}
lim VAR BYTE
serStr VAR BYTE(20)
SERIN 16, 16468, [DEC lim, STR serStr\lim]
DEBUG "lim: ", DEC lim, CR
DEBUG "serStr: ", STR serStr, CR
Again, it does not work (DEBUG output):
6,FISH
lim: 6
serStr: ,Tj֙
SERIN 16, 16468, [DEC lim, STR serStr\19\"*"]
Note that the length has to allow for a zero byte at the end. Sorry I didn't mention this earlier.
When I do a simple STR read with SERIN everything works fine. I can then execute the rest of the code and do LOOKUP and LOOKDOWN.
The simple separation of a number and text into different variables fails with all suggested solutions so far...
Best
Dean
Assuming you are using Mikes example the best way to display your string would be like this
That's assuming the value lim matches the number of characters sent, 6 and FISH might not work but 7 and FISHING will.
If that doesn't do it we need to see an example of how the data is transmitted and the program you are using.
Jeff T.
I have no doubt, that both of you know what you are talking about.
If you could help me to figure out the communication problem I would be very glad!
I am using mac os x. With a PL2303 driver compatible usb to serial converter.
Currently I am using the goSerial.app, since I could not yet figure out how to use minicom to send a string of carracters on minicom (the setup worked, I can receive data but just dont know how to send).
I sure hope the PL2303 drive is not the problem? It is the original one, I think from sourceforge.
For communication with the bs2 homework board, I use the MacBS2 software.
How could we go about deciphering the problem I have?
Best
Dean
Try this just to make sure it works, here's the main part of the code
Now from the Pbasic DEBUG terminal type in something like 5deans*
I'm sure you will have this solved pretty soon, let us know if that test works.
Jeff T.
the MacBS2 doesn't have a debug window like Parallax's Basic IDE for Windows.
I can only receive on MacBS2, not send...
Sincerely
Dean
SEROUT 16, 16780, ["lim: ", DEC lim, CR]
That was it. At 2400 it works like a charm!
Thank you.
Sincerely
Dean
I'm new on this topic and I'm trying to activated 16 relays one at a time using a serin and keyboard.I'will like to knwo if it is possible using a letters,for example to activate P0 with a letter "A",P1 with letter "B"...............
regards
Victor
I'm using this code found in internet ,but it only activate 10 relay, so I'w like to activate 16
' {$STAMP BS2}
' {$PBASIC 2.5}
caracter VAR Byte
Principal:
DEBUG 2,1,1,"Select one [0 - 9]", CR
SERIN 16, 16468, [DEC1 caracter]
BRANCH caracter,[P0, P1, P2, P3, P4, P5, P6, P7, P8, P9]
DEBUG CLS
DEBUG 2,1,2,"No one select"
PAUSE 1500
DEBUG CLS
P0:
DEBUG 2,2,4,
HIGH %000000000
LOW %000000001
LOW %000000010
LOW %000000011
LOW %000000100
LOW %000000101
LOW %000000110
LOW %000000111
GOTO Principal
P1:
DEBUG 2,2,4,
LOW %000000000
HIGH %000000001
LOW %000000010
LOW %000000011
LOW %000000100
LOW %000000101
LOW %000000110
LOW %000000111
GOTO Principal
P2:
DEBUG 2,2,4,
LOW %000000000
LOW %000000001
HIGH %000000010
LOW %000000011
LOW %000000100
LOW %000000101
LOW %000000110
LOW %000000111
GOTO Principal
P3:
DEBUG 2,2,4,
LOW %000000000
LOW %000000001
LOW %000000010
HIGH %000000011
LOW %000000100
LOW %000000101
LOW %000000110
LOW %000000111
GOTO Principal
P4:
DEBUG 2,2,4,
LOW %000000000
LOW %000000001
LOW %000000010
LOW %000000011
HIGH %000000100
LOW %000000101
LOW %000000110
LOW %000000111
GOTO Principal
P5:
DEBUG 2,2,4,
LOW %000000000
LOW %000000001
LOW %000000010
LOW %000000011
LOW %000000100
HIGH %000000101
LOW %000000110
LOW %000000111
GOTO Principal
P6:
DEBUG 2,2,4,
LOW %000000000
LOW %000000001
LOW %000000010
LOW %000000011
LOW %000000100
LOW %000000101
HIGH %000000110
LOW %000000111
GOTO Principal
P7:
DEBUG 2,2,4,
LOW %000000000
LOW %000000001
LOW %000000010
LOW %000000011
LOW %000000100
LOW %000000101
LOW %000000110
HIGH %000000111
GOTO Principal
P8:
DEBUG 2,2,4,
LOW %000000000
LOW %000000001
LOW %000000010
LOW %000000011
LOW %000000100
LOW %000000101
LOW %000000110
LOW %000000111
LOW %000001000
GOTO Principal
P9:
DEBUG 2,2,4,
HIGH %000000000
LOW %000000001
LOW %000000010
LOW %000000011
LOW %000000100
LOW %000000101
LOW %000000110
LOW %000000111
HIGH %000001000
GOTO Principal
Thanks.
Victor
The program you posted only requests a single digit (SERIN 16, 16468, [DEC1 caracter]), so it only allows for 0-9. If you want to allow bigger numbers, you can use DEC instead of DEC1 or you could use DEC2 and require two digits all the time. If you use DEC, you have to put some kind of delimiter after the number when you enter the number. This could be a carriage return or space or comma or almost any non-digit character. Read the description of the SERIN statement and the "formatters" (in Appendix C) in the BASIC Stamp Syntax and Reference Manual for details.
You could also use HEX1 instead of DEC1 and this would allow the use of 16 "digits" (0-9 and A-F or a-f)