Seite 1 von 1

Übersetzer gesucht QuickBasic => PureBasic

Verfasst: 22.03.2013 09:35
von Ghosty1967
Kann mir das mal einer in PB übersetzen und lauffähig machen...
Ich werde noch wahnsinnig, egal was ich versuche, ich bekomme keine Kommunikation in PB zustande.
In Quick Basic klappts so...

Bitte, bitte helft mir...

Code: Alles auswählen

CLS
LOCATE 1, 1
DIM cmd$(100), resp$(1000)
’ Set up serial port for 9600 baud, even parity, 7 bits;
’ Ignore Request to Send and Carrier Detect; Send line feed,
’ enable parity check, reserve 1000 bytes for input buffer
’
OPEN "com1:9600,e,7,2,rs,cd,lf,pe" FOR RANDOM AS #1 LEN = 1000
’
’ Put the multimeter into the remote operation mode
PRINT #1, ":SYST:REM"
’
’ Query the multimeter’s id string
’
PRINT #1, "*IDN?"
LINE INPUT #1, resp$
PRINT "*IDN? returned: ", resp$
’
’ Ask what revision of SCPI the multimeter conforms to
PRINT #1, ":SYST:VERS?"
LINE INPUT #1, resp$
PRINT ":SYST:VERS? returned: ", resp$
’
’ Send a message to the multimeter’s display, and generate a beep
PRINT #1, ":SYST:BEEP;:DISP:TEXT ’HP 34401A’"
’
’ Configure the multimeter for dc voltage readings,
’ 10 V range, 0.1 V resolution, 4 readings
PRINT #1, ":CONF:VOLT:DC 10,0.1;:SAMP:COUN 4"
’ Trigger the readings, and fetch the results
PRINT #1, ":READ?"
LINE INPUT #1, resp$
PRINT ":READ? returned: ", resp$
END

Re: Übersetzer gesucht QuickBasic => PureBasic

Verfasst: 22.03.2013 16:45
von TroaX
Oha das Übersetzen von QuickBasic zu PureBasic ist schon etwas fummeliger, da PureBasic zu QuickBasic kaum eine kompatibilität aufweist. Während der Befehl OPEN in Quickbasic Je nach Parameter eine Schnittstelle/Datei öffnet, gibt es einen Äquivalenten Befehl in PB leider nicht. Da musst du mit der SerialPort-Bibliothek arbeiten, wenn dein Multimeter auch nach RS232 arbeitet (da gehe ich aber mal von aus).
http://www.purebasic.com/german/documen ... index.html
Da ich mich noch nicht so mit dem Serial-Port auskenne hoffe ich, das dir jemand anderes da mehr zu sagen kann.

Ansonsten kannst du dich natürlich auch statt mit QuickBasic und PureBasic mal mit FreeBasic auseinander setzen. FreeBasic kompiliert auch in Maschienen-Code und läuft ohne Runtimes. Allerdings ist die Syntax und der Befehlssatz nahezu fast identisch mit QuickBasic und ist damit auch näher am System dran. Dadurch kannst du auch Programme für Systeme wie FreeDOS schreiben. je nachdem was du eben brauchst. Zur Not bastelst du dir in FreeBASIC eine DLL und baust sie in dein PureBasic Programm ein.
http://www.freebasic-portal.de/

Ich hoffe aber, das dir jemand den Code hier übersetzen kann :-)

Re: Übersetzer gesucht QuickBasic => PureBasic

Verfasst: 22.03.2013 17:37
von bobobo
eine FreebasicKrücke für PB für so nabbelige PortAbfragen? Ich fass es nicht. 8)

Re: Übersetzer gesucht QuickBasic => PureBasic

Verfasst: 22.03.2013 17:45
von NicTheQuick
Also laut dieser Erklärung, würde ich den COM-Port so öffnen:

Code: Alles auswählen

;OPEN "com1:9600,e,7,2,rs,cd,lf,pe" For RANDOM As #1 LEN = 1000

;Baurate:		9600
;Parity:		even
;Bits per Byte:	7
;Stopbits:		2
;Options
;	rs		->	Suppresses detection of Request To Send (RTS).
;	cd		->	CD[m] Specifies the timeout period on the Data Carrier Detect Line (DCD)
;	lf		->	Effective only with the ASC option.
;	pe		->	
:
;Other things:
;If the RB option is not used or n is omitted, the Default is 512 bytes.
;If the TB option is not used or n is omitted, the Default is 512 bytes.
;If the RS option is not specified, the Request To Send line (RTS) is set high.


OpenSerialPort(#PB_Any, "COM1", 9600, #PB_SerialPort_EvenParity, 7, 2, #PB_SerialPort_NoHandshake, 512, 512)
Und dann weiter mit

Code: Alles auswählen

Ergebnis = WriteSerialPortString(0, ":SYST:REM", #PB_Ascii)

Re: Übersetzer gesucht QuickBasic => PureBasic

Verfasst: 22.03.2013 18:11
von bobobo
#PB_Ascii ist hier Standard auch im UnicodeModus


ömm folgendes ohne Gewähr, hab hier nicht so ein Messgerät
aber ungefähr so könnte was gehen

Code: Alles auswählen

;CLS
;LOCATE 1, 1
;Dim cmd$(100), resp$(1000)
;’ Set up serial port For 9600 baud, even parity, 7 bits;
;’ Ignore Request To Send And Carrier Detect; Send line feed,
;’ enable parity check, reserve 1000 bytes For input buffer
;OPEN "com1:9600,e,7,2,rs,cd,lf,pe" For RANDOM As #1 LEN = 1000
If OpenSerialPort(0, "COM1", 9600, #PB_SerialPort_EvenParity, 7, 2,#PB_SerialPort_NoHandshake,512,512)
    Debug "Success ..weiter im Text"
  Else
    Debug "Failed"
    End
  EndIf

;’ Put the multimeter into the remote operation mode
;PRINT #1, ":SYST:REM"
WriteSerialPortString(0,":SYST:REM")
;’ Query the multimeter’s id string
;PRINT #1, "*IDN?"
WriteSerialPortString(0,"*IDN?")
;LINE INPUT #1, resp$
resp.s=Space(512) ;512 wie Buffer
If AvailableSerialPortInput(0)
  ReadSerialPortData(0,@resp,Len(resp))
EndIf

;PRINT "*IDN? returned: ", resp$
Debug "*IDN? returned: "+ resp$
;’ Ask what revision of SCPI the multimeter conforms To
;PRINT #1, ":SYST:VERS?"
WriteSerialPortString(0,":SYST:VERS?")
;LINE INPUT #1, resp$
resp.s=Space(512) 
If AvailableSerialPortInput(0)
  ReadSerialPortData(0,@resp,Len(resp))
EndIf
;PRINT ":SYST:VERS? returned: ", resp$
Debug ":SYST:VERS? returned: "+ resp
; Send a message To the multimeter’s display, And generate a beep
;PRINT #1, ":SYST:BEEP;:DISP:TEXT ’HP 34401A’"
WriteSerialPortString(0,":SYST:BEEP;:DISP:TEXT ’HP 34401A’")
;’ Configure the multimeter For dc voltage readings,
;’ 10 V range, 0.1 V resolution, 4 readings
;PRINT #1, ":CONF:VOLT:DC 10,0.1;:SAMP:COUN 4"
WriteSerialPortString(0,":CONF:VOLT:DC 10,0.1;:SAMP:COUN 4")
;’ Trigger the readings, And fetch the results
;PRINT #1, ":Read?"
WriteSerialPortString(0,":Read?")

;LINE INPUT #1, resp$
resp.s=Space(512) 
If AvailableSerialPortInput(0)
  ReadSerialPortData(0,@resp,Len(resp))
EndIf
;PRINT ":READ? returned: ", resp$
Debug ":READ? returned: "+ resp$
CloseSerialPort(#SerialPort)
Debug "Zu .. Feierabend"
End

Re: Übersetzer gesucht QuickBasic => PureBasic

Verfasst: 22.03.2013 21:41
von Ghosty1967
Danke, danke erstmal...
jetzt ist Wochenende aber ich werde am Montag direkt mal loslegen und eure Vorschläge ausprobieren.
Mein letzter Versuch sah eigentlich aus wie der Vorschlag von "NicTheQuick" also

Code: Alles auswählen

OpenSerialPort(#PB_Any, "COM1", 9600, #PB_SerialPort_EvenParity, 7, 2, #PB_SerialPort_NoHandshake, 512, 512)
Ergebnis = WriteSerialPortString(0, ":SYST:REM", #PB_Ascii)
nur das ich die Puffergröße anders definiert hatte (128). Eventuell ist ja auch das HP ein wenig zeitkritisch...
Ich werde rumbasteln und euch auf den neusten Stand bringen.
Ich wünsche euch ein schönes Wochenende und mir, das die "Kölner Haie" heute gewinnen! :lol:

Re: Übersetzer gesucht QuickBasic => PureBasic

Verfasst: 25.03.2013 00:27
von Falko
Zwar hat bobobo das in Windows erzeugt, aber ich wollte mal eine Consoleausgabe
zeigen. Leider kann ich bei mir an meinem Multimeter, sowas nicht testen. Kannst ja
mal ausprobieren ob es so bei dir läuft. Wegen dem Puffer, das kannst du ja ändern.
Die Variablen habe ich nur mit Space belegt. Also bitte nur als Testcode ansehen.
Garantieren kann ich im Moment hier nichts, ob es so bei dir läuft.

Code: Alles auswählen

OpenConsole("Ausgabe Multimeter")
  ClearConsole() ;CLS
  ConsoleLocate(1,1);LOCATE 1, 1
  cmd$=Space(100)
  resp$=Space(10000);Dim cmd$(100), resp$(1000)
  ; Set up serial port For 9600 baud, even parity, 7 bits;
  ; Ignore Request To Send And Carrier Detect; Send line feed,
  ; enable parity check, reserve 1000 bytes For input buffer
  ;
  ;OPEN "com1:9600,e,7,2,rs,cd,lf,pe" For RANDOM As #1 LEN = 1000
  OpenSerialPort(1,"COM1",9600,#PB_SerialPort_EvenParity,7,2, #PB_SerialPort_NoHandshake, 1000, 1000)
  
  ;
  ; Put the multimeter into the remote operation mode
  WriteSerialPortString(1, ":SYST:REM");PRINT #1, ":SYST:REM"  ; Format hier ist #PB_Ascii (auch im Unicode-Modus) standard
  ;
  ; Query the multimeter’s id string
  ;
  WriteSerialPortString(1, "*IDN?");PRINT #1, "*IDN?"
  Laenge.l=AvailableSerialPortInput(1)
  If ReadPuffer 
    ReadSerialPortData(1, @resp$, Laenge); LINE INPUT #1, resp$
    PrintN("*IDN? returned: "+resp$) ; PRINT "*IDN? returned: ", resp$
  EndIf
    ;
    ; Ask what revision of SCPI the multimeter conforms To
    WriteSerialPortString(1, ":SYST:VERS?");PRINT #1, ":SYST:VERS?"
    Laenge=AvailableSerialPortInput(1)
  If ReadPuffer 
    ReadSerialPortData(1, @resp$, Laenge);LINE INPUT #1, resp$
    PrintN(":SYST:VERS? returned: "+ resp$) ;PRINT ":SYST:VERS? returned: ", resp$
  EndIf  
  ;
    ; Send a message To the multimeter’s display, And generate a beep
  WriteSerialPortString(1, ":SYST:BEEP;:DISP:TEXT ’HP 34401A’");PRINT #1, ":SYST:BEEP;:DISP:TEXT ’HP 34401A’"
  ;
  ; Configure the multimeter For dc voltage readings,
  ; 10 V range, 0.1 V resolution, 4 readings
  WriteSerialPortString(1, ":CONF:VOLT:DC 10,0.1;:SAMP:COUN 4");PRINT #1, ":CONF:VOLT:DC 10,0.1;:SAMP:COUN 4"
  ; Trigger the readings, And fetch the results
  WriteSerialPortString(1, ":READ?");PRINT #1, ":READ?"
  If ReadPuffer 
    ReadSerialPortData(1, @resp$, Laenge);LINE INPUT #1, resp$
    PrintN(":READ? returned: "+ resp$) ;PRINT ":READ? returned: ", resp$
  EndIf 
  PrintN("Druecken Sie Return zum Schliessen der Konsole.")
  Input()
  CloseSerialPort(1)
CloseConsole()   
End
PS: Änderungswünsche und Korrekturen sind natürlich erwünscht :)

Gruß,
Falko

Re: Übersetzer gesucht QuickBasic => PureBasic

Verfasst: 10.04.2013 21:25
von Ghosty1967
Erstmal danke an euch alle...
hat sich wohl erledigt. Laut HP scheint meine RS232 nen knacks weg zu haben.
Hab mein Projekt eingestellt :|