BBC BASIC for Windows
« variable baud rate »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:53pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: variable baud rate  (Read 606 times)
hitsware
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 70
xx variable baud rate
« Thread started 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
 
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: variable baud rate
« Reply #1 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
« Last Edit: Jul 25th, 2016, 11:26am by DDRM » User IP Logged

hitsware
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 70
xx Re: variable baud rate
« Reply #2 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 !
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: variable baud rate
« Reply #3 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
User IP Logged

hitsware
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 70
xx Re: variable baud rate
« Reply #4 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)
User IP Logged

Zaphod
Guest
xx Re: variable baud rate
« Reply #5 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
 

User IP Logged

hitsware
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 70
xx Re: variable baud rate
« Reply #6 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 sad
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: variable baud rate
« Reply #7 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
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls