-
Danke fuerchau für die Antwort, aber habe folgendes Problem:
Also wenn ich bei Length (80) eintrage, kommt bei nach dem wrtfile in der Variable write 80 zurück. Bei 99 bei Length kommt 99 in write zurück. Wenn ich bei Length mehr eintrage, führt er das wrtfile nciht aus. Wie finde ich denn die Länge von ENT2 raus? Weil der hängt da ja noch son "Müll" dran wie oben beschrieben?
Mfg KAMPI
-
Hallo Kampi,
ich antworte mal einfach.
Testweise würde ich mal folgendes versuchen:
-Eine andere variable für ENT2 (schreiben) mit varying definieren.
- vorher clear auf die variable
- Wert füllen mit X'00'
- länge der variable mit %len ermitteln
- entsprechend Länge mit übergeben.
Vielleicht hilfts
Gruss
Michael
-
WrtFile gibt die Anzahl der geschriebenen Daten zurück !
Die zu schreibende Länge wird im Parameter Length vorgegeben !!!
Schau dir obiges Beispiel GENAU an und nimm ggf. ein C/C++-Handbuch hinzu.
-
So habs jetzt alles hinbekommen, ein wenig anders als in dem Beipsiel, da das nicht so richtig geklappt hat. Trotzdem danke an alle für die Hilfen!!
Sieht jetzt folgendermaßen aus:
PHP-Code:
D* D* Create File D* D CRTFILE PR 10U 0 ExtProc('CreateFileA') D DLL('Kernel32.dll') D Linkage(*StdCall) D * VALUE OPTIONS(*STRING) D 10I 0 Value D 10I 0 Value D $SEC LIKE(secattr) D 10I 0 Value D 10I 0 Value D 10I 0 Value D* D* Write File D* D WRTFILE PR 10U 0 ExtProc('WriteFile') D DLL('Kernel32.dll') D Linkage(*StdCall) D 10I 0 Value D * VALUE OPTIONS(*STRING) D 10I 0 Value D $WRITE LIKE(WRITE) D $OVER LIKE(OVERLAP) D* D* Read File D* D READFILE PR 10U 0 ExtProc('ReadFile') D DLL('Kernel32.dll') D Linkage(*StdCall) D 10I 0 Value D * VALUE OPTIONS(*STRING) D 10I 0 Value D $WRITE LIKE(WRITE) D $OVER LIKE(OVERLAP) D* D* Close File D* D CLOSEFILE PR 10U 0 ExtProc('CloseHandle') D DLL('Kernel32.dll') D Linkage(*StdCall) D 10I 0 Value D* D* Initializations D* D secattr DS D LENGTH 10I 0 INZ(80) D SECDESC 10I 0 INZ(0) D BOOL 10I 0 INZ(0) D name S 10A D access S 10U 0 INZ(3221225472) D share S 10U 0 INZ(0) Dcreate S 10I 0 INZ(3) Dattr S 10U 0 INZ(128) Dtemplate S 10I 0 INZ(0) DBRC S 10U 0 DRET S 10I 0 DRET2 S 10U 0 DRET3 S 10U 0 DWRITE S 10U 0 DOVERLAP S 10U 0 DENT1 S 10A DENT2 S 80A DENT3 S 180A DaENT1 S * inz(%addr(ENT1)) DaENT2 S * inz(%addr(ENT2)) DaENT3 S * inz(%addr(ENT3)) C TEST BEGACT PRESS FRA000000B C EVAL zaehler = 0 C EVAL sstemp = 0 C TIME SysZeit C DOW zaehler < 4 C EVAL sstemp = ss C EVAL zaehler = zaehler + 1 C EVAL ENT1 = '\\.\com1' + X'00' C EVAL ENT2 = X'0D' + 'lftx' + X'0D' + X'00' C EVAL BRC = CRTFILE(aENT1:ACCESS:share: C secattr:create:attr:template) C EVAL RET = WRTFILE(BRC:aENT2:LENGTH:WRITE C :OVERLAP) C EVAL RET2 = Closefile(brc) C CLEAR ENT1 C CLEAR ENT2 C CLEAR BRC C CLEAR RET C CLEAR RET2 C CLEAR WRITE C DOW sstemp = ss C TIME SysZeit C ENDDO C ENDDO C EVAL ENT1 = '\\.\com1' + X'00' C EVAL ENT2 = X'0D' + 'last 1' + X'0D' + X'00' C EVAL BRC = CRTFILE(aENT1:ACCESS:share: C secattr:create:attr:template) C* C EVAL RET = WRTFILE(BRC:aENT2:LENGTH:WRITE C :OVERLAP) C* C EVAL Length = 180 C EVAL RET3 = READFILE(BRC:aENT3:Length:WRITE C :OVERLAP) C* C EVAL RET2 = Closefile(brc) C EVAL ID = %subst(ENT3:135:10) C EVAL FRA000000B.ID.TEXT = ID C EVAL TEMP = %subst(ENT3:154:2) C EVAL FRA000000B.TEMP.TEXT = TEMP C EVAL DAUER = %subst(ENT3:162:3) C EVAL FRA000000B.DAUER.TEXT = DAUER C CLEAR ENT1 C CLEAR ENT2 C CLEAR BRC C CLEAR RET C CLEAR RET2 C CLEAR WRITE C ENDACT
Mfg KAMPI
-
Für den WriteFile würde ich dir noch empfehlen, die Variable LENGTH mit der tatsächlichen Länge der Daten zu füllen, da die Leerzeichen immer mit ausgegeben werden (die Länge ist ja mit 80 initialisiert). Du benötigst auch X'00' nicht !
In der Variablen WRITE wird die tatsächliche Anzahl geschriebener Zeichen zurückgegeben.
WriteFile
The WriteFile function writes data to a file and is designed for both synchronous and asynchronous operation. The function starts writing data to the file at the position indicated by the file pointer. After the write operation has been completed, the file pointer is adjusted by the number of bytes actually written, except when the file is opened with FILE_FLAG_OVERLAPPED. If the file handle was created for overlapped input and output (I/O), the application must adjust the position of the file pointer after the write operation is finished.
BOOL WriteFile(
HANDLE hFile, // handle to file to write to
LPCVOID lpBuffer, // pointer to data to write to file
DWORD nNumberOfBytesToWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
LPOVERLAPPED lpOverlapped // pointer to structure for overlapped I/O
);
Parameters
hFile
Handle to the file to be written to. The file handle must have been created with GENERIC_WRITE access to the file.
Windows NT:
For asynchronous write operations, hFile can be any handle opened with the FILE_FLAG_OVERLAPPED flag by the CreateFile function, or a socket handle returned by thesocket oraccept functions.
Windows 95:
For asynchronous write operations, hFile can be a communications resource, mailslot, or named pipe handle opened with the FILE_FLAG_OVERLAPPED flag by CreateFile, or a socket handle returned by the socket or accept functions. Windows 95 does not support asynchronous write operations on disk files.
lpBuffer
Pointer to the buffer containing the data to be written to the file.
nNumberOfBytesToWrite
Number of bytes to write to the file.
A value of zero specifies a null write operation. A null write operation does not write any bytes but does cause the time stamp to change.
Named pipe write operations across a network are limited to 65,535 bytes.
lpNumberOfBytesWritten
Pointer to the number of bytes written by this function call. WriteFile sets this value to zero before doing any work or error checking.
Windows NT: If lpOverlapped is NULL, lpNumberOfBytesWritten cannot be NULL.
Windows NT: If lpOverlapped is not NULL, lpNumberOfBytesWritten can be NULL. If this is an overlapped write operation, you can get the number of bytes written by calling GetOverlappedResult. If hFile is associated with an I/O completion port, you can get the number of bytes written by calling GetQueuedCompletionStatus.
Windows 95 and Windows 98: This parameter cannot be NULL.
lpOverlapped
Pointer to an OVERLAPPED structure. This structure is required if hFile was opened with FILE_FLAG_OVERLAPPED.
If hFile was opened with FILE_FLAG_OVERLAPPED, the lpOverlapped parameter must not be NULL. It must point to a valid OVERLAPPED structure. If hFile was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the function can incorrectly report that the write operation is complete.
If hFile was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the write operation starts at the offset specified in the OVERLAPPED structure and WriteFile may return before the write operation has been completed. In this case, WriteFile returns FALSE and the GetLastError function returns ERROR_IO_PENDING. This allows the calling process to continue processing while the write operation is being completed. The event specified in the OVERLAPPED structure is set to the signaled state upon completion of the write operation.
If hFile was not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the write operation starts at the current file position and WriteFile does not return until the operation has been completed.
If hFile was not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the write operation starts at the offset specified in the OVERLAPPED structure and WriteFile does not return until the write operation has been completed.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Ebenso gibt die Funktion ReadFile im Parameter WRITE die Anzahl gelesener Zeichen zurück. Dies ist insbesonders wichtig, da beim Lesen von COM die Daten ggf. nicht sofort vollständig kommen !
ReadFile
The ReadFile function reads data from a file, starting at the position indicated by the file pointer. After the read operation has been completed, the file pointer is adjusted by the number of bytes actually read, unless the file handle is created with the overlapped attribute. If the file handle is created for overlapped input and output (I/O), the application must adjust the position of the file pointer after the read operation.
BOOL ReadFile(
HANDLE hFile, // handle of file to read
LPVOID lpBuffer, // pointer to buffer that receives data
DWORD nNumberOfBytesToRead, // number of bytes to read
LPDWORD lpNumberOfBytesRead, // pointer to number of bytes read
LPOVERLAPPED lpOverlapped // pointer to structure for data
);
Parameters
hFile
Handle to the file to be read. The file handle must have been created with GENERIC_READ access to the file.
Windows NT:
For asynchronous read operations, hFile can be any handle opened with the FILE_FLAG_OVERLAPPED flag by the CreateFile function, or a socket handle returned by thesocket oraccept functions.
Windows 95:
For asynchronous read operations, hFile can be a communications resource, mailslot, or named pipe handle opened with the FILE_FLAG_OVERLAPPED flag by CreateFile, or a socket handle returned by the socket or accept functions. Windows 95 does not support asynchronous read operations on disk files.
lpBuffer
Pointer to the buffer that receives the data read from the file.
nNumberOfBytesToRead
Number of bytes to be read from the file.
lpNumberOfBytesRead
Pointer to the number of bytes read. ReadFile sets this value to zero before doing any work or error checking. If this parameter is zero when ReadFile returns TRUE on a named pipe, the other end of the message-mode pipe called the WriteFile function with nNumberOfBytesToWrite set to zero.
Windows NT: If lpOverlapped is NULL, lpNumberOfBytesRead cannot be NULL.
Windows NT: If lpOverlapped is not NULL, lpNumberOfBytesRead can be NULL. If this is an overlapped read operation, you can get the number of bytes read by calling GetOverlappedResult. If hFile is associated with an I/O completion port, you can get the number of bytes read by calling GetQueuedCompletionStatus.
Windows 95 and Windows 98: This parameter cannot be NULL.
lpOverlapped
Pointer to an OVERLAPPED structure. This structure is required if hFile was created with FILE_FLAG_OVERLAPPED.
If hFile was opened with FILE_FLAG_OVERLAPPED, the lpOverlapped parameter must not be NULL. It must point to a valid OVERLAPPED structure. If hFile was created with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the function can incorrectly report that the read operation is complete.
If hFile was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the read operation starts at the offset specified in the OVERLAPPED structure and ReadFile may return before the read operation has been completed. In this case, ReadFile returns FALSE and the GetLastError function returns ERROR_IO_PENDING. This allows the calling process to continue while the read operation finishes. The event specified in the OVERLAPPED structure is set to the signaled state upon completion of the read operation.
If hFile was not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the read operation starts at the current file position and ReadFile does not return until the operation has been completed.
If hFile is not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the read operation starts at the offset specified in the OVERLAPPED structure. ReadFile does not return until the read operation has been completed.
Hier hast du ggf. noch ein Problem, wenn mal keine Antwort kommt, da du keinen Timeout angeben kannst.
-
Nachtrag:
Durch die Angabe "VALUE OPTIONS(*STRING)" wird von RPG eine Kopie der zu sendenen Daten bis zum X'00' erstellt und an WriteFile übergeben.
Da du in der Länge aber trotzdem 80 angibst, werden die Daten hinter der temporären Kopie mit geschrieben (daher der Schrott).
Es ist also ZWINGEND ERFORDERLICH die korrekte Länge anzugeben, man weiss schließlich nie welche Daten denn da so drinn stehen und nicht ggf. als Befehle interpretiert werden.
Statt Options(*string) solltest du nichts angeben und die Pufferadressen mittels %ADDR(Puffer) übergeben.
-
Guten Morgen allerseits,
vielen Dank für die weiterführenden Tips!!! Werde die Sachen die Tage noch umsetzen, aber immo bin ich erst mal froh, dass es so gut läuft. Denn das komische war, als ich das mit LENGTH mal ausprobiert habe, das egal was für einen Wert ich für LENGTH unter "28" eingebe, er das WRTFILE nicht macht, obwohl in ENT1 nur "lftx" steht.
Muss mich jetzt erst mal anderen Programmteilen zuwenden, werde das aber mit den Tipps noch mal versuchen.
Schönen Arbeitstag und schönes (verschneites) Wochenende!!!!
MFG KAMPI
Similar Threads
-
By schatte in forum NEWSboard Linux
Antworten: 12
Letzter Beitrag: 29-01-08, 14:02
-
By marmart in forum IBM i Hauptforum
Antworten: 5
Letzter Beitrag: 25-09-07, 15:29
-
By schatte in forum NEWSboard Windows
Antworten: 7
Letzter Beitrag: 21-11-06, 11:37
-
By pwrdwnsys in forum IBM i Hauptforum
Antworten: 2
Letzter Beitrag: 07-11-06, 15:34
-
By cami in forum IBM i Hauptforum
Antworten: 3
Letzter Beitrag: 27-08-06, 17:31
Berechtigungen
- Neue Themen erstellen: Nein
- Themen beantworten: Nein
- You may not post attachments
- You may not edit your posts
-
Foren-Regeln
|
Erweiterte Foren Suche
Google Foren Suche
Forum & Artikel Update eMail
AS/400 / IBM i
Server Expert Gruppen
Unternehmens IT
|
Kategorien online Artikel
- Big Data, Analytics, BI, MIS
- Cloud, Social Media, Devices
- DMS, Archivierung, Druck
- ERP + Add-ons, Business Software
- Hochverfügbarkeit
- Human Resources, Personal
- IBM Announcements
- IT-Karikaturen
- Leitartikel
- Load`n`go
- Messen, Veranstaltungen
- NEWSolutions Dossiers
- Programmierung
- Security
- Software Development + Change Mgmt.
- Solutions & Provider
- Speicher – Storage
- Strategische Berichte
- Systemmanagement
- Tools, Hot-Tips
Auf dem Laufenden bleiben
|
Bookmarks