Menu

USB Serial Ports

Anonymous
2015-12-11
2020-02-22
  • Anonymous

    Anonymous - 2015-12-11

    Hi Guys:

    I just found your very nice PC-BASIC. And it runs well on my Vista machine.

    However, I have a problem:
    1. I need to use the serial ports to drive an FE5680A Rubidium Frequency reference.
    2. I control it now using TeraTerm terminal emulator, this works well.
    3. The serial interface is on COM:20 at 9600bps. This is a USB port.
    4. While a terminal is useful, I need an active program to run it. I wrote a GW-Basic program that does this. This worked in an old XP machine that had "Real" com ports, not USB ports. USB ports are now the only thing available. I'm trying to get that program to run in my modern laptop.
    5. Since PC-BASIC only has basic's COM1 or COM2.

    I haven't figured out how to get this to work yet.
    1. The download package didn't have a PCBASIC.INI example.
    2. I found some info in the "Options" part of the documentation. I don't know how to put options in the INI file.
    3. Can you give me an example INI file to make it work with my USB ports? I have both COM6 and COM20 available to play with.

    Oh yes, What's the definition of "Command Line"?
    1. It seems that within basic a "Command Line" is what you use to enter programs, i.e. 10 A = B+C.
    2. But it also seems a "Command Line" is also what is after the name of a program, i.e. PCBASIC interface=cli. (As in Command Line Interface.)
    It appears these two terms are often used, but I don't know the difference?

    Thanks!!!
    Duane
    redrok@redrok.com

     
    • Rob Hagemans

      Rob Hagemans - 2015-12-12

      Hi Duane!

      You need to tell PC-BASIC to use your Windows COM20 as BASIC's COM1: using the option com1=COM20. You can of course vary this to use BASIC's COM2: and your USB COM6, etc.

      Using the command line

      The easiest way is to play around on the command line (by which I mean the Windows CMD terminal; the one that gives a C:\> prompt, and not anything within BASIC. I suspect the documentation is indeed somewhat sloppy and confusing on this point).

      To set the com1=COM20 option, after the C:\> prompt you'd type something like:

      "C:\Program Files\PC-BASIC\PCBASIC.COM" --com1=COM20 --com2=COM6
      

      where the path to the executable may be different on your machine, e.g. on 64-bit machines it's probably "C:\Program Files (x86)\PC-BASIC\PCBASIC.COM". This would enable both USB adapters as COM1: and COM2: in BASIC.

      Alternative: using the INI file

      Alternatively, you should find an INI file in your roaming profile directory, which is a path like
      "C:\Documents and Settings\Duane\AppData\Roaming\PC-BASIC" where I'm assuming your user name is Duane. The actual location is a bit different between Windows versions and WIndows seems to hide this location by default (which I think is completely crazy as this is the official place to put settings files, but there you go).

      Another way of getting there is to type %APPDATA% in the Windows Explorer and then select the folder Roaming, then PC-BASIC.

      There should be a text file in that folder which depending on your Windows settings shows up as PCBASIC or PCBASIC.INI or some version of that; you can edit this in Notepad to add lines

      com1=COM20
      com2=COM6
      

      which does the same thing as using the command line option. Don't put dashes (--) in front of the option in the INI file.

      If you can find the PC-BASIC directory in your AppData profile folder but there's no INI file, you can just create one with Notepad.


      Let me know how it goes - I'm interested to know if the serial ports work OK in PC-BASIC for what you need to do, as I don't have any serial devices to test with myself.

      Hope this helps,
      Rob

       
      • Anonymous

        Anonymous - 2015-12-15

        http://sourceforge.net/p/pcbasic/discussion/general/thread/5ab86229/
        USB Serial Ports

        Hi Rob:

        I've tried all your suggestions for redirecting the com ports
        but none work.

        I tried both the INI and cmd.exe methods.
        I made a simple basic program called X.BAS that only tries to send
        a character string out basic com1.
        1. I did find the PCBASIC.INI file and edited it to contain:

        [pcbasic]
        com1=com20
        com2=com22
        

        I made a batch file, X1.BAT, to automate starting pcbasic, it contains:

        CD C:\DOWNLOAD\PC-BASIC\
        PCBASIC.COM X.BAS
        

        However, cmd.exe reports:

        WARNING: Could not attache com20 to COM device
        WARNING: Could not attache com22 to COM device
        

        X.BAS reports errors when accessing the coms.
        Both when initializing and printing to the com1 port.

        1. I tried the second method using Basic command line.
          Again I used a batch file, X2.BAT
        CD C:\DOWNLOAD\PC-BASIC\
        PCBASIC.COM X.BAS --com1=com20 --com1=com22
        

        However, cmd.exe also reports:

        WARNING: Could not attache com20 to COM device
        WARNING: Could not attache com22 to COM device
        

        X.BAS reports errors when accessing the coms.
        Both when initializing and printing to the com1 port.

        My guess is that the redirection is sent to cmd.exe in both
        methods but cmd.exe did not like the format it was sent.

        OK, so I tried these combinations:

        COM1:=COM20:
        COM1=PORT:COM20
        COM1:=PORT:COM20:
        

        All to no avail with the same exact results.
        I'm stumped???

        Do you have any other suggestions?

        I know the com ports work a I can use them from TeraTerm.
        (Yes, I know I need to disable TeraTerm when using PCBASIC
        otherwise there would be a conflict.)
        BTW this is a Vista machine and the lines of code in X.BAS with errors are:

        1110  OPEN "COM1: 9600,N,8,1,RS,CS0,DS0,CD0" AS#1:REM <--- ERROR
        2210  INPUT#1,PIN$   :REM <--- ERROR
        2310  INPUT#1,PINACK$:REM <--- ERROR
        

        Thanks!!!
        Duane
        redrok@redrok.com

         
    • Smithdoor

      Smithdoor - 2020-02-22

      Is possible in basic to seen data between computers via Wi-Fi or LAN

      Thank you
      Dave

       
  • Rob Hagemans

    Rob Hagemans - 2015-12-15

    Hi Duane,

    I think the basic program X.BAS is fine, but PC-BASIC has a problem connecting to the serial ports (as per the warning messages).

    Can you try (in the INI file):

    com1=COM20:
    

    with the bit before the equals sign all lower case and no colons before the equals sign but using the colon afterwards. On the command line that would be:

    pcbasic.com --com1=COM20:
    

    Alternatives that might work as well:

    com1=PORT:COM20:
    com1=PORT:19
    com1=19
    

    Again, all lowercase before the equals sign, and there should never be a colon before the equals sign.

    Let me know how it goes.

    Cheers,
    Rob

     
  • Rob Hagemans

    Rob Hagemans - 2015-12-16

    Two more things!

    1) I checked the source code and you can't actually leave out the PORT: specification. Apologies, I thought this was a default but that's not the case.

    2) I've checked some Microsoft sources - the colon at the end of the port name seems not to be necessary. However, apparently Windows doesn't always recognise port names of the form COM20 when the number is 10 or higher. In that case, you can still use the full WIndows path \\.\COM20.

    So all in all you should try one of the following options for COM20:

    com1=PORT:COM20
    com1=PORT:\\.\COM20 
    com1=PORT:19
    

    All of them are case sensitive. Note that if you just specify a number, it starts counting from zero so PORT:COM1 equals PORT:0 etcetera.

    Hope this works for you - in another thread (https://sourceforge.net/p/pcbasic/discussion/general/thread/3bca703c/#934f) someone else reported being able to open a connection on COM37 with the command line option --com2:PORT:COM37.

    Let me know how it goes.

    Rob

     
  • Anonymous

    Anonymous - 2015-12-17

    Hi Rob;
    I haven't had any luck with all the variations.
    I have found that it makes no difference whether I start
    using the "INI" or the "PCBASIC Command Line". Exactly the
    same errors occur either way.

    I find it's much easier to play around with the command line
    methed. Just edit the match file and away it goes.

    I'm giving you examples of all my files.

    "X.BAS" Used in all the tests:
    10 CLS:COLOR 14:LOCATE 6,1:PRINT"RUN ";CHR$(34);"X.BAS";CHR$(34)
    20 OPEN "com1: 9600,N,8,1,RS,CS0,DS0,CD0" AS#1
    30 PRINT #1,"S"          :rem Command to read parameters from the FE5680A
    40 INPUT #1, PIN$
    50 PRINT ">";PIN$;"<"    :rem the carrots help me see if anything happens.
    60 INPUT #1, PINACK$
    70 PRINT ">";PINACK$;"<" :rem the carrots help me see if anything happens.
    80 CLOSE #1
    90 STOP
    

    "XCMD.BAT" Batch file to test using the command line method:

    CD C:\DOWNLOAD\PC-BASIC\
    PCBASIC.COM X.BAS --com1=PORT:\\.\COM20
    

    "PCBASIC.INI" INI method
    This is in this directory:
    C:\Documents and Settings\Shirley\AppData\Roaming\pcbasic

    [pcbasic]
    com1=PORT:COM20:
    com2=PORT:COM22:
    

    "XINI.BAT" Batch file for INI method

    CD C:\DOWNLOAD\PC-BASIC\
    PCBASIC.COM X.BAS
    

    BTW, is there a CMD.EXE command that will send all the error
    messages to a text file, possibly CMD.TXT.
    Some CMD.EXE errors are quite lengthy and they dissapear once
    PCBASIC crashes so I can't read them. Something like:
    error > cmd.txt
    That's not right but like that. It might be a great help.

    Duane
    redrok@redrok.com

     
    • Rob Hagemans

      Rob Hagemans - 2015-12-17

      Hi Duane, thanks for all the details!

      When you're saying PC-BASIC crashes, can you describe what happens? Does the PC-BASIC interpreter stop functioning and/or exit? If so, there's a bug somewhere in my code so I'd like to find out more.

      You can send the command-line warnings and errors to a file errors.txt if you call PC-BASIC as follows:

      PCBASIC.COM X.BAS --com1=PORT:COM20 --logfile=errors.txt
      

      The file should appear in the working directory, so if you did CD C:\DOWNLOAD\PC-BASIC\ that's the folder where the file should appear. The --com1 setting should be whichever one makes it crash.

      In fact, you should be able to capture any BASIC errors on screen as well, as follows:

      PCBASIC.COM X.BAS --com1=PORT:COM20 --logfile=errors.txt --output=output.txt
      

      (All on one line, though it gets broken into two lines on my screen). Could you make it crash again, then paste or attach the contents of those files to a forum post? Thanks!

      Rob

      (By the way, in general in CMD.EXE you can record output with >cmdoutput.txt and errors with 2>cmderrors.txt after the command, see here: https://support.microsoft.com/en-us/kb/110930 . The link is for XP but this should also work on later versions. PC-BASIC also has the options I use in the commands above where it will capture errors and output itself.)

       
  • Anonymous

    Anonymous - 2015-12-17

    Hi Rob;

    I'm not sure but there may be a reason the USB COM ports can't work is there may be a problem
    with the actual OPEN instruction itself.
    OPEN "com1 9600,N,8,1,RS,CS0,DS0,CD0" AS#1
    doesn't cause an error. However, this doesn't pass the musterd when reading the manuels.
    Everyone specifies this form:
    OPEN "com1: 9600,N,8,1,RS,CS0,DS0,CD0" AS#1
    ^ With a colon.
    Now PCBASIC goes on to my input atatement:
    INPUT #1, PIN$
    This crashes PCBASIC and returns to CMD.EXE.
    My guess is CMD.EXE passes com1, using com1=COM20 and several other forms without
    the colon, to PCBASIC, but PCBASIC doesn't recognize this as an OPEN statement, and ignores
    the rest. This crashes on the INPUT statement because the AS#1 was not done in the INPUT
    statement.

    I tried to make CMD.EXE save the error info as you sugested, but I don't know how to do it in my
    batch file XCMD.BAT.

    CD C:\DOWNLOAD\PC-BASIC\ PCBASIC.COM X.BAS com1=COM20 1>output.msg 2>output.err --logfile=errors.txt --output=output.txt

    Is this the correct form?
    What should it be>

    Duane
    redrok@redrok.com

     
    • Rob Hagemans

      Rob Hagemans - 2015-12-17

      Hi Duane, the BASIC syntax stays the same, so the OPEN command needs a colon just as the manuals say. This is independent of the setting at the command line.

      The fact that it crashes means to me that it probably does manage to connect to the serial port, but hits on an error in the code, which I will need to find. If there were a problem in your BASIC program, it should give an error but never crash PC-BASIC.

      To find out what happens at the crash, it would be really useful if I could see the error messages on the command line. The correct form in your batch file would be

      CD C:\DOWNLOAD\PC-BASIC\
      PCBASIC.COM X.BAS --com1=PORT:COM20 --logfile=errors.txt --output=output.txt
      

      Note that all the options are case senstive and get two dashes in front at the command line and everything after PCBASIC.COM goes on one line in your file. You won't need the form with the > signs.

      Rob

       
  • Anonymous

    Anonymous - 2015-12-18

    X.BAS

    21 OPEN "com1: 9600,N,8,1,RS,CS0,DS0,CD0" AS#1
    31 PRINT #1, "S"
    41 INPUT #1, PIN$
    51 PRINT ">";PIN$;"<"    :rem the carrots help me see if anything happens.
    61 INPUT #1, PINACK$
    71 PRINT ">";PINACK$;"<" :rem the carrots help me see if anything happens.
    81 CLOSE #1
    91 STOP
    

    XCMD.BAT

    CD C:\DOWNLOAD\PC-BASIC\
    PCBASIC.COM X.BAS --com1=PORT:COM20 --logfile=errors.txt --output=output.txt
    

    output.txt

    Bad file name in 21 
    Okÿ
    

    errors.txt
    (empty)

    There is not a lot of info there.

    The
    1>output.msg 2>output.err
    The CMD.EXE commands to get the CMD.EXE outputs.
    Where do I put them?

    I'm not a "Coder", I'm more of a "User". Prety good at Basic though.
    Duane
    redrok@redrok.com

     
  • Rob Hagemans

    Rob Hagemans - 2015-12-18

    Hi Duane, that's quite useful information!

    It looks like the problem is not with the COM20 port connection, since there are no more warnings about that. (If errors.txt is created, but is empty, that simply means there are no warnings or errors on the command line). So that's progress!

    We now run into a Bad file name at the OPEN statement.

    Can you try a few things in line 21:
    First, if there is a space between the COM1: and 9600, can you remove it? Not sure if this is allowed by GW-BASIC (will have to check) but it's possible that PC-BASIC doesn't deal with it correctly.
    If something works differently after this (another error, a crash), please let me know with the log files as you did above.

    Second, can you try with line 21 as follows:

    21 OPEN "com1:" AS #1
    

    Again, if anything is different, let me know.

    You mentioned a crash earlier, where PC-BASIC would stop working on the INPUT statement, can you still reproduce this? If so, could you send me the log files for that case?

    You don't need to do anything with the 1>output.msg 2>output.err, that was just some extra information. We're getting all the outputs we need this way.

    Thanks!
    Rob

     
  • Anonymous

    Anonymous - 2015-12-18

    Hi Rob;
    X.BAS

    21 OPEN "com1:9600,N,8,1,RS,CS0,DS0,CD0" AS#1
    31 PRINT #1, "S"
    41 INPUT #1, PIN$
    51 PRINT ">";PIN$;"<"    :rem the carrots help me see if anything happens.
    61 INPUT #1, PINACK$
    71 PRINT ">";PINACK$;"<" :rem the carrots help me see if anything happens.
    81 CLOSE #1
    91 STOP
    

    XCMD.BAT

    CD C:\DOWNLOAD\PC-BASIC\
    PCBASIC.COM X.BAS --com1=PORT:COM20 --logfile=errors.txt --output=output.txt
    

    output.txt
    (empty)
    errors.txt

    ERROR: Unhandled exception
    Traceback (most recent call last):
      File "E:\pc-basic\packaging\windows\build\installer\out00-PYZ.pyz\pcbasic.__main__", line 168, in start_basic
      File "E:\pc-basic\packaging\windows\build\installer\out00-PYZ.pyz\pcbasic.run", line 46, in start
      File "E:\pc-basic\packaging\windows\build\installer\out00-PYZ.pyz\pcbasic.run", line 60, in run_once
      File "E:\pc-basic\packaging\windows\build\installer\out00-PYZ.pyz\pcbasic.statements", line 108, in parse_statement
      File "E:\pc-basic\packaging\windows\build\installer\out00-PYZ.pyz\pcbasic.statements", line 1979, in exec_input
      File "E:\pc-basic\packaging\windows\build\installer\out00-PYZ.pyz\pcbasic.devices", line 367, in read_var
      File "E:\pc-basic\packaging\windows\build\installer\out00-PYZ.pyz\pcbasic.devices", line 389, in _input_entry
      File "E:\pc-basic\packaging\windows\build\installer\out00-PYZ.pyz\pcbasic.devices", line 452, in read
      File "E:\pc-basic\packaging\windows\build\installer\out00-PYZ.pyz\pcbasic.ports", line 256, in read_raw
      File "E:\pc-basic\packaging\windows\build\installer\out00-PYZ.pyz\pcbasic.ports", line 231, in check_read
    TypeError: can't concat NoneType to bytearray
    

    Lines are long, each long line starts with " File "E" and wraps around.
    This CRASHES, by that I mean PCBASIC self terminates and returns to CMD.EXE
    which then also terminates.


    X.BAS

    21 OPEN "com1:" AS #1
    31 PRINT #1, "S"
    41 INPUT #1, PIN$
    51 PRINT ">";PIN$;"<"    :rem the carrots help me see if anything happens.
    61 INPUT #1, PINACK$
    71 PRINT ">";PINACK$;"<" :rem the carrots help me see if anything happens.
    81 CLOSE #1
    91 STOP
    

    XCMD.BAT

    CD C:\DOWNLOAD\PC-BASIC\
    PCBASIC.COM X.BAS --com1=PORT:COM20 --logfile=errors.txt --output=output.txt
    

    output.txt

    Device Timeout in 21 
    Okÿ
    system
    

    errors.txt

    (empty)
    

    21 OPEN "com1:9600" AS #1
    21 OPEN "com1:9600"AS #1
    21 OPEN "com1:9600"AS 1
    When I add 9600 the results are all the same as above.


    Note! CRASHES, by that I mean PCBASIC self terminates and returns to CMD.EXE
    which then also terminates. There output.txt is empty, presumably it hadn't written anything yet, and error.txt containd all those errors.

    You asked about CRASHING on the input ststement.
    I can't seem to remember how we got to where PCBASIC accepted the OPEN statement and went on to the INPUT statement wherein it crashed. In order to crash on the input statement it must have done the PRINT#1 statement. But I can't find the circumstances it happened. Sorry %^(

    Duane
    redrok@redrok.com

     
    • Rob Hagemans

      Rob Hagemans - 2015-12-18

      Hi Duane, that's excellent, thanks!

      The BASIC program and setup are clearly OK, the problem is a bug in PC-BASIC. With the errors.txt I now know where to look, so I should be able to fix that soon. I hope to have some time next week to put out a new release, after which you shouldn't have this problem anymore!

      The crash does in fact happen at the INPUT statement, so that mystery is also solved.

      So hang on for a few days and I hope to get back with good news.

      Thanks for your help,
      Rob

       
      • Anonymous

        Anonymous - 2016-01-16

        Hi Rob;
        Have you made any headway in making USB serial adapters work?
        Dusne
        redrok@redrok.com

         
        • Rob Hagemans

          Rob Hagemans - 2016-01-16

          Hi Duane, a fix for the issue above was included with release 15.08.3. If you still have issues in that version, could you let me know what is not working?

           
  • Anonymous

    Anonymous - 2015-12-18

    I appreciate that.
    If you need anymore tests just email me.
    Duane
    redrok@redrok.com

     

    Last edit: Anonymous 2015-12-19
  • Anonymous

    Anonymous - 2015-12-19

    Hi Rob;
    Since you are digging deep into the OPEN COM statement, I'm wondering if it would be possible to add an extra option.

    I'm proposing adding the option [,I] to the statement.

    [,I] inverts the serial bits on both the outgoing and incoming data streams. This is very useful when working with microprocessors which usually have the bit streams inverted. This is commonly called "TTL serial" as the physical voltage levels are similar to "TTL logic" and inverted.

    Often a transistor or logic gate is used to take the conventional RS-232 levels and convert them to the the low levels micros use and inverting them at the same time. Today we use USB RS-232 port devices. They usually output these inverted TTL levels.

    But sometimes, as in my current FE5680A project, I would like to un-invert the signals.

    Adding this option shouldn't affect the legacy users of basic as they never had this option.

    BTW, I can see it might be useful to separate the option for input and output.
    Possibly with [,IO] and [,II] options instead.

    Duane
    redrok@redrok.com

     
    • Rob Hagemans

      Rob Hagemans - 2015-12-19

      Hi Duane, thanks for the suggestion!

      At the moment I'm not considering extending the language - the aim of PC-BASIC is to be 100% compatible with GW-BASIC and its sister languages, and it is not there yet; furthermore, there are some persistent problems with the interface that need a lot of work to fix.

      Adding extra language features will just mean being able to spend less time on these goals as I would need to implement the feature and (worse) debug and test it. This is true even if the new feature doesn't break compatibility; but many extensions will break compatibility in subtle and hard to predict ways, simply because GW-BASIC is such a mess of a language.

      So for now, apologies on this one - but I do have good hopes to fix serial port access so that it works as it should.

      By the way, to invert the bits of byte I, why not simply use I = NOT(I) in BASIC?

      Cheers,
      Rob

       
  • Anonymous

    Anonymous - 2015-12-19

    That doesn't work as I = NOT(I) only inverts tha data. Bit stream inversion inverts everything including the start and stop bits. It is not a LOGICAL inversion. It is a hardware inversion.

     
  • Anonymous

    Anonymous - 2017-04-04

    Hello Rob,
    I too am having problems connecting a USB to RS232 device. Mine is a Tera Grand model, which appears to be installed correctly as COM1. It shows up in my device and printers as FT232R USB UART.

    I set com1=PORT:COM1 in the ini file, and am using the following PCBASIC code:
    30 open "com1:9600,N,8,1,RS,CS0,DS0,CD0" as #1

    When I run the code I get the following error:
    Device Unavailable in 30

    What am I missing?
    Thanks, for any assistance,
    Terry

     
    • Rob Hagemans

      Rob Hagemans - 2017-04-05

      Hi Terry, no idea, sorry. The INI option and the code look correct, but Device Unavailable suggests PC-BASIC can't find the port - can you access the port from Windows as COM1 ?

      Unfortunately there are many moving parts to serial communications and I'm not at all familiar with it, so I can only be of limited help.

      If you start PC-BASIC from the command prompt, you may be able to see logging messages which would help find out why the port is not found - happy to help make sense of them if you can get these messages.

      Thanks
      Rob

       
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.