Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lakeshore 218 Temperature Monitor
#1
Hey all!

I'm currently using a Lakeshore 218 Temperature monitor and was hoping to be able to grab readings using QBasic. Here's what I have so far:

CLS 'Clear screen
PRINT " SERIAL COMMUNICATION PROGRAM"
PRINT
TIMEOUT = 2000 'Read timeout (may need more)
BAUD$ = "9600"
TERM$ = CHR$(13) + CHR$(10) 'Terminators are <CR><LF>
OPEN "COM1:" + BAUD$ + ",O,7,1,RS" FOR RANDOM AS #1 LEN = 256
LOOP1: LINE INPUT "ENTER COMMAND (or EXIT):"; CMD$ 'Get command from keyboard
CMD$ = UCASE$(CMD$) 'Change input to upper case
IF CMD$ = "EXIT" THEN CLOSE #1: END 'Get out on Exit
CMD$ = CMD$ + TERM$
PRINT #1, CMD$; 'Send command to instrument
IF INSTR(CMD$, "?") <> 0 THEN 'Test for query
RS$ = "" 'If query, read response
N = 0 'Clr return string and count
WHILE (N < TIMEOUT) AND (INSTR(RS$, TERM$) = 0) 'Wait for response
IN$ = INPUT$(LOC(1), #1) 'Get one character at a time
IF IN$ = "" THEN N = N + 1 ELSE N = 0 'Add 1 to timeout if no chr
RS$ = RS$ + IN$ 'Add next chr to string
WEND 'Get chrs until terminators
IF RS$ <> "" THEN 'See if return string is empty
RS$ = MID$(RS$, 1, (INSTR(RS$, TERM$) - 1))'Strip off terminators
PRINT "RESPONSE:"; RS$ 'Print response to query
ELSE
PRINT "NO RESPONSE" 'No response to query
END IF
END IF 'Get next command
GOTO LOOP1

When I compile and run, I get an error calling out line 17 (IN$ = INPUT$(LOC(1), #1) 'Get one character at a time) and saying "Input past end of file". No clue how to mitigate this. Can anyone help out?


   
Reply
#2
I'm just taking a shot in the dark since I don't really know about communicating with devices in this way but is it possible that you need to send some sort of command to the device first before receiving any data from it?

EDIT: OOPS. I see that you are already doing that! DOH! Maybe you need to use PUT and GET rather than PRINT and INPUT. Also, before getting anything, check if LOF(1) > 0
Tread on those who tread on you

Reply
#3
We're going back to the days of Windows 98 when this code would work. Past that, Windows gummed up to ports to the point access was not possible without third party intervention such as porttalk: https://superuser.com/questions/1336100/...windows-10

Now that stated, I do not know if there were any QB64 additions that would solve this situation, as I also do not work with comm devices. I know a fellow who does, over at Pete's QBasic site (Not mine, that other Pete). He used to work a lot with comm ports and robotics. He mods the place now. So if you're really, really, really, really, really, really, really, really, really, really, really, really, really, desperate for a possible answer, if one doesn't appear in this thread, I'd say try there. Address your question to Clippy. Well, shower time.

Pete
Reply
#4
Do computers still have RS232 connectors? I've not seen one for a very long time.
I generally use a serial to USB converter (or more often I2C to USB).
These will pretend to be COM ports if you configure them in "control panel (windows)"  as such.
So you can do all the OPEN COM stuff and work at a blistering baud rate.
I've been using "future technologies" devices
https://ftdichip.com/
Reply
#5
Hi CJAlva,

Welcome to forum! Sorry I don't know com ports but have you checked Wiki?
https://qb64phoenix.com/qb64wiki/index.php/OPEN_COM

PS I saw Clippy's name from GotBasic.com link at Discord.  < Just saw discussion of Clippy in another board, not same guy?

Also I am not sure but Old Moses may have mentioned com ports when he was machining but maybe he was just that doing manually with QB64 calculations.
b = b + ...
Reply
#6
(09-15-2022, 05:39 PM)david_uwi Wrote: Do computers still have RS232 connectors? I've not seen one for a very long time.
I generally use a serial to USB converter (or more often I2C to USB).
These will pretend to be COM ports if you configure them in "control panel (windows)"  as such.
So you can do all the OPEN COM stuff and work at a blistering baud rate.
I've been using "future technologies" devices
https://ftdichip.com/

Neither had I, until I started this job. It's remarkably outdated stuff for the organization, but I you shouldn't waste (reasonably) good tech  hahahaha

I'm doing the same. It runs RS232 null out of the reader and I convert it to usb at the lab pc. Baud for the reader, interestingly, can be set to 300/1200/9600
Reply
#7
Have you verified that the USB com port is registering as COM 1 in device manager?
Tread on those who tread on you

Reply
#8
I find your code a bit difficult to read (please use more subs/functions) Smile

QB64 has some unreliable behaviour with serial, but some (proven) serial functions I wrote and use are here:
Code: (Select All)
Errhandler: ' ser.open% (ser$)
errorNum = Err: Resume Next

Function ser.open% (ser$)
  On Error GoTo Errhandler
  Open ser$ + ",N,8,1,BIN,CS0,DS0,RB8192" For Random As #88
  If errorNum = 0 Then serBytes$ = ser.read$
  On Error GoTo 0
  ser.open% = errorNum
End Function

Function ser.close$ ()
  ser.close$ = ser.read$
  Close #88
End Function

Sub ser.send (bytes$)
  Dim b As String * 1
  For i% = 1 To Len(bytes$)
    b = Mid$(bytes$, i%, 1)
    Put #88, , b
  Next i%
End Sub

Function ser.read$ ()
  Dim b As String * 1: resp$ = ""
  Do While Loc(88)
    Get #88, , b: resp$ = resp$ + b
  Loop
  ser.read$ = resp$
End Function
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply
#9
(09-15-2022, 05:57 PM)Spriggsy Wrote: Have you verified that the USB com port is registering as COM 1 in device manager?

It defaults as COM3. The copy/paste calls COM1, but I changed it in QB to call COM3. Sorry there
Reply
#10
(09-15-2022, 06:32 PM)CJAlva Wrote:
(09-15-2022, 05:57 PM)Spriggsy Wrote: Have you verified that the USB com port is registering as COM 1 in device manager?

It defaults as COM3. The copy/paste calls COM1, but I changed it in QB to call COM3. Sorry there

Ah, I see. No worries. I hope you can get it to work. It sounds like a fun project. Here is the product manual for this device. It has a sample VB program on page 77.
218_v2.0.doc (lakeshore.com)

EDIT: LOL! I just realized that the QB example is the one you pasted in the original post.
Tread on those who tread on you

Reply




Users browsing this thread: 4 Guest(s)