Hallöchen.
@NicTheQuick: Den Vorwurf des "Buchstaben an den Kopf geworfen" weise ich von mir. Im ersten Post habe ich das Problem schon konkretisiert: Mangelnde Kenntnisse im AT-Befehlssatz und Kommunikation mit einem seriellen analog Modem. Natürlich könnt ihr code haben, aber hier handelt es sich weniger um ein PB-Programmier- und Umsatzproblem, sondern mehr in Modem-Know-How.
@DarkDragon: Einige Seiten zu AT habe ich ja schon, jedoch ist mir nicht klar (wie im ersten Post geschrieben), wie es erkennbar ist (über das ECHO?) das ein Connect stattfindet, sprich - wie bekomme ich per ReadSerial mit, WANN eine Verbindung stattfindet. Ich habe gelesen es kommt bei eingeschaltetem ECHO (E1) ein CONNECTED zürück. Ist aber nicht so. Der Tipp mit dem VoiceModem prüfe ich. Ich bin allerdings davon ausgegangen, da die Hardware aktuell ist.
@kunstlust: Prüfe ich - davon bin ich ausgegangen. Die Hardware ist aktuell.
Code: Alles auswählen
;
;
; 232Notifier
; (c) Stephen Kalisch, 2012
;
;
EnableExplicit
#sw_name = "232Notifier"
#sw_version = "v0.1_ALPHA"
#sw_autor = "Stephen Kalisch"
#sw_email = "software@ria-tec.com"
#sw_customer = "KUNDE"
;
;- CONSTANTS
;
#logo_tuppi = 1
#PortID = 1
#win_main = 1
#gadget_width = 120
#sound_dir = "Sounds\"
#AT_reset = "ATZ"
#AT_dial = "ATD"
#AT_erkennung = "ATX4"
#AT_dialkeep = ";"
#at_hookoff = "ATH"
#AT_Send = #CR$
#BUFFER_READ = 1024
#BUFFER_WRITE = 1024
; Enumerations
Enumeration ; Window
#win_main_button_ListenSwitch
#win_main_statusbar
#win_main_log
#win_main_panel
#GADGET_START
#win_main_readcom
#win_main_writecom
#win_main_modemcom
#win_main_read_comport
#win_main_read_baud
#win_main_read_parity
#win_main_read_data
#win_main_read_stopbits
#win_main_read_atinit
#win_main_read_phone
#win_main_write_comport
#win_main_write_baud
#win_main_write_parity
#win_main_write_data
#win_main_write_stopbits
#win_main_write_atinit
#win_main_write_phone
#win_main_modem_comport
#win_main_modem_baud
#win_main_modem_parity
#win_main_modem_data
#win_main_modem_stopbits
#win_main_modem_atinit
#win_main_modem_phone
#win_main_job_list
#win_main_job_addjob
#win_main_job_deletejob
#win_main_job_editjob
#win_job_searchstring
#win_job_phonenumber
#win_job_voicefile
#win_job_savejob
#GADGET_END
EndEnumeration
;
;- VARS
;
Structure PORTCFG
ID.l
Port$
Baud.l
Bytes.c
Stopbits.c
Partiy.l; = #PB_SerialPort_NoParity
Init$
Buffer$
EndStructure
Structure JOBSTRUCTURE
active.b
SearchString$
PhoneNumber$
VoiceFile$
EndStructure
Global ReadPort.PORTCFG, WritePort.PORTCFG, ModemPort.PORTCFG
Global MaxCOMPorts = 20, ExePath$
Define.l we, c
Define.w x, y, xSpace, ySpace
Define.s Dummy$
Define.s searchstring$, phonenumber$, voicefile$
Global NewList Job.JOBSTRUCTURE()
; Exe-Path ermitteln
ExePath$ = Space(1000)
GetModuleFileName_(0,@ExePath$,1000)
ExePath$ = GetPathPart(ExePath$)
;
;- PROCEDURES
;
Procedure Die(Txt$)
MessageRequester(#sw_name + " - FEHLER", Txt$ + #CRLF$ + #CRLF$ + "Bitte wenden Sie sich an den Betreiber der Anlage!", #MB_ICONERROR)
End
EndProcedure
Procedure LogIt(Txt$)
Protected hndFile
; LOg to file
hndFile = OpenFile(#PB_Any, ExePath$ + FormatDate("_%yyyy-%mm-%dd", Date()) + ".log")
If hndFile
WriteStringN(hndFile, FormatDate("[%dd.%mm.%yy %hh:%ii:%ss] ", Date()) + Txt$)
CloseFile(hndFile)
EndIf
; Log to syslog-panel
AddGadgetItem(#win_main_log, -1, FormatDate("[%dd.%mm.%yy %hh:%ii:%ss] ", Date()) + Txt$)
While WindowEvent() : Wend
EndProcedure
Procedure SaveConfig()
Protected c
If CreatePreferences(ExePath$ + #sw_name + ".ini")
PreferenceGroup("ReadPort")
WritePreferenceString("COM-Port", ReadPort\Port$)
WritePreferenceInteger("Baud", ReadPort\Baud)
WritePreferenceInteger("DataBits", ReadPort\Bytes)
WritePreferenceInteger("StopBits", ReadPort\Stopbits)
WritePreferenceInteger("Parity", ReadPort\Partiy)
WritePreferenceString("AT-Init", ReadPort\Init$)
PreferenceGroup("WritePort")
WritePreferenceString("COM-Port", WritePort\Port$)
WritePreferenceInteger("Baud", WritePort\Baud)
WritePreferenceInteger("DataBits", WritePort\Bytes)
WritePreferenceInteger("StopBits", WritePort\Stopbits)
WritePreferenceInteger("Parity", WritePort\Partiy)
WritePreferenceString("AT-Init", WritePort\Init$)
PreferenceGroup("ModemPort")
WritePreferenceString("COM-Port", ModemPort\Port$)
WritePreferenceInteger("Baud", ModemPort\Baud)
WritePreferenceInteger("DataBits", ModemPort\Bytes)
WritePreferenceInteger("StopBits", ModemPort\Stopbits)
WritePreferenceInteger("Parity", ModemPort\Partiy)
WritePreferenceString("AT-Init", ModemPort\Init$)
c = 0
ForEach Job()
c + 1
PreferenceGroup("Job #" + Str(c))
WritePreferenceLong("Active", Job()\active)
WritePreferenceString("Searchstring", Job()\SearchString$)
WritePreferenceString("Phonenumber", Job()\PhoneNumber$)
WritePreferenceString("Voicefile", GetFilePart(Job()\VoiceFile$))
Next
LogIt("Konfiguration gespeichert")
StatusBarText(#win_main_statusbar, 0, "Konfig gespeichert")
EndIf
EndProcedure
Procedure LoadConfig()
Protected ComPort$ = ""
Protected ComBaud = 0
Protected ComData = 8
Protected ComStop = 1
Protected ComParity = #PB_SerialPort_NoParity
Protected ComInit$ = ""
Protected c
If OpenPreferences(ExePath$ + #sw_name + ".ini")
PreferenceGroup("ReadPort")
ReadPort\Port$ = ReadPreferenceString("COM-Port", ComPort$)
ReadPort\Baud = ReadPreferenceInteger("Baud", ComBaud)
ReadPort\Bytes = ReadPreferenceInteger("DataBits", ComData)
ReadPort\Stopbits = ReadPreferenceInteger("StopBits", ComStop)
ReadPort\Partiy = ReadPreferenceInteger("Parity", ComParity)
ReadPort\Init$ = ReadPreferenceString("AT-Init", ComInit$)
PreferenceGroup("WritePort")
WritePort\Port$ = ReadPreferenceString("COM-Port", ComPort$)
WritePort\Baud = ReadPreferenceInteger("Baud", ComBaud)
WritePort\Bytes = ReadPreferenceInteger("DataBits", ComData)
WritePort\Stopbits = ReadPreferenceInteger("StopBits", ComStop)
WritePort\Partiy = ReadPreferenceInteger("Parity", ComParity)
WritePort\Init$ = ReadPreferenceString("AT-Init", ComInit$)
PreferenceGroup("ModemPort")
ModemPort\Port$ = ReadPreferenceString("COM-Port", ComPort$)
ModemPort\Baud = ReadPreferenceInteger("Baud", ComBaud)
ModemPort\Bytes = ReadPreferenceInteger("DataBits", ComData)
ModemPort\Stopbits = ReadPreferenceInteger("StopBits", ComStop)
ModemPort\Partiy = ReadPreferenceInteger("Parity", ComParity)
ModemPort\Init$ = ReadPreferenceString("AT-Init", ComInit$)
c = 0
ClearList(Job())
Repeat
c + 1
If PreferenceGroup("Job #" + Str(c))
AddElement(Job())
Job()\active = ReadPreferenceLong("Active", 0)
Job()\SearchString$ = ReadPreferenceString("Searchstring", "-")
Job()\PhoneNumber$ = ReadPreferenceString("Phonenumber", "-")
Job()\VoiceFile$ = ReadPreferenceString("Voicefile", "-")
Debug "read job #" + Str(c)
Debug Job()\SearchString$
Else
Debug "end of reading jobs at pos " + Str(c)
c = -1
EndIf
Until c = -1
Debug"Konfiguration geladen"
EndIf
EndProcedure
Procedure.s SK_ReadSerialPortString(PortNo)
Protected *Buffer, bufferlen = 1024, lTimer = 250, receivedString$, receivedBytes
*buffer = AllocateMemory(bufferlen)
If *buffer
Repeat
Delay(1)
lTimer -1
receivedBytes = ReadSerialPortData(PortNo, *Buffer, bufferlen)
If receivedBytes
receivedString$ + PeekS(*buffer, receivedBytes)
lTimer = 250
EndIf
Until receivedBytes < bufferlen Or lTimer <= 0
FreeMemory(*buffer)
EndIf
ProcedureReturn receivedString$
EndProcedure
Procedure.s ReadSerialPortString(port.i)
Protected length.i = AvailableSerialPortInput(port)
Protected *mem, pos = 0
Protected result.s
If length And IsSerialPort(port)
*mem = AllocateMemory(length)
While pos < length
pos + ReadSerialPortData(port, *mem + pos, length - pos)
Wend
result = PeekS(*mem, length)
FreeMemory(*mem)
ProcedureReturn result
EndIf
ProcedureReturn ""
EndProcedure
Procedure FillJobList()
Protected c
ClearGadgetItems(#win_main_job_list)
c = 0
ForEach Job()
AddGadgetItem(#win_main_job_list, c, Chr(10) + Job()\SearchString$ + Chr(10) + Job()\PhoneNumber$ + Chr(10) + GetFilePart(Job()\VoiceFile$))
If Job()\active = #True
SetGadgetItemState(#win_main_job_list, c, #PB_ListIcon_Checked)
EndIf
c + 1
Next
EndProcedure
Procedure JobWindow(search$ = "", phone$ = "", voicefile$ = "")
Protected hndJob
Protected bJobExit.b = #False
Protected we.l, x, y, xSpace, ySpace, c
; Edit existing Job?
If search$ <> "" And phone$ <> ""
ForEach Job()
If Job()\SearchString$ = search$ And Job()\PhoneNumber$ = phone$
Break
EndIf
Next
EndIf
hndJob = OpenWindow(#PB_Any, 0, 0, 270, 120, #sw_name + " - Job", #PB_Window_ScreenCentered | #PB_Window_SystemMenu, WindowID(#win_main))
If IsWindow(hndJob)
x = 5
y = 5
xSpace = 5
ySpace = 25
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Suchstring")
StringGadget(#win_job_searchstring, x + #gadget_width + 10, y, #gadget_width, 20, search$)
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Telefon-Nr")
StringGadget(#win_job_phonenumber, x + #gadget_width + 10, y, #gadget_width, 20, phone$)
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Voice-Datei")
ComboBoxGadget(#win_job_voicefile, x + #gadget_width + 10, y, #gadget_width, 20)
y + ySpace
ButtonGadget(#win_job_savejob, x, y, WindowWidth(hndJob) - x*2, 30, "Speichern")
; Voice-Files
If ExamineDirectory(1, ExePath$ + #sound_dir, "*.wav")
c = 0
While NextDirectoryEntry(1)
c + 1
AddGadgetItem(#win_job_voicefile, -1, DirectoryEntryName(1))
If GetFilePart(voicefile$) = DirectoryEntryName(1)
SetGadgetState(#win_job_voicefile, c-1)
EndIf
Wend
FinishDirectory(1)
EndIf
Repeat
Delay(1)
we = WaitWindowEvent(1)
If we
Select EventGadget()
Case #win_job_savejob
bJobExit = #True
EndSelect
EndIf
Until we = #PB_Event_CloseWindow Or bJobExit = #True
If bJobExit = #True
If GetGadgetText(#win_job_phonenumber)<>"" And GetGadgetText(#win_job_searchstring)<>""
; New Job?
If search$ = "" And phone$ = ""
AddElement(Job())
Job()\active = #True
EndIf
Job()\PhoneNumber$ = GetGadgetText(#win_job_phonenumber)
Job()\SearchString$ = GetGadgetText(#win_job_searchstring)
Job()\VoiceFile$ = ExePath$ + #sound_dir + GetGadgetItemText(#win_job_voicefile, GetGadgetState(#win_job_voicefile))
FillJobList()
SaveConfig()
EndIf
EndIf
CloseWindow(hndJob)
EndIf
EndProcedure
Procedure CheckJobs(string2check$)
Protected filelen
Protected *buffer
Protected dummy$
Debug "Checking Input '" + string2check$ + "' with Jobs..."
ForEach Job()
Debug "Job: " + Job()\SearchString$
If FindString(UCase(string2check$), UCase(Job()\SearchString$))
If IsSerialPort(ModemPort\id)
Debug "DIALING..." + Job()\PhoneNumber$
WriteSerialPortString(ModemPort\id, #AT_dial + Job()\PhoneNumber$ + #AT_dialkeep + #AT_Send)
dummy$ = ReadSerialPortString(ModemPort\id)
Debug Dummy$
If FindString(dummy$, "OK")
If ReadFile(0, Job()\VoiceFile$)
filelen = Lof(0)
*buffer = AllocateMemory(filelen)
If ReadData(0, *buffer, filelen) = filelen
Debug "VOICE FILE READ OK"
WriteSerialPortData(ModemPort\ID, *buffer, filelen)
Else
Debug "VOICE FILE READ IS NOT OK !!!"
EndIf
CloseFile(0)
EndIf
WriteSerialPortString(ModemPort\ID, #at_hookoff)
EndIf
Else
Debug "NO COM FOR MODEM"
EndIf
EndIf
Next
EndProcedure
;
;- INIT
;
UsePNGImageDecoder()
CatchImage(#logo_tuppi, ?logo_tuppi)
LoadConfig()
;
;- WINDOWS
;
;{
If OpenWindow(#win_main, 0, 0, 500, 620, #sw_name + Chr(32) + #sw_version, #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
x = 5
y = 5
xSpace = 5
ySpace = 25
;
; Statusbar
;
If CreateStatusBar(#win_main_statusbar, WindowID(#win_main))
AddStatusBarField(#PB_Ignore) : StatusBarText(#win_main_statusbar, 0, "...")
AddStatusBarField(220)
Else
Die("KEINE STATUSBAR")
EndIf
ImageGadget(#PB_Any, x, y, ImageWidth(#logo_tuppi), ImageHeight(#logo_tuppi), ImageID(#logo_tuppi))
x = ImageWidth(#logo_tuppi) + xSpace
; Button for listeing
ButtonGadget(#win_main_button_ListenSwitch, WindowWidth(#win_main) - xSpace - #gadget_width*2, y, #gadget_width * 2, 50, "Mitschnitt einschalten", #PB_Button_Toggle)
; PANEL
x = 5
y + ySpace * 2 + 5
PanelGadget(#win_main_panel, x, y, WindowWidth(#win_main) - 10, WindowHeight(#win_main) - 10 - StatusBarHeight(#win_main_statusbar) - y)
; Syslog
y = 5
AddGadgetItem(#win_main_panel, - 1, "System-Log")
ListViewGadget(#win_main_log, x, y, GadgetWidth(#win_main_panel) - 20, GadgetHeight(#win_main_panel) - 20 - StatusBarHeight(#win_main_statusbar))
;
; READ PORT : COM Input
;
AddGadgetItem(#win_main_panel, -1, "READ-Port")
TextGadget(#PB_Any, x, y, #gadget_width, 20, "COM-Port")
ComboBoxGadget(#win_main_read_comport, #gadget_width + 10, y, #gadget_width, 20)
; Baud-Rate
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Speed (Baud)")
ComboBoxGadget(#win_main_read_baud, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_read_baud, -1, "2400")
AddGadgetItem(#win_main_read_baud, -1, "4800")
AddGadgetItem(#win_main_read_baud, -1, "9600")
AddGadgetItem(#win_main_read_baud, -1, "19200")
AddGadgetItem(#win_main_read_baud, -1, "38400")
AddGadgetItem(#win_main_read_baud, -1, "57600 ")
AddGadgetItem(#win_main_read_baud, -1, "115200")
For c = 0 To CountGadgetItems(#win_main_read_baud)-1
If Val(GetGadgetItemText(#win_main_read_baud, c)) = ReadPort\Baud
SetGadgetState(#win_main_read_baud, c)
Break
EndIf
Next c
; Parity
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Parität")
ComboBoxGadget(#win_main_read_parity, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_read_parity, -1, "Keine Parität: " + Str(#PB_SerialPort_NoParity))
AddGadgetItem(#win_main_read_parity, -1, "Gerade Parität: " + Str(#PB_SerialPort_EvenParity))
For c = 0 To CountGadgetItems(#win_main_read_parity)-1
If Val(Right(GetGadgetItemText(#win_main_read_parity, c), 1)) = ReadPort\Partiy
SetGadgetState(#win_main_read_parity, c)
Break
EndIf
Next c
; Data-Length
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Data-Länge")
ComboBoxGadget(#win_main_read_data, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_read_data, -1, "7")
AddGadgetItem(#win_main_read_data, -1, "8")
For c = 0 To CountGadgetItems(#win_main_read_data)-1
If Val(GetGadgetItemText(#win_main_read_data, c)) = ReadPort\Bytes
SetGadgetState(#win_main_read_data, c)
Break
EndIf
Next c
; Stop Bits
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Stop-Bits")
ComboBoxGadget(#win_main_read_stopbits, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_read_stopbits, -1, "1")
AddGadgetItem(#win_main_read_stopbits, -1, "1.5")
AddGadgetItem(#win_main_read_stopbits, -1, "2")
For c = 0 To CountGadgetItems(#win_main_read_stopbits)-1
If Val(GetGadgetItemText(#win_main_read_stopbits, c)) = ReadPort\Stopbits
SetGadgetState(#win_main_read_stopbits, c)
Break
EndIf
Next c
y + ySpace
ListViewGadget(#win_main_readcom, x, y, GadgetWidth(#win_main_panel) - 20, GadgetHeight(#win_main_panel) - 20 - y - StatusBarHeight(#win_main_statusbar))
;
; WRITE PORT : COM output
;
AddGadgetItem(#win_main_panel, -1, "WRITE-Port")
y =5
TextGadget(#PB_Any, x, y, #gadget_width, 20, "COM-Port")
ComboBoxGadget(#win_main_write_comport, #gadget_width + 10, y, #gadget_width, 20)
; Baud-Rate
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Speed (Baud)")
ComboBoxGadget(#win_main_write_baud, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_write_baud, -1, "2400")
AddGadgetItem(#win_main_write_baud, -1, "4800")
AddGadgetItem(#win_main_write_baud, -1, "9600")
AddGadgetItem(#win_main_write_baud, -1, "19200")
AddGadgetItem(#win_main_write_baud, -1, "38400")
AddGadgetItem(#win_main_write_baud, -1, "57600 ")
AddGadgetItem(#win_main_write_baud, -1, "115200")
For c = 0 To CountGadgetItems(#win_main_write_baud)-1
If Val(GetGadgetItemText(#win_main_write_baud, c)) = WritePort\Baud
SetGadgetState(#win_main_write_baud, c)
Break
EndIf
Next c
; Parity
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Parität")
ComboBoxGadget(#win_main_write_parity, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_write_parity, -1, "Keine Parität: " + Str(#PB_SerialPort_NoParity))
AddGadgetItem(#win_main_write_parity, -1, "Gerade Parität: " + Str(#PB_SerialPort_EvenParity))
For c = 0 To CountGadgetItems(#win_main_write_parity)-1
If Val(Right(GetGadgetItemText(#win_main_write_parity, c), 1)) = WritePort\Partiy
SetGadgetState(#win_main_write_parity, c)
Break
EndIf
Next c
; Data-Length
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Data-Länge")
ComboBoxGadget(#win_main_write_data, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_write_data, -1, "7")
AddGadgetItem(#win_main_write_data, -1, "8")
For c = 0 To CountGadgetItems(#win_main_write_data)-1
If Val(GetGadgetItemText(#win_main_write_data, c)) = WritePort\Bytes
SetGadgetState(#win_main_write_data, c)
Break
EndIf
Next c
; Stop Bits
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Stop-Bits")
ComboBoxGadget(#win_main_write_stopbits, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_write_stopbits, -1, "1")
AddGadgetItem(#win_main_write_stopbits, -1, "1.5")
AddGadgetItem(#win_main_write_stopbits, -1, "2")
For c = 0 To CountGadgetItems(#win_main_write_stopbits)-1
If Val(GetGadgetItemText(#win_main_write_stopbits, c)) = WritePort\Stopbits
SetGadgetState(#win_main_write_stopbits, c)
Break
EndIf
Next c
y + ySpace
ListViewGadget(#win_main_writecom, x, y, GadgetWidth(#win_main_panel) - 20, GadgetHeight(#win_main_panel) - 20 - y - StatusBarHeight(#win_main_statusbar))
;
; MODEM-Port
;
; Config
AddGadgetItem(#win_main_panel, -1, "MODEM-Port")
x = 5
y = 5
TextGadget(#PB_Any, x, y, #gadget_width, 20, "COM-Port")
ComboBoxGadget(#win_main_modem_comport, #gadget_width + 10, y, #gadget_width, 20)
; Baud-Rate
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Speed (Baud)")
ComboBoxGadget(#win_main_modem_baud, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_modem_baud, -1, "2400")
AddGadgetItem(#win_main_modem_baud, -1, "4800")
AddGadgetItem(#win_main_modem_baud, -1, "9600")
AddGadgetItem(#win_main_modem_baud, -1, "19200")
AddGadgetItem(#win_main_modem_baud, -1, "38400")
AddGadgetItem(#win_main_modem_baud, -1, "57600 ")
AddGadgetItem(#win_main_modem_baud, -1, "115200")
For c = 0 To CountGadgetItems(#win_main_modem_baud)-1
If Val(GetGadgetItemText(#win_main_modem_baud, c)) = ModemPort\Baud
SetGadgetState(#win_main_modem_baud, c)
Break
EndIf
Next c
; Parity
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Parität")
ComboBoxGadget(#win_main_modem_parity, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_modem_parity, -1, "Keine Parität: " + Str(#PB_SerialPort_NoParity))
AddGadgetItem(#win_main_modem_parity, -1, "Gerade Parität: " + Str(#PB_SerialPort_EvenParity))
For c = 0 To CountGadgetItems(#win_main_modem_parity)-1
If Val(Right(GetGadgetItemText(#win_main_modem_parity, c), 1)) = ModemPort\Partiy
SetGadgetState(#win_main_modem_parity, c)
Break
EndIf
Next c
; Data-Length
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Data-Länge")
ComboBoxGadget(#win_main_modem_data, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_modem_data, -1, "7")
AddGadgetItem(#win_main_modem_data, -1, "8")
For c = 0 To CountGadgetItems(#win_main_modem_data)-1
If Val(GetGadgetItemText(#win_main_modem_data, c)) = ModemPort\Bytes
SetGadgetState(#win_main_modem_data, c)
Break
EndIf
Next c
; Stop Bits
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "Stop-Bits")
ComboBoxGadget(#win_main_modem_stopbits, #gadget_width + 10, y, #gadget_width, 20)
AddGadgetItem(#win_main_modem_stopbits, -1, "1")
AddGadgetItem(#win_main_modem_stopbits, -1, "1.5")
AddGadgetItem(#win_main_modem_stopbits, -1, "2")
For c = 0 To CountGadgetItems(#win_main_modem_stopbits)-1
If Val(GetGadgetItemText(#win_main_modem_stopbits, c)) = ModemPort\Stopbits
SetGadgetState(#win_main_modem_stopbits, c)
Break
EndIf
Next c
; INIT-String
y + ySpace
TextGadget(#PB_Any, x, y, #gadget_width, 20, "AT-Init")
StringGadget(#win_main_modem_atinit, #gadget_width + 10, y, #gadget_width, 20, WritePort\Init$)
y + ySpace
ListViewGadget(#win_main_modemcom, x, y, GadgetWidth(#win_main_panel) - 20, GadgetHeight(#win_main_panel) - 20 - y - StatusBarHeight(#win_main_statusbar))
;
; JOB LIST
;
AddGadgetItem(#win_main_panel, -1, "Jobs")
y = 5
ButtonGadget(#win_main_job_addjob, x, y, #gadget_width, 20, "Neuer Job")
ButtonGadget(#win_main_job_editjob, x + #gadget_width + xSpace, y, #gadget_width, 20, "Job ändern")
ButtonGadget(#win_main_job_deletejob, x + #gadget_width*2 + xSpace*2, y, #gadget_width, 20, "Job löschen")
y + ySpace
ListIconGadget(#win_main_job_list, x, y, GadgetWidth(#win_main_panel) - 20, GadgetHeight(#win_main_panel) - 20 - y - StatusBarHeight(#win_main_statusbar), "An/Aus", 60, #PB_ListIcon_CheckBoxes | #PB_ListIcon_GridLines |#PB_ListIcon_FullRowSelect)
AddGadgetColumn(#win_main_job_list, 1, "Suchstring", 100)
AddGadgetColumn(#win_main_job_list, 2, "Telefon-Nr", 110)
AddGadgetColumn(#win_main_job_list, 3, "Voice-Datei", 130)
FillJobList()
While WindowEvent() : Wend
Else
Die("KEIN FENSTER")
EndIf
;}
;
;-MAIN
;
; Check connected Modems
StatusBarText(#win_main_statusbar, 0, "Prüfe COM-Ports...")
For c = 1 To MaxCOMPorts
StatusBarText(#win_main_statusbar, 1, "COM" + Str(c))
AddGadgetItem(#win_main_read_comport, -1, "COM" + Str(c))
AddGadgetItem(#win_main_write_comport, -1, "COM" + Str(c))
If OpenSerialPort(#PortID, "COM" + Str(c), ReadPort\Baud, ReadPort\Partiy, ReadPort\Bytes, ReadPort\Stopbits, #PB_SerialPort_NoHandshake, 4096, 4096)
LogIt("COM" + Str(c) + " verfügbar")
; If WriteSerialPortString(#portID, "AT" + #CR$)
; LogIt("AT von COM" + Str(c) + ": " + SK_ReadSerialPortString(#portID))
; EndIf
AddGadgetItem(#win_main_modem_comport, -1, "COM" + Str(c))
CloseSerialPort(#portID)
While WindowEvent(): Delay(1): Wend
EndIf
Delay(100)
Next c
; Select Ports in Lists
For c = 0 To CountGadgetItems(#win_main_read_comport) -1
If ReadPort\Port$ = GetGadgetItemText(#win_main_read_comport, c)
SetGadgetState(#win_main_read_comport, c)
Break
EndIf
Next c
For c = 0 To CountGadgetItems(#win_main_write_comport) -1
If WritePort\Port$ = GetGadgetItemText(#win_main_write_comport, c)
SetGadgetState(#win_main_write_comport, c)
Break
EndIf
Next c
For c = 0 To CountGadgetItems(#win_main_modem_comport) -1
If ModemPort\Port$ = GetGadgetItemText(#win_main_modem_comport, c)
SetGadgetState(#win_main_modem_comport, c)
Break
EndIf
Next c
;
;
; MAIN LOOP
;
;
; Ready
StatusBarText(#win_main_statusbar, 0, #sw_customer)
Repeat
we = WaitWindowEvent(1)
Delay(1)
;
; READPORT
;
If IsSerialPort(ReadPort\ID)
dummy$ = ReadSerialPortString(ReadPort\ID)
If dummy$
; Store input
ReadPort\Buffer$ + dummy$
If Right(dummy$, 2) = #CRLF$
; Log input
AddGadgetItem(#win_main_readcom, -1, ReadPort\Buffer$)
LogIt("READ " + ReadPort\Port$ +": " + ReadPort\Buffer$)
; send to WRITE PORT
If IsSerialPort(WritePort\ID)
If WriteSerialPortString(WritePort\id, ReadPort\Buffer$)
AddGadgetItem(#win_main_writecom, -1, ReadPort\Buffer$)
LogIt("WRITE " + WritePort\Port$ + ": " + ReadPort\Buffer$)
If AvailableSerialPortOutput(WritePort\ID) > 0
LogIt("WRITE-Buffer hat noch " + Str(AvailableSerialPortOutput(WritePort\id)) + " Bytes von " + Str(Len(ReadPort\Buffer$)) + " übrig!")
EndIf
Else
LogIt("FEHLER BEIM SCHREIBEN AUF WRITEPORT " + WritePort\Port$ + " : " + ReadPort\Buffer$)
EndIf
EndIf
; Check the Jobs
CheckJobs(ReadPort\Buffer$)
; Clear temp input
ReadPort\Buffer$ = ""
EndIf
EndIf
EndIf
;
; GADGETS
;
If we = #PB_Event_Gadget
Select EventGadget()
Case #win_main_job_list
; #PB_ListIcon_Selected =
; GetGadgetState(#win_main_job_list)
For c = 0 To CountGadgetItems(#win_main_job_list) - 1
; #PB_ListIcon_Selected
; #PB_ListIcon_Checked
Next
; ListIconGadget(
Case #win_main_job_addjob
JobWindow()
Case #win_main_job_editjob
searchstring$ = GetGadgetItemText(#win_main_job_list, GetGadgetState(#win_main_job_list), 1)
phonenumber$ = GetGadgetItemText(#win_main_job_list, GetGadgetState(#win_main_job_list), 2)
voicefile$ = GetGadgetItemText(#win_main_job_list, GetGadgetState(#win_main_job_list), 3)
JobWindow(searchstring$, phonenumber$, voicefile$)
Case #win_main_job_deletejob
searchstring$ = GetGadgetItemText(#win_main_job_list, GetGadgetState(#win_main_job_list), 1)
phonenumber$ = GetGadgetItemText(#win_main_job_list, GetGadgetState(#win_main_job_list), 2)
voicefile$ = GetGadgetItemText(#win_main_job_list, GetGadgetState(#win_main_job_list), 3)
; find job in list
ForEach Job()
If Job()\SearchString$ = searchstring$ And Job()\PhoneNumber$ = phonenumber$ And Job()\VoiceFile$ = voicefile$
DeleteElement(job())
Break
EndIf
Next
FillJobList()
Case #win_main_button_ListenSwitch
If GetGadgetState(#win_main_button_ListenSwitch) = #True
; Open COM Ports
ReadPort\id = OpenSerialPort(#PB_Any, ReadPort\Port$, ReadPort\Baud, readport\Partiy, ReadPort\Bytes, ReadPort\Stopbits, #PB_SerialPort_NoHandshake, #BUFFER_READ, #BUFFER_WRITE)
WritePort\id = OpenSerialPort(#PB_Any, WritePort\Port$, WritePort\Baud, WritePort\Partiy, WritePort\Bytes, WritePort\Stopbits, #PB_SerialPort_NoHandshake, #BUFFER_READ, #BUFFER_WRITE)
ModemPort\id = OpenSerialPort(#PB_Any, ModemPort\Port$, ModemPort\Baud, ModemPort\Partiy, ModemPort\Bytes, ModemPort\Stopbits, #PB_SerialPort_NoHandshake, #BUFFER_READ, #BUFFER_WRITE)
; Check COM Ports if OK
If IsSerialPort(ReadPort\ID)
Logit("READ-Port " + ReadPort\Port$ + " geöffnet")
AddGadgetItem(#win_main_readcom, -1, "--- STARTE LESEN VON READPORT " + ReadPort\Port$ + " ---")
Else
StatusBarText(#win_main_statusbar, 1, "Fehler beim öffnen des READ-Ports: " + ReadPort\Port$)
Logit("Fehler beim öffnen des READ-Ports: " + ReadPort\Port$)
EndIf
If IsSerialPort(WritePort\ID)
Logit("WRITE-Port " + WritePort\Port$ + " geöffnet")
AddGadgetItem(#win_main_writecom, -1, "--- STARTE WEITERLEITEN AUF WRITEPORT " + WritePort\Port$ + "---")
Else
StatusBarText(#win_main_statusbar, 1, "Fehler beim öffnen des WRITE-Ports: " + WritePort\Port$)
Logit("Fehler beim öffnen des WRITE-Ports: " + WritePort\Port$)
EndIf
If IsSerialPort(ModemPort\ID)
Logit("MODEM-Port " + ModemPort\Port$ + " geöffnet. Konfiguriere...")
WriteSerialPortString(ModemPort\id, "ATZ" + #CR$)
Debug ReadSerialPortString(ModemPort\ID)
WriteSerialPortString(ModemPort\id, "ATE1" + #CR$)
Debug ReadSerialPortString(ModemPort\ID)
Else
StatusBarText(#win_main_statusbar, 1, "Fehler beim öffnen des MODEM-Ports: " + ModemPort\Port$)
Logit("Fehler beim öffnen des MODEM-Ports: " + ModemPort\Port$)
EndIf
; Switch Button
SetGadgetText(#win_main_button_ListenSwitch, "Mitschnitt AUSSCHALTEN")
; Inform User
StatusBarText(#win_main_statusbar, 0, "Mitschnitt eingeschaltet")
; Switch Gadgets
For c = #GADGET_START To #GADGET_END
If IsGadget(c) : DisableGadget(c, #True) : EndIf
Next
ElseIf GetGadgetState(#win_main_button_ListenSwitch) = #False
; Inform user
StatusBarText(#win_main_statusbar, 1, "Mitlesen beendet für READ-Port: " + ReadPort\Port$)
; Switch Button
SetGadgetText(#win_main_button_ListenSwitch, "Mitschnitt EINSCHALTEN")
StatusBarText(#win_main_statusbar, 0, "Mitschnitt ausgeschaltet")
; Switch Gagdets
For c = #GADGET_START To #GADGET_END
If IsGadget(c) : DisableGadget(c, #False) : EndIf
Next
; Close Ports
If IsSerialPort(ReadPort\id)
CloseSerialPort(ReadPort\ID)
LogIt("ReadPort " + ReadPort\Port$ + " geschlossen.")
EndIf
If IsSerialPort(WritePort\id)
CloseSerialPort(WritePort\ID)
LogIt("WritePort " + WritePort\Port$ + " geschlossen.")
EndIf
If IsSerialPort(ModemPort\id)
CloseSerialPort(ModemPort\ID)
LogIt("ModemPort " + ModemPort\Port$ + " geschlossen.")
EndIf
EndIf
; READ Port
Case #win_main_read_comport
ReadPort\Port$ = GetGadgetItemText(#win_main_read_comport, GetGadgetState(#win_main_read_comport))
StatusBarText(#win_main_statusbar, 1, "READ-Port: " + ReadPort\Port$)
SaveConfig()
Case #win_main_read_baud
ReadPort\Baud = Val(GetGadgetItemText(#win_main_read_baud, GetGadgetState(#win_main_read_baud)))
StatusBarText(#win_main_statusbar, 1, "Baud-Rate für READ-Port: " + Str(ReadPort\Baud))
SaveConfig()
Case #win_main_read_parity
ReadPort\Partiy = Val(Right(GetGadgetItemText(#win_main_read_parity, GetGadgetState(#win_main_read_parity)), 1))
StatusBarText(#win_main_statusbar, 1, "Parity für READ-Port: " + Str(ReadPort\Partiy))
SaveConfig()
Case #win_main_read_data
ReadPort\Bytes = Val(GetGadgetItemText(#win_main_read_data, GetGadgetState(#win_main_read_data)))
StatusBarText(#win_main_statusbar, 1, "Data-Bytes für READ-Port: " + Str(ReadPort\Bytes))
SaveConfig()
Case #win_main_read_stopbits
ReadPort\Stopbits = Val(GetGadgetItemText(#win_main_read_stopbits, GetGadgetState(#win_main_read_stopbits)))
StatusBarText(#win_main_statusbar, 1, "Stop-Bits für READ-Port: " + Str(ReadPort\Stopbits))
SaveConfig()
; WRITE Port
Case #win_main_write_comport
writePort\Port$ = GetGadgetItemText(#win_main_write_comport, GetGadgetState(#win_main_write_comport))
StatusBarText(#win_main_statusbar, 1, "WRITE-Port: " + writePort\Port$)
SaveConfig()
Case #win_main_write_baud
writePort\Baud = Val(GetGadgetItemText(#win_main_write_baud, GetGadgetState(#win_main_write_baud)))
StatusBarText(#win_main_statusbar, 1, "Baud-Rate für write-Port: " + Str(writePort\Baud))
SaveConfig()
Case #win_main_write_parity
writePort\Partiy = Val(Right(GetGadgetItemText(#win_main_write_parity, GetGadgetState(#win_main_write_parity)), 1))
StatusBarText(#win_main_statusbar, 1, "Parity für write-Port: " + Str(writePort\Partiy))
SaveConfig()
Case #win_main_write_data
writePort\Bytes = Val(GetGadgetItemText(#win_main_write_data, GetGadgetState(#win_main_write_data)))
StatusBarText(#win_main_statusbar, 1, "Data-Bytes für write-Port: " + Str(writePort\Bytes))
SaveConfig()
Case #win_main_write_stopbits
writePort\Stopbits = Val(GetGadgetItemText(#win_main_write_stopbits, GetGadgetState(#win_main_write_stopbits)))
StatusBarText(#win_main_statusbar, 1, "Stop-Bits für write-Port: " + Str(writePort\Stopbits))
SaveConfig()
; MODEM Port
Case #win_main_modem_comport
ModemPort\Port$ = GetGadgetItemText(#win_main_modem_comport, GetGadgetState(#win_main_modem_comport))
StatusBarText(#win_main_statusbar, 1, "MODEM-Port: " + ModemPort\Port$)
SaveConfig()
Case #win_main_modem_baud
ModemPort\Baud = Val(GetGadgetItemText(#win_main_modem_baud, GetGadgetState(#win_main_modem_baud)))
StatusBarText(#win_main_statusbar, 1, "Baud-Rate für MODEM-Port: " + Str(ModemPort\Baud))
SaveConfig()
Case #win_main_modem_parity
ModemPort\Partiy = Val(Right(GetGadgetItemText(#win_main_modem_parity, GetGadgetState(#win_main_modem_parity)), 1))
StatusBarText(#win_main_statusbar, 1, "Parity für MODEM-Port: " + Str(ModemPort\Partiy))
SaveConfig()
Case #win_main_modem_data
ModemPort\Bytes = Val(GetGadgetItemText(#win_main_modem_data, GetGadgetState(#win_main_modem_data)))
StatusBarText(#win_main_statusbar, 1, "Data-Bytes für MODEM-Port: " + Str(ModemPort\Bytes))
SaveConfig()
Case #win_main_modem_stopbits
ModemPort\Stopbits = Val(GetGadgetItemText(#win_main_modem_stopbits, GetGadgetState(#win_main_modem_stopbits)))
StatusBarText(#win_main_statusbar, 1, "Stop-Bits für MODEM-Port: " + Str(ModemPort\Stopbits))
SaveConfig()
Case #win_main_modem_atinit
ModemPort\Init$ = GetGadgetText(#win_main_modem_atinit)
StatusBarText(#win_main_statusbar, 1, "AT-Init für MODEM-Port: " + ModemPort\Init$)
SaveConfig()
EndSelect
EndIf
Until we = #PB_Event_CloseWindow
;
;- END
;
SaveConfig()
End
;
;- DATA
;
DataSection
logo_tuppi: IncludeBinary "Grafiken/Tuppi-Logo.png"
EndDataSection