Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lakeshore 218 Temperature Monitor
#11
By the way.... Since you have piqued my interest with this project idea, I've decided to take a gander at the MSDN for COM port communications. I'm working on a little something that you might end up being able to try in the next couple of days...

Code: (Select All)
Option Explicit
$NoPrefix
$Console:Only

Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000

Const OPEN_EXISTING = 3

Const CBR_110 = 110
Const CBR_300 = 300
Const CBR_600 = 600
Const CBR_1200 = 1200
Const CBR_2400 = 2400
Const CBR_4800 = 4800
Const CBR_9600 = 9600
Const CBR_14400 = 14400
Const CBR_19200 = 19200
Const CBR_38400 = 38400
Const CBR_57600 = 57600
Const CBR_115200 = 115200
Const CBR_128000 = 128000
Const CBR_256000 = 256000

Const EVENPARITY = 2
Const MARKPARITY = 3
Const NOPARITY = 0
Const ODDPARITY = 1
Const SPACEPARITY = 4

Const DTR_CONTROL_DISABLE = &H00
Const DTR_CONTROL_ENABLE = &H01
Const DTR_CONTROL_HANDSHAKE = &H02

Const RTS_CONTROL_DISABLE = &H00
Const RTS_CONTROL_ENABLE = &H01
Const RTS_CONTROL_HANDSHAKE = &H02
Const RTS_CONTROL_TOGGLE = &H03

Const ONESTOPBIT = 0
Const ONE5STOPBITS = 1
Const TWOSTOPBITS = 2

Type DCB
    As Unsigned Long DCBlength, BaudRate
    As Bit fBinary, fParity, fOutxCtsFlow, fOutxDsrFlow
    As _Bit * 2 fdtrControl
    As Bit fDsrSensitivity, fTXContinueOnXoff, fOutX, fInX, fErrorChar, fNull
    As _Bit * 2 fRtsControl
    As Bit fAbortOnError
    As _Bit * 17 fDummy2
    As Unsigned Integer wReserved, XonLim, XoffLim
    As Byte ByteSize, Parity, StopBits
    As Unsigned Byte XonChar, XoffChar, ErrorChar, EofChar, EvtChar
    As Unsigned Integer wReserved1
End Type

Declare CustomType Library
    Function CreateFile%& (ByVal lpFileName As Offset, Byval dwDesiredAccess As Unsigned Long, Byval dwShareMode As Unsigned Long, Byval lpSecurityAttributes As Offset, Byval dwCreationDisposition As Unsigned Long, Byval dwFlagsAndAttributes As Unsigned Long, Byval hTemplateFile As Offset)
    Function GetCommState& (ByVal hFile As Offset, Byval lpDCB As Offset)
    Function SetCommState& (ByVal hFile As Offset, Byval lpDCB As Offset)
End Declare

Dim As DCB dcb
Dim As Offset hCom
Dim As Long fSuccess
Dim As String pcCommPort: pcCommPort = "COM1" + Chr$(0)

hCom = CreateFile(Offset(pcCommPort), GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
If hCom = -1 Then End

fSuccess = GetCommState(hCom, Offset(dcb))
If fSuccess Then
    PrintCommState dcb

    dcb.BaudRate = CBR_9600
    dcb.ByteSize = 8
    dcb.Parity = NOPARITY
    dcb.StopBits = ONESTOPBIT

    fSuccess = SetCommState(hCom, Offset(dcb))
    If fSuccess Then
        fSuccess = GetCommState(hCom, Offset(dcb))
        If fSuccess Then
            PrintCommState dcb
            Print "Serial port "; pcCommPort; " successfully reconfigured"
        Else
            End
        End If
    Else
        End
    End If
Else
    End
End If

Sub PrintCommState (dcb As DCB)
    Print "BaudRate ="; dcb.BaudRate; ", ByteSize ="; dcb.ByteSize; ", Parity ="; dcb.Parity; ", StopBits ="; dcb.StopBits
End Sub


[Image: image.png]
Tread on those who tread on you

Reply


Messages In This Thread
Lakeshore 218 Temperature Monitor - by CJAlva - 09-15-2022, 03:46 PM
RE: Lakeshore 218 Temperature Monitor - by Pete - 09-15-2022, 04:46 PM
RE: Lakeshore 218 Temperature Monitor - by CJAlva - 09-15-2022, 05:55 PM
RE: Lakeshore 218 Temperature Monitor - by bplus - 09-15-2022, 05:43 PM
RE: Lakeshore 218 Temperature Monitor - by CJAlva - 09-15-2022, 06:32 PM
RE: Lakeshore 218 Temperature Monitor - by SpriggsySpriggs - 09-15-2022, 07:19 PM
RE: Lakeshore 218 Temperature Monitor - by Pete - 09-15-2022, 07:40 PM
RE: Lakeshore 218 Temperature Monitor - by Pete - 09-15-2022, 08:27 PM



Users browsing this thread: 1 Guest(s)