variable baud rate
Post by hitsware on Jul 24th, 2016, 7:30pm
How may I have baudrate be a variable ?
The below gives me an 'invalid channel'
Code:
FOR x=0 TO 7: READ note
port% = OPENUP("COM4: note ,N,8,1")
FOR y=0 TO 100
BPUT#1,CHR$(85);
NEXT y: NEXT x
DATA 240,270,300,320,360,400,450,480
Re: variable baud rate
Post by DDRM on Jul 25th, 2016, 11:23am
Without the relevant hardware, I can't test this, so treat it with a degree of scepticism, but I imagine the problem is that you need to convert the VALUE of note into a string, and include that, rather than the variable name. You can do that with STR$.
Does this do what you want?
Code:
FOR x=0 TO 7
READ note
port$="COM4:"+STR$(note)+",N,8,1"
port% = OPENUP(port$)
FOR y=0 TO 100
BPUT#1,CHR$(85);
NEXT y
NEXT x
DATA 240,270,300,320,360,400,450,480
I note that you are opening the same channel 8 times: is that really what you want? Should there be a CLOSE#port% before the NEXT X?
Best wishes,
D
Re: variable baud rate
Post by hitsware on Jul 25th, 2016, 4:21pm
Code:
FOR x=0 TO 7: READ note
port$="COM4:"+STR$(note)+",N,8,1"
port% = OPENUP(port$)
FOR y=0 TO 500
BPUT#1,CHR$(85);
NEXT y: CLOSE#1: NEXT x
DATA 240,270,300,320,360,400,450,480
Thank You !
Re: variable baud rate
Post by DDRM on Jul 26th, 2016, 07:49am
Shouldn't that be
BPUT#port%
...
CLOSE#port%
?
You may be lucky and get it allocated to channel 1, but you may not...
Best wishes,
D
Re: variable baud rate
Post by hitsware on Jul 26th, 2016, 3:49pm
Code:
port% = OPENUP("COM1: 9600,N,8,1")
PRINT port%
returns '1'
It works as is
The "channel" is COM4
(depending what and where is plugged in)
(I don't pretend to understand)
Re: variable baud rate
Post by Zaphod on Jul 26th, 2016, 11:13pm
I think you really should take DDRM's advice.
In your particular circumstance it may return 1 as the channel number, but if there is another channel open it won't, so as it stands it is a program that has great potential to fail that can be easily fixed as DDRM mentioned.
You should also check for port% being greater than zero and only BPUT the data if it is, and if it is zero then flag that the port has not opened to the user.
If you issue a CLOSE# port% when your code fails it will close ALL channels, even those open by other parts of the program.
Programs that are robust and that protect against failure and tells you what is going on if it does fail are so much more useful I think.
Code:
FOR x=0 TO 7
READ note
port% = OPENUP("COM4: "+STR$(note)+" ,N,8,1")
IF port% THEN
FOR y=0 TO 100
BPUT#port%,CHR$(85);
NEXT
CLOSE# port%
ELSE
PRINT "Port not opened ",note
ENDIF
NEXT
END
DATA 240,270,300,320,360,400,450,480
Re: variable baud rate
Post by hitsware on Jul 28th, 2016, 11:24pm
Thanks Guys ......
Moot anyways. I was thinking using it for music,
but forgot the obvious (duh) Changing the baud changes
the timing so doesn't keep a beat
Re: variable baud rate
Post by DDRM on Jul 29th, 2016, 07:12am
No, but the changes are known, so as long as you know the previous and new baud rates you can calculate how much to change the beat frequency or duration by?
Best wishes,
D