• Print

Author Topic: OPEN "COM..." works but needs testing to make it 100% compatible with QBASIC  (Read 7534 times)

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4664
  • QB Forever
    • Email
OPEN "COM..." works but needs testing to make it 100% compatible with QBASIC
« on: March 29, 2010, 03:57:30 AM »
I've just tested OPEN "COM... now that the GFS has been almost fully implemented and it works perfectly.

Using a program called "Virtual Serial Ports Emulator" I setup a virtual com port pair between com4 and com5. The program below outputs "HELLO".

Code: [Select]
OPEN "com4" FOR BINARY AS #1
OPEN "com5" FOR BINARY AS #2
a$ = "HELLO"
PUT #1, , a$
SLEEP 1
b$ = "     "
GET #2, , b$
PRINT b$

As for the other parameters after COM like:
Code: [Select]
OPEN "COM1:9600,N,8,1,BIN" ...If it isn't supported already I'll simply manually call the appropriate VisualC commands to setup the desired state.

Of course, as always, you'll have to wait for the next update to use this functionality. Don't bother trying the above program on the currently released version of QB64, it just prints "     ".

Expect the next version of QB64 to be released in one weeks time. 8)

PS. The internal GFS switchover required many changes and it is possible minor problems could have been introduced which will need to be ironed out.
« Last Edit: July 14, 2010, 11:46:12 PM by Galleon »
Something old... Something new... Something borrowed... Something blue...

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: OPEN "COM... works!
« Reply #1 on: March 29, 2010, 10:39:08 PM »
Simulated ports? Sounds interesting! I will be looking forward to the new improvements!

Ted
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Zom-B

  • Hero Member
  • *****
  • Posts: 545
Re: OPEN "COM... works!
« Reply #2 on: July 07, 2010, 09:21:46 AM »
I can't get the COM ports to work correctly.

I have a device (microcontroller) attached which continuously puts out data bytes with 9600,8,N,1 mode, and I want to receive the data in QB64. I attached the device at COM3 and Windows' HyperTerminal correctly receives my data.

This is what I tried:

Code: [Select]
OPEN "COM3:9600,N,8,1" FOR BINARY AS #1
'OPEN "COM3:9600,N,8,1" FOR RANDOM AS #1
'OPEN "COM3:9600,N,8,1" FOR INPUT AS #1
DO
  'INPUT #1, a: PRINT a '        "Path/File access error" (input)
  'INPUT #1, a$: PRINT LEN(a$) ' "Path/File access error" (input)
  'PRINT LEN(INPUT$(1, 1)); "." '"Input past end of file" (random)
  'GET 1, , a: PRINT a '         "Path/File access error" (binary)
  GET 1, , a$: PRINT LEN(a$) '   Only getting empty strings (binary)
LOOP

The first three modes in the loop give run-time errors, sometimes even after execution 1 or 2 times without error (though I can't verify the data from that small amount)

The last mode only puts out infinite '0' on the screen, indicating the strings are all empty. I verified this by replacing it with this:
Code: [Select]
GET 1, , a$: IF LEN(a$) > 0 THEN PRINT LEN(a$) '  Only getting empty strings and it puts out nothing at all.
« Last Edit: July 07, 2010, 12:36:42 PM by Zom-B »

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4664
  • QB Forever
    • Email
Re: OPEN "COM... works!
« Reply #3 on: July 07, 2010, 05:20:17 PM »
Hi Zom-B,

Thank you for the contributions you've made in the forum so far.

Now about OPEN COM...
It's only half implemented, but with a little help from you I could get it to work properly. Actual COM port operations are one of my weaker areas, but I have located enough relevant information to finish implementing the OPEN COM command for QB64. However, I require someone to help me test this though... interested?
Something old... Something new... Something borrowed... Something blue...

Omega

  • Sr. Member
  • ****
  • Posts: 377
    • Recall site..
    • Email
Re: OPEN "COM... works!
« Reply #4 on: July 07, 2010, 05:23:46 PM »
Hmmm.. thats what i would have done! ;)
Pretty cool dude.

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4664
  • QB Forever
    • Email
Re: OPEN "COM... works!
« Reply #5 on: July 07, 2010, 05:44:09 PM »
Try it like this...
Code: [Select]
a$ = " "
GET 1, , a$
PRINT a$
Something old... Something new... Something borrowed... Something blue...

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: OPEN "COM... works!
« Reply #6 on: July 07, 2010, 05:54:25 PM »
When using INPUT$ you cannot read an empty receive buffer. Use LOC(1) to check for data before reading it.

DO 'receive buffer read loop
IF LOC(1) THEN
reply$ = INPUT$(1, 1)   ' gets one byte at a time and reassemble string.
PRINT reply$;
END IF
LOOP UNTIL INKEY$ = CHR$(27)

Does LOC work yet?
« Last Edit: October 08, 2010, 03:26:11 AM by Clippy »
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Zom-B

  • Hero Member
  • *****
  • Posts: 545
Re: OPEN "COM... works!
« Reply #7 on: July 08, 2010, 05:21:32 AM »
Quote from: Galleon on July 07, 2010, 05:20:17 PM
Hi Zom-B,

Thank you for the contributions you've made in the forum so far.

Now about OPEN COM...
It's only half implemented, but with a little help from you I could get it to work properly. Actual COM port operations are one of my weaker areas, but I have located enough relevant information to finish implementing the OPEN COM command for QB64. However, I require someone to help me test this though... interested?

I'm interested.
I already went searching for clues in the libqbx source code but I can't find any behavior inside sub_open that differentiates file system names from COM names. sub_open delegates to gfs_open after preparing some things and that method just prepares a better filename in filenamez and uses that to CreateFile it.

Quote from: Clippy on July 07, 2010, 05:54:25 PM
When using INPUT$ you cannot read an empty receive buffer. Use LOC(1) to check for data before reading it.

DO 'receive buffer read loop
IF LOC(1) THEN PRINT LOC(1); ASC(INPUT$(1, 1))
LOOP UNTIL INKEY$ = CHR$(27)

Does LOC work yet?
Ok, tried that, and I get nothing, which means LOC(1) always stays 0. When i use RANDOM file mode however, i get loc(1)=1 and at INPUT$(1,1) i get "Input past end of file".

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: OPEN "COM... works!
« Reply #8 on: July 08, 2010, 11:43:13 AM »
I figured that it would probably not work. LOC has to be able to read the buffer and so does INPUT$. I think Galleon needs to work on this problem a bit.

Qbasic really was cool at doing that kinda stuff. I'm amazed that it lasted so long! You would think that the code would be outdated by now.
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Pete

  • Moderator
  • Hero Member
  • *****
  • Posts: 6240
  • Cuz I sez so varmint!
Re: OPEN "COM... works!
« Reply #9 on: July 08, 2010, 12:28:42 PM »

Sure, QB has its critics, but I've also am always amazed, especially for the time period it was created in, at just how much it can do. I guess that was the Hay Day of Micro$oft; compared to the stuff they make now, which I guess we'd called their Reprocessed Hay Days.

Pete  ;D
It's only rocket science; it's not Linux!

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: OPEN "COM... works!
« Reply #10 on: July 08, 2010, 01:02:55 PM »
Perhaps LOC is the problem if it is reading the buffer. Once the buffer is read, the data goes away too. So reading with INP would clear all data inside of it, which is what it is supposed to do. Bet you didn't think INP would affect anything but those FIFO buggers know their........... stuff?

Somehow QB did it which explains one of the difficulties of accessing port data.

LOC should be reading the Data Ready register at Base + 5. There is data in the buffer if bit 0 is on:

   dataready% = INP(base% + 5) AND 1

Where the base& value is the serial port's address. (it can be found in the Windows Components list)

The problem is that the ports are blocked by Windows NT. We gotta work on that!

Ted
« Last Edit: July 08, 2010, 01:10:39 PM by Clippy »
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4664
  • QB Forever
    • Email
Re: OPEN "COM... works!
« Reply #11 on: July 11, 2010, 01:02:06 AM »
*bump* ;)

PS. LOC isn't implemented at all. QB64 thinks it's an array in your example!
Something old... Something new... Something borrowed... Something blue...

Marky37_UK

  • Guest
Re: OPEN "COM... works!
« Reply #12 on: July 11, 2010, 02:21:31 AM »
Hi Galleon,
Looking forward to this, i will gladly test for you.

Mark

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4664
  • QB Forever
    • Email
Re: OPEN "COM... works!
« Reply #13 on: July 11, 2010, 03:52:14 AM »
Oh what's that... a ball?

It's in my court. 8)

I'll put together a prototype which should, in theory, set the correct baud, parity, etc and share it with 'you' and we'll take it from there.

I should reiterate that I should reiterate that QB64 should be QBASIC compatible and therefore our goal is not to create some new way of interpreting what effects GET/PUT/INPUT/OUTPUT should have upon an open COM but to make sure what did work shall work. Through, supporting the faster baud rates is still a must too. We'll I'm off to uniterate once and create what I first iterated.
Something old... Something new... Something borrowed... Something blue...

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4664
  • QB Forever
    • Email
Re: OPEN "COM... works!
« Reply #14 on: July 12, 2010, 06:47:27 AM »
I've made some good progress on implementing OPEN COM properly. The version of QB64 I'm working on now can correctly interpret and error check the syntax of the open com string and sets up a structure containing the relevant values and defaults as necessary. I've left the baud rate unrestricted so users can take advantage of faster connections.

Next, I'll be using a similar method as described in the link below to initialize the port with the given settings.
http://www.codeproject.com/KB/system/chaiyasit_t.aspx

And you thought I was just fixing critical errors in V0.9 eh?
Something old... Something new... Something borrowed... Something blue...

  • Print