I need to control an instrument through the com port. If I first set the com port to 9600,N,8,1 with Hyperterminal Vertex's code from the code archives works with the instrument. The problem seems to be that code below (a boiled down version of Vertex's original) doesn't actually change the Com port settings. Any suggestions to fix or a alternative to change the com port settings from Blitzplus?
driverHandle = apiCreateFile("COM1", $80000000 Or $40000000 , 0, 0, 3, 0, 0)
If driverHandle = -1 Then Stop
apiSetupComm(driverHandle, 1024, 1024)
dcb = CreateBank(28)
PokeInt dcb, 00, 28 ; sizeof(DCB)
PokeInt dcb, 04, 9600 ; baud rate
;val = 1 ; ;Binary Mode (skip Eof check)
;val = val Or 2 ;Enable parity checking
;val = val Or 48 ; DTR Flow control on
;PokeByte dcb, 08, val
PokeByte dcb, 08, 0 ;no parity
PokeByte dcb, 09, 0 ;16 RTS_CONTROL=48
PokeByte dcb, 18, 8 ; number of bits/byte, 4-8
PokeByte dcb, 19, 0 ; 0-4=no, odd, even, mark, space
PokeByte dcb, 20, 1 ; 0,1,2 = 1, 1.5, 2
apiSetCommState(driverHandle, dcb)
apiSetCommMask(driverHandle, EV_TXEMPTY)
; Get the Comm state
For i=0 To 27
PokeByte dcb,i,0
Next
PokeInt dcb, 0, 28 ; sizeof(DCB)
;Get the Comm state
apiGetCommState(driverHandle,dcb)
mx$= "handle = "+driverhandle +Chr$(13)
mx$=mx$+ "Baudrate " +PeekInt(dcb,4) +Chr$(13)
mx$=mx$+ "Databits " +PeekByte(dcb,18) +Chr$(13)
mx$=mx$+ "Parity " +PeekByte(dcb,19) +Chr$(13)
mx$=mx$+ "Stopbits " +PeekByte(dcb,20) +Chr$(13)
Notify mx$
apiCloseHandle(driverHandle)
driverHandle = apiCreateFile("COM1", $80000000 Or $40000000 , 0, 0, 3, 0, 0)
If driverHandle = -1 Then Stop
apiSetupComm(driverHandle, 1024, 1024)
dcb = CreateBank(28)
PokeInt dcb, 00, 28 ; sizeof(DCB)
PokeInt dcb, 04, 9600 ; baud rate
;val = 1 ; ;Binary Mode (skip Eof check)
;val = val Or 2 ;Enable parity checking
;val = val Or 48 ; DTR Flow control on
;PokeByte dcb, 08, val
PokeByte dcb, 08, 0 ;no parity
PokeByte dcb, 09, 0 ;16 RTS_CONTROL=48
PokeByte dcb, 18, 8 ; number of bits/byte, 4-8
PokeByte dcb, 19, 0 ; 0-4=no, odd, even, mark, space
PokeByte dcb, 20, 1 ; 0,1,2 = 1, 1.5, 2
apiSetCommState(driverHandle, dcb)
apiSetCommMask(driverHandle, EV_TXEMPTY)
; Get the Comm state
For i=0 To 27
PokeByte dcb,i,0
Next
PokeInt dcb, 0, 28 ; sizeof(DCB)
;Get the Comm state
apiGetCommState(driverHandle,dcb)
mx$= "handle = "+driverhandle +Chr$(13)
mx$=mx$+ "Baudrate " +PeekInt(dcb,4) +Chr$(13)
mx$=mx$+ "Databits " +PeekByte(dcb,18) +Chr$(13)
mx$=mx$+ "Parity " +PeekByte(dcb,19) +Chr$(13)
mx$=mx$+ "Stopbits " +PeekByte(dcb,20) +Chr$(13)
Notify mx$
apiCloseHandle(driverHandle)