Hi all
This is part of a power basic TAM project.
Recording audio via microphone and soundcard into a wave file works great.
Making phone calls with my voice modem and headset (connected to soundcard) works either.
But i´m not able to record incoming audio from my modem.
i use a Motorola SM56 Speakerphone (PCI). Control panel tells me, there is a
wave driver installed for this modem. audio transfer between modem and soundcard
works (otherwise my headset couldn´t work). The modem manual states DirectX
version 6 must be installed for audio transfer to work. On the other hand
WaveInGetNumDevs() returns "2" (default audio input device = soundcard [deviceid=0],
second input device = "modem nr. 0" [deviceid=1]), meaning this modem is a
wave input device.
If i query the modem device, i get dwformats=0 [wave_invalidformat] and
wchannels=1 in waveincaps structure in return, meaning it doesn´t support
wave format (?) but it offers input for one channel. (???)
So what, if it is listed as a wave input device, why doesn´t it support
wave format? .
How does DirectX audio capture work ? maybe this could be a way to do it.
Any ideas about this, i´m stuck with it since several days ...
Thanks in advance,
Guenther
below some testing code i use (put together from code sample i found):
#COMPILE EXE
#DIM ALL
%USEMACROS = 1
#INCLUDE "Win32API.inc"
$ComPort = "COM3"
$AppTitle = "PB/Win Comm Example"
%IDD_MAIN = 100
%IDC_LISTBOX1 = 101
%IDC_EDIT1 = 102
%IDC_SEND = 103
%IDC_SENDFILE = 104
%IDC_RECEIVEFILE = 105
%IDC_QUIT = 106
%IDC_ECHO = 107
GLOBAL nComm AS LONG ' file number of comm device
GLOBAL nWriteFile AS LONG ' file number of output file
GLOBAL fUpdating AS LONG ' flag to avoid conflicts when updating
GLOBAL fCloseThread AS LONG ' flag to tell thread to shut down
GLOBAL hwi AS LONG
'***********************************************************************************************
CALLBACK FUNCTION check_callback
'***********************************************************************************************
'
'***********************************************************************************************
'FUNCTION OpenWaveIn(BYVAL hWnd AS LONG) AS LONG
LOCAL rc AS LONG
LOCAL NumDevs AS DWORD
LOCAL i AS LONG
LOCAL ErrStr AS ASCIIZ*512
LOCAL wfx AS WAVEFORMATEX
LOCAL wic AS WAVEINCAPS
rc = WaveInGetNumDevs()
FOR i = 0 TO rc -1
' FOR i = 1 TO rc -1
rc = WaveInGetDevCaps(i, wic, LEN(WAVEINCAPS))
IF (rc = %MMSYSERR_NOERROR) THEN
MSGBOX wic.szpname+" --- "+HEX$(wic.dwformats)+" --- "+STR$(wic.wchannels)
' IF wic.dwFormats AND %WAVE_FORMAT_1M16 THEN
wfx.nChannels = 1
wfx.nSamplesPerSec = 11025
wfx.wFormatTag = %WAVE_FORMAT_PCM
wfx.wBitsPerSample = 16
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample \ 8
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign
wfx.cbSize = 0
' rc = waveinOpen(hwi, i, wfx, hWnd, hWnd, %CALLBACK_WINDOW)
IF (rc = %MMSYSERR_NOERROR) THEN
FUNCTION = %True
' EXIT FUNCTION
ELSE
WaveInGetErrorText rc, ErrStr, 511
MSGBOX ErrStr
END IF
' ELSE
MSGBOX "Device " & wic.szpName & " - WAVE_FORMAT_1M16 Not Supported"
' END IF
ELSE
WaveInGetErrorText rc, ErrStr, 127
MSGBOX ErrStr
END IF
NEXT i
MSGBOX "No suitable device found"
FUNCTION = %False
END FUNCTION
'***********************************************************************************************
SUB AddLine (BYVAL hWnd AS DWORD, BYVAL nID AS LONG, SendText AS ASCIIZ)
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL ListCount AS LONG
' find the current listbox count
CONTROL SEND hWnd, nID, %LB_GETCOUNT, 0, 0 TO ListCount
' update the listbox
CONTROL SEND hWnd, nID, %LB_ADDSTRING, 0, VARPTR(SendText)
' scroll the new item into view
CONTROL SEND hWnd, nID, %LB_SETCURSEL, ListCount, 0
END SUB
'***********************************************************************************************
FUNCTION StartComms () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL dummy AS STRING
COMM OPEN $COMPORT AS #nComm
IF ERRCLEAR THEN EXIT FUNCTION ' Exit if port cannot be opened
COMM SET #nComm, BAUD = 9600 ' 9600 baud
COMM SET #nComm, BYTE = 8 ' 8 bits
COMM SET #nComm, PARITY = %False ' No parity
COMM SET #nComm, STOP = 0 ' 1 stop bit
COMM SET #nComm, TXBUFFER = 4096 ' 4k transmit buffer
COMM SET #nComm, RXBUFFER = 4096 ' 4k receive buffer
' Issue a CR/LF and flush the receive buffer
COMM PRINT #nComm, $NUL
SLEEP 2000
IF COMM(#nComm, RXQUE) THEN COMM RECV #nComm, COMM(#nComm, RXQUE), dummy
FUNCTION = %TRUE
END FUNCTION
'***********************************************************************************************
SUB EndComms ()
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL dummy AS STRING
' Flush the RX buffer & close the port
SLEEP 1000
IF COMM(#nComm, RXQUE) THEN
COMM RECV #nComm, COMM(#nComm, RXQUE), dummy
END IF
COMM CLOSE #nComm
END SUB
'***********************************************************************************************
FUNCTION ReceiveData (BYVAL hWnd AS LONG) AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL sBigBuffer AS STRING
LOCAL sBuffer AS STRING
LOCAL ncBytesInBuffer AS LONG
WHILE ISFALSE fCloseThread
' Test the RX buffer
ncBytesInBuffer = COMM(#nComm, RXQUE)
' Abort this iteration if sending
IF ISFALSE ncBytesInBuffer OR fUpdating THEN
SLEEP 100
ITERATE LOOP
END IF
' Read incoming characters.
COMM RECV #nComm, ncBytesInBuffer, sBuffer
sBigBuffer = sBigBuffer & sBuffer
' If Receive mode is on, write raw data to the file
IF nWriteFile THEN PRINT #nWriteFile, sBuffer;
' Strip out LF characters
REPLACE $LF WITH "" IN sBigBuffer
' Process only complete lines of text terminated by carriage returns
WHILE INSTR(sBigBuffer, $CR)
' Display the data
AddLine hWnd, %IDC_LISTBOX1, "==> " + EXTRACT$(sBigBuffer, $CR)
' Remove the "displayed" line from the buffer
sBigBuffer = STRDELETE$(sBigBuffer, 1, LEN(EXTRACT$(sBigBuffer, $CR)) + 1)
WEND
WEND
FUNCTION = %TRUE
END FUNCTION
'***********************************************************************************************
CALLBACK FUNCTION Dialog_Callback () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
IF CBMSG = %WM_INITDIALOG THEN
' Set focus to the edit control
CONTROL SET FOCUS CBHNDL, %IDC_EDIT1
' Set the SELECTION range to highlight the initial entry
CONTROL SEND CBHNDL, %IDC_EDIT1, %EM_SETSEL, 0, -1
' Return 0 to stop the dialog box engine setting focus
FUNCTION = %FALSE
END IF
END FUNCTION
'***********************************************************************************************
CALLBACK FUNCTION Send_Callback () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL SendText AS ASCIIZ * 1024
LOCAL Result AS LONG
LOCAL hListBox AS DWORD
' Obtain the text to send from the edit control
CONTROL GET TEXT CBHNDL, %IDC_EDIT1 TO SendText
' Set the update flag
fUpdating = %TRUE
' Send the line to the comm port
COMM PRINT #nComm, SendText
' Check the Echo mode state
CONTROL SEND CBHNDL, %IDC_ECHO, %BM_GETCHECK, 0, 0 TO Result
IF Result <> %BST_CHECKED THEN
' Add the echo to the listbox
AddLine CBHNDL, %IDC_LISTBOX1, "<== " + SendText
END IF
' Set the SELECTION range for the edit control so the next keypress "clears" the control
CONTROL SEND CBHNDL, %IDC_EDIT1, %EM_SETSEL, 0, -1
' Restore the keyboard focus to the edit control
CONTROL SET FOCUS CBHNDL, %IDC_EDIT1
' Release the update flag
fUpdating = %FALSE
FUNCTION = %TRUE
END FUNCTION
'***********************************************************************************************
CALLBACK FUNCTION SendFile_Callback() AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL SendFileName AS STRING
LOCAL nReadFile AS LONG
LOCAL FileLen AS LONG
LOCAL Chunk AS LONG
LOCAL i AS LONG
LOCAL sBuffer AS STRING
SendFileName = INPUTBOX$("Name of disk file to transmit? ", $AppTitle, "")
IF ISFALSE LEN(SendFileName) OR ISFALSE LEN(DIR$(SendFileName)) THEN
EXIT FUNCTION
END IF
AddLine CBHNDL, %IDC_LISTBOX1, "Wait... Sending " & SendFileName
DIALOG DOEVENTS
' send the file
nReadFile = FREEFILE
OPEN SendFileName FOR BINARY AS #nReadFile ' Open as binary
FileLen = LOF(nReadFile) ' File length
Chunk = COMM(#nComm, TXBUFFER) \ 2 ' 1/2 * TXBUFFER
FOR i = 1 TO FileLen \ Chunk
GET$ #nReadFile, Chunk, sBuffer ' Read a chunk
COMM SEND #nComm, sBuffer ' and send it
SLEEP 0
NEXT i
IF FileLen MOD Chunk <> 0 THEN ' More to send?
GET$ #nReadFile, FileLen MOD Chunk, sBuffer
COMM SEND #nComm, sBuffer
END IF
CLOSE #nReadFile
AddLine CBHNDL, %IDC_LISTBOX1, "Transmission complete!"
END FUNCTION
'***********************************************************************************************
CALLBACK FUNCTION ReceiveFile_Callback () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL sReceiveFileName AS STRING
LOCAL sBuffer AS STRING
' First check if file is already open
IF nWriteFile THEN
CLOSE #nWriteFile 'close the file
AddLine CBHNDL, %IDC_LISTBOX1, "Finished writing file!"
' Update the button label
sBuffer = "&Receive File"
CONTROL SEND CBHNDL, %IDC_RECEIVEFILE, %WM_SETTEXT, 0, STRPTR(sBuffer)
nWriteFile = 0
EXIT FUNCTION
END IF
' Create a new file
sReceiveFileName = INPUTBOX$("Output file name?", $AppTitle, "")
IF ISFALSE LEN(sReceiveFileName) THEN EXIT FUNCTION
nWriteFile = FREEFILE
OPEN sReceiveFileName FOR APPEND AS #nWriteFile
IF ERRCLEAR THEN
' Error opening the file
nWriteFile = 0
ELSE
' Update the dialog
AddLine CBHNDL, %IDC_LISTBOX1, "Receiving data stream to " & sReceiveFileName
sBuffer = "Stop &Receive"
CONTROL SEND CBHNDL, %IDC_RECEIVEFILE, %WM_SETTEXT, 0, STRPTR(sBuffer)
END IF
END FUNCTION
'***********************************************************************************************
CALLBACK FUNCTION Quit_Callback () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
' Kill the dialog and let PBMAIN() continue
DIALOG END CBHNDL, 0
END FUNCTION
'***********************************************************************************************
FUNCTION PBMAIN () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
#REGISTER NONE
LOCAL hDlg AS DWORD
LOCAL Result AS LONG
LOCAL hThread AS LONG
DIM Txt(1 TO 1) AS STRING
' Initialize the port ready for the session
IF ISFALSE StartComms THEN
MSGBOX "Failed to start communications!",, $AppTitle
EXIT FUNCTION
END IF
Txt(1) = "This listbox shows the transmission I/O stream..."
' Create a modal dialog box
DIALOG NEW 0, $AppTitle,,, 330, 203, %WS_POPUP OR %WS_VISIBLE OR %WS_CLIPCHILDREN OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX, 0 TO hDlg
' Add our application controls
CONTROL ADD LABEL, hDlg, -1, "Transmission &log for " & $ComPort, _
9, 5, 100, 10, 0
CONTROL ADD LISTBOX, hDlg, %IDC_LISTBOX1, Txt(), 9, 15, 313, 133, _
%WS_BORDER OR %LBS_WANTKEYBOARDINPUT _
OR %LBS_DISABLENOSCROLL OR %WS_VSCROLL OR %WS_GROUP _
OR %WS_TABSTOP OR %LBS_NOINTEGRALHEIGHT
CONTROL ADD LABEL, hDlg, -1, "Te&xt to send", 9, 151, 100, 10, 0
CONTROL ADD TEXTBOX, hDlg, %IDC_EDIT1, "ATZ", 9, 161, 257, 12, _
%ES_AUTOHSCROLL OR %ES_NOHIDESEL OR %WS_BORDER _
OR %WS_GROUP OR %WS_TABSTOP
CONTROL ADD BUTTON, hDlg, %IDC_SEND, "Send &Text", 273, 160, 50, 14, _
%WS_GROUP OR %WS_TABSTOP OR %BS_DEFPUSHBUTTON _
CALL Send_Callback
CONTROL ADD BUTTON, hDlg, %IDC_SENDFILE, "&Send File", 9, 182, 50, 14, _
%WS_GROUP OR %WS_TABSTOP CALL SendFile_Callback
CONTROL ADD BUTTON, hDlg, %IDC_RECEIVEFILE, "&Receive File", _
62, 182, 50, 14, %WS_GROUP OR %WS_TABSTOP _
CALL ReceiveFile_Callback
CONTROL ADD BUTTON, hDlg, %IDC_QUIT, "&Quit", 273, 182, 50, 14, _
%WS_GROUP OR %WS_TABSTOP CALL Quit_Callback
CONTROL ADD BUTTON, hDlg, 500, "check", 150, 182, 50, 14, _
%WS_GROUP OR %WS_TABSTOP CALL check_Callback
CONTROL ADD CHECKBOX, hDlg, %IDC_ECHO, "Disable Local &Echo", _
241, 5, 80, 10, _
%WS_GROUP OR %WS_TABSTOP OR %BS_AUTOCHECKBOX _
OR %BS_LEFTTEXT OR %BS_RIGHT
' Erase our array to free memory no longer required
REDIM Txt()
' Create a "listen" thread to monitor input from the modem
THREAD CREATE ReceiveData(hDlg) TO hThread
' Start the dialog box & run until DIALOG END executed.
DIALOG SHOW MODAL hDlg, CALL Dialog_Callback TO Result
' close down our "listen" thread
fCloseThread = %TRUE
DO
THREAD CLOSE hThread TO Result
SLEEP 0
LOOP UNTIL ISTRUE Result
' Flush & close the comm port and close the Receive file if open
EndComms
IF nWriteFile THEN CLOSE #nWriteFile
END FUNCTION
'***********************************************************************************************
'***********************************************************************************************
This is part of a power basic TAM project.
Recording audio via microphone and soundcard into a wave file works great.
Making phone calls with my voice modem and headset (connected to soundcard) works either.
But i´m not able to record incoming audio from my modem.
i use a Motorola SM56 Speakerphone (PCI). Control panel tells me, there is a
wave driver installed for this modem. audio transfer between modem and soundcard
works (otherwise my headset couldn´t work). The modem manual states DirectX
version 6 must be installed for audio transfer to work. On the other hand
WaveInGetNumDevs() returns "2" (default audio input device = soundcard [deviceid=0],
second input device = "modem nr. 0" [deviceid=1]), meaning this modem is a
wave input device.
If i query the modem device, i get dwformats=0 [wave_invalidformat] and
wchannels=1 in waveincaps structure in return, meaning it doesn´t support
wave format (?) but it offers input for one channel. (???)
So what, if it is listed as a wave input device, why doesn´t it support
wave format? .
How does DirectX audio capture work ? maybe this could be a way to do it.
Any ideas about this, i´m stuck with it since several days ...
Thanks in advance,
Guenther
below some testing code i use (put together from code sample i found):
#COMPILE EXE
#DIM ALL
%USEMACROS = 1
#INCLUDE "Win32API.inc"
$ComPort = "COM3"
$AppTitle = "PB/Win Comm Example"
%IDD_MAIN = 100
%IDC_LISTBOX1 = 101
%IDC_EDIT1 = 102
%IDC_SEND = 103
%IDC_SENDFILE = 104
%IDC_RECEIVEFILE = 105
%IDC_QUIT = 106
%IDC_ECHO = 107
GLOBAL nComm AS LONG ' file number of comm device
GLOBAL nWriteFile AS LONG ' file number of output file
GLOBAL fUpdating AS LONG ' flag to avoid conflicts when updating
GLOBAL fCloseThread AS LONG ' flag to tell thread to shut down
GLOBAL hwi AS LONG
'***********************************************************************************************
CALLBACK FUNCTION check_callback
'***********************************************************************************************
'
'***********************************************************************************************
'FUNCTION OpenWaveIn(BYVAL hWnd AS LONG) AS LONG
LOCAL rc AS LONG
LOCAL NumDevs AS DWORD
LOCAL i AS LONG
LOCAL ErrStr AS ASCIIZ*512
LOCAL wfx AS WAVEFORMATEX
LOCAL wic AS WAVEINCAPS
rc = WaveInGetNumDevs()
FOR i = 0 TO rc -1
' FOR i = 1 TO rc -1
rc = WaveInGetDevCaps(i, wic, LEN(WAVEINCAPS))
IF (rc = %MMSYSERR_NOERROR) THEN
MSGBOX wic.szpname+" --- "+HEX$(wic.dwformats)+" --- "+STR$(wic.wchannels)
' IF wic.dwFormats AND %WAVE_FORMAT_1M16 THEN
wfx.nChannels = 1
wfx.nSamplesPerSec = 11025
wfx.wFormatTag = %WAVE_FORMAT_PCM
wfx.wBitsPerSample = 16
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample \ 8
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign
wfx.cbSize = 0
' rc = waveinOpen(hwi, i, wfx, hWnd, hWnd, %CALLBACK_WINDOW)
IF (rc = %MMSYSERR_NOERROR) THEN
FUNCTION = %True
' EXIT FUNCTION
ELSE
WaveInGetErrorText rc, ErrStr, 511
MSGBOX ErrStr
END IF
' ELSE
MSGBOX "Device " & wic.szpName & " - WAVE_FORMAT_1M16 Not Supported"
' END IF
ELSE
WaveInGetErrorText rc, ErrStr, 127
MSGBOX ErrStr
END IF
NEXT i
MSGBOX "No suitable device found"
FUNCTION = %False
END FUNCTION
'***********************************************************************************************
SUB AddLine (BYVAL hWnd AS DWORD, BYVAL nID AS LONG, SendText AS ASCIIZ)
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL ListCount AS LONG
' find the current listbox count
CONTROL SEND hWnd, nID, %LB_GETCOUNT, 0, 0 TO ListCount
' update the listbox
CONTROL SEND hWnd, nID, %LB_ADDSTRING, 0, VARPTR(SendText)
' scroll the new item into view
CONTROL SEND hWnd, nID, %LB_SETCURSEL, ListCount, 0
END SUB
'***********************************************************************************************
FUNCTION StartComms () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL dummy AS STRING
COMM OPEN $COMPORT AS #nComm
IF ERRCLEAR THEN EXIT FUNCTION ' Exit if port cannot be opened
COMM SET #nComm, BAUD = 9600 ' 9600 baud
COMM SET #nComm, BYTE = 8 ' 8 bits
COMM SET #nComm, PARITY = %False ' No parity
COMM SET #nComm, STOP = 0 ' 1 stop bit
COMM SET #nComm, TXBUFFER = 4096 ' 4k transmit buffer
COMM SET #nComm, RXBUFFER = 4096 ' 4k receive buffer
' Issue a CR/LF and flush the receive buffer
COMM PRINT #nComm, $NUL
SLEEP 2000
IF COMM(#nComm, RXQUE) THEN COMM RECV #nComm, COMM(#nComm, RXQUE), dummy
FUNCTION = %TRUE
END FUNCTION
'***********************************************************************************************
SUB EndComms ()
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL dummy AS STRING
' Flush the RX buffer & close the port
SLEEP 1000
IF COMM(#nComm, RXQUE) THEN
COMM RECV #nComm, COMM(#nComm, RXQUE), dummy
END IF
COMM CLOSE #nComm
END SUB
'***********************************************************************************************
FUNCTION ReceiveData (BYVAL hWnd AS LONG) AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL sBigBuffer AS STRING
LOCAL sBuffer AS STRING
LOCAL ncBytesInBuffer AS LONG
WHILE ISFALSE fCloseThread
' Test the RX buffer
ncBytesInBuffer = COMM(#nComm, RXQUE)
' Abort this iteration if sending
IF ISFALSE ncBytesInBuffer OR fUpdating THEN
SLEEP 100
ITERATE LOOP
END IF
' Read incoming characters.
COMM RECV #nComm, ncBytesInBuffer, sBuffer
sBigBuffer = sBigBuffer & sBuffer
' If Receive mode is on, write raw data to the file
IF nWriteFile THEN PRINT #nWriteFile, sBuffer;
' Strip out LF characters
REPLACE $LF WITH "" IN sBigBuffer
' Process only complete lines of text terminated by carriage returns
WHILE INSTR(sBigBuffer, $CR)
' Display the data
AddLine hWnd, %IDC_LISTBOX1, "==> " + EXTRACT$(sBigBuffer, $CR)
' Remove the "displayed" line from the buffer
sBigBuffer = STRDELETE$(sBigBuffer, 1, LEN(EXTRACT$(sBigBuffer, $CR)) + 1)
WEND
WEND
FUNCTION = %TRUE
END FUNCTION
'***********************************************************************************************
CALLBACK FUNCTION Dialog_Callback () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
IF CBMSG = %WM_INITDIALOG THEN
' Set focus to the edit control
CONTROL SET FOCUS CBHNDL, %IDC_EDIT1
' Set the SELECTION range to highlight the initial entry
CONTROL SEND CBHNDL, %IDC_EDIT1, %EM_SETSEL, 0, -1
' Return 0 to stop the dialog box engine setting focus
FUNCTION = %FALSE
END IF
END FUNCTION
'***********************************************************************************************
CALLBACK FUNCTION Send_Callback () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL SendText AS ASCIIZ * 1024
LOCAL Result AS LONG
LOCAL hListBox AS DWORD
' Obtain the text to send from the edit control
CONTROL GET TEXT CBHNDL, %IDC_EDIT1 TO SendText
' Set the update flag
fUpdating = %TRUE
' Send the line to the comm port
COMM PRINT #nComm, SendText
' Check the Echo mode state
CONTROL SEND CBHNDL, %IDC_ECHO, %BM_GETCHECK, 0, 0 TO Result
IF Result <> %BST_CHECKED THEN
' Add the echo to the listbox
AddLine CBHNDL, %IDC_LISTBOX1, "<== " + SendText
END IF
' Set the SELECTION range for the edit control so the next keypress "clears" the control
CONTROL SEND CBHNDL, %IDC_EDIT1, %EM_SETSEL, 0, -1
' Restore the keyboard focus to the edit control
CONTROL SET FOCUS CBHNDL, %IDC_EDIT1
' Release the update flag
fUpdating = %FALSE
FUNCTION = %TRUE
END FUNCTION
'***********************************************************************************************
CALLBACK FUNCTION SendFile_Callback() AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL SendFileName AS STRING
LOCAL nReadFile AS LONG
LOCAL FileLen AS LONG
LOCAL Chunk AS LONG
LOCAL i AS LONG
LOCAL sBuffer AS STRING
SendFileName = INPUTBOX$("Name of disk file to transmit? ", $AppTitle, "")
IF ISFALSE LEN(SendFileName) OR ISFALSE LEN(DIR$(SendFileName)) THEN
EXIT FUNCTION
END IF
AddLine CBHNDL, %IDC_LISTBOX1, "Wait... Sending " & SendFileName
DIALOG DOEVENTS
' send the file
nReadFile = FREEFILE
OPEN SendFileName FOR BINARY AS #nReadFile ' Open as binary
FileLen = LOF(nReadFile) ' File length
Chunk = COMM(#nComm, TXBUFFER) \ 2 ' 1/2 * TXBUFFER
FOR i = 1 TO FileLen \ Chunk
GET$ #nReadFile, Chunk, sBuffer ' Read a chunk
COMM SEND #nComm, sBuffer ' and send it
SLEEP 0
NEXT i
IF FileLen MOD Chunk <> 0 THEN ' More to send?
GET$ #nReadFile, FileLen MOD Chunk, sBuffer
COMM SEND #nComm, sBuffer
END IF
CLOSE #nReadFile
AddLine CBHNDL, %IDC_LISTBOX1, "Transmission complete!"
END FUNCTION
'***********************************************************************************************
CALLBACK FUNCTION ReceiveFile_Callback () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
LOCAL sReceiveFileName AS STRING
LOCAL sBuffer AS STRING
' First check if file is already open
IF nWriteFile THEN
CLOSE #nWriteFile 'close the file
AddLine CBHNDL, %IDC_LISTBOX1, "Finished writing file!"
' Update the button label
sBuffer = "&Receive File"
CONTROL SEND CBHNDL, %IDC_RECEIVEFILE, %WM_SETTEXT, 0, STRPTR(sBuffer)
nWriteFile = 0
EXIT FUNCTION
END IF
' Create a new file
sReceiveFileName = INPUTBOX$("Output file name?", $AppTitle, "")
IF ISFALSE LEN(sReceiveFileName) THEN EXIT FUNCTION
nWriteFile = FREEFILE
OPEN sReceiveFileName FOR APPEND AS #nWriteFile
IF ERRCLEAR THEN
' Error opening the file
nWriteFile = 0
ELSE
' Update the dialog
AddLine CBHNDL, %IDC_LISTBOX1, "Receiving data stream to " & sReceiveFileName
sBuffer = "Stop &Receive"
CONTROL SEND CBHNDL, %IDC_RECEIVEFILE, %WM_SETTEXT, 0, STRPTR(sBuffer)
END IF
END FUNCTION
'***********************************************************************************************
CALLBACK FUNCTION Quit_Callback () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
' Kill the dialog and let PBMAIN() continue
DIALOG END CBHNDL, 0
END FUNCTION
'***********************************************************************************************
FUNCTION PBMAIN () AS LONG
'***********************************************************************************************
'
'***********************************************************************************************
#REGISTER NONE
LOCAL hDlg AS DWORD
LOCAL Result AS LONG
LOCAL hThread AS LONG
DIM Txt(1 TO 1) AS STRING
' Initialize the port ready for the session
IF ISFALSE StartComms THEN
MSGBOX "Failed to start communications!",, $AppTitle
EXIT FUNCTION
END IF
Txt(1) = "This listbox shows the transmission I/O stream..."
' Create a modal dialog box
DIALOG NEW 0, $AppTitle,,, 330, 203, %WS_POPUP OR %WS_VISIBLE OR %WS_CLIPCHILDREN OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX, 0 TO hDlg
' Add our application controls
CONTROL ADD LABEL, hDlg, -1, "Transmission &log for " & $ComPort, _
9, 5, 100, 10, 0
CONTROL ADD LISTBOX, hDlg, %IDC_LISTBOX1, Txt(), 9, 15, 313, 133, _
%WS_BORDER OR %LBS_WANTKEYBOARDINPUT _
OR %LBS_DISABLENOSCROLL OR %WS_VSCROLL OR %WS_GROUP _
OR %WS_TABSTOP OR %LBS_NOINTEGRALHEIGHT
CONTROL ADD LABEL, hDlg, -1, "Te&xt to send", 9, 151, 100, 10, 0
CONTROL ADD TEXTBOX, hDlg, %IDC_EDIT1, "ATZ", 9, 161, 257, 12, _
%ES_AUTOHSCROLL OR %ES_NOHIDESEL OR %WS_BORDER _
OR %WS_GROUP OR %WS_TABSTOP
CONTROL ADD BUTTON, hDlg, %IDC_SEND, "Send &Text", 273, 160, 50, 14, _
%WS_GROUP OR %WS_TABSTOP OR %BS_DEFPUSHBUTTON _
CALL Send_Callback
CONTROL ADD BUTTON, hDlg, %IDC_SENDFILE, "&Send File", 9, 182, 50, 14, _
%WS_GROUP OR %WS_TABSTOP CALL SendFile_Callback
CONTROL ADD BUTTON, hDlg, %IDC_RECEIVEFILE, "&Receive File", _
62, 182, 50, 14, %WS_GROUP OR %WS_TABSTOP _
CALL ReceiveFile_Callback
CONTROL ADD BUTTON, hDlg, %IDC_QUIT, "&Quit", 273, 182, 50, 14, _
%WS_GROUP OR %WS_TABSTOP CALL Quit_Callback
CONTROL ADD BUTTON, hDlg, 500, "check", 150, 182, 50, 14, _
%WS_GROUP OR %WS_TABSTOP CALL check_Callback
CONTROL ADD CHECKBOX, hDlg, %IDC_ECHO, "Disable Local &Echo", _
241, 5, 80, 10, _
%WS_GROUP OR %WS_TABSTOP OR %BS_AUTOCHECKBOX _
OR %BS_LEFTTEXT OR %BS_RIGHT
' Erase our array to free memory no longer required
REDIM Txt()
' Create a "listen" thread to monitor input from the modem
THREAD CREATE ReceiveData(hDlg) TO hThread
' Start the dialog box & run until DIALOG END executed.
DIALOG SHOW MODAL hDlg, CALL Dialog_Callback TO Result
' close down our "listen" thread
fCloseThread = %TRUE
DO
THREAD CLOSE hThread TO Result
SLEEP 0
LOOP UNTIL ISTRUE Result
' Flush & close the comm port and close the Receive file if open
EndComms
IF nWriteFile THEN CLOSE #nWriteFile
END FUNCTION
'***********************************************************************************************
'***********************************************************************************************
Comment