[Libnodave] String ind SPS schreiben...

paddy_cmd

Level-1
Beiträge
16
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo leute,
ich habe da ein kleines Problem!

Ich versuche einen String von 5 Zeichen in die SPS in einen DB zu schreiben!
das ganze soll über libnodave und TCP/IP gehen!

verbindung bekomme ich einwandfrei hin, aber nicht das schreiben!

Kann mir jemand irgendwie ne Funktion zukommen lassen die einen string an eine bestimmte adresse schreibt.
Mein Programm wird mit VB.net 2008 erstellt!

Danke im Voraus!
 
Einen String oder einen S7-String?
Beim S7-String berücksichtigen, dass wenn dieser 5 Bytes lang ist, 7 Bytes geschrieben werden müssen. Und zwar befindet sich im ersten Byte die Maximallänge und im zweiten Byte die Aktuallänge. Bei Schreiben muss natürlich speziell das erste Byte zuvor gelesen (wenn nicht fix und bekannt) und das zweite Byte unter dessen Berücksichtigung angepasst werden.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Ich würde die Bytes schreiben. Funktion wäre daveWriteBytes. Im Prinzip ist es doch egal ob man Strings, Int, Dint, Real schreibt, es sind immer einige Bytes, die halt zusammen einen bestimmten Wert ergeben. Bei String sind es 2 Byte Kopf und dann die Charcodes der einzelnen Zeichen.

Hier noch aus Zottels Hilfe:

daveWriteBytes
Write a sequence of bytes from a buffer to PLC memory.

int daveWriteBytes(daveConnection * dc, int area, int DB, int start, int len, void * buffer);

Parameters:
# dc: A pointer to a daveConnection structure representing an established connection.
# area: A constant that specifies a memory area in the PLC.
# DB: The number of a data block. Only meaningful if area is daveDB. Use 0 oterwise.
# start: The address of the first byte in the block.
# len: The number of bytes to read.
# buffer: A pointer to some memory space where you want the result to be copied too.
Hints:
len:
Note that timer, counters and the analog input/output words of the 200 family are allways words (2 bytes). To read n of them, you have to specify 2xn bytes as len.
buffer:
You may call daveWriteBytes() without a buffer specifying NULL (C) or nil (Pascal). There is, however, an internal buffer that is part of the daveConnection structure. This internal buffer allways holds the result from the last read operation.
Maximum length:
The maximum size of a block in S7-Communication is limited by the size of a message structure calledPDU. Each call to daveReadBytes causes a the exchange of a request and a response PDU. The result data must fit into the "payload" area of a response PDU. This means a maximum block length is PDU size -18 bytes for read. A typical PDU size is 240 Byte, limiting read calls to 222 byte result length. If you need more data, you need to use multiple calls to daveReadBytes().
Efficiency:
Each call to daveWriteBytes() causes a the exchange of a request and a response PDU together with prefixes, ackknowledges and what else the transport layer requires. Therefore you should try to write as much as possible in a single call. Example:

daveWriteBytes(dc, daveDB, 5, 68, 14, appBuffer);

writes DBD68 and DBD78 and everything in between from the range appBuffer+4 to appBuffer+9 with 6 unwanted bytes, but it is much faster than:

daveWriteBytes(dc, daveDB, 5, 68, 4, appBuffer);
daveWriteBytes(dc, daveDB, 5, 78, 4, appBuffer+4);

Also einen passenden Buffer anlegen, den Kopf und die einzelnen Zeichen in den Buffer (Array) kopieren und dann schreiben, fertig.
 
Zuletzt bearbeitet:
Hier eine .NET-Funtion....

...die einen String in ein S7-kompatibles ByteArray wandelt. Brauchst Du nur noch an die entsprechende Stelle in Deinen SendeBuffer kopieren.

Code:
[COLOR=#0000ff][COLOR=#0000ff]Public[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Shared[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function[/COLOR][/COLOR] StringToS7String([COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] Wert [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]String[/COLOR][/COLOR], [COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] MaxS7Length [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR]) [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR]()
[COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] Wert.Length > MaxS7Length [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Throw[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]New[/COLOR][/COLOR] ArgumentException([COLOR=#a31515][COLOR=#a31515]"Die Lnge von Parameter 'Wert' darf nicht grer als Parameter 'MaxS7Length' sein"[/COLOR][/COLOR], [COLOR=#a31515][COLOR=#a31515]"Wert, MaxS7Length"[/COLOR][/COLOR])
[COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] Wert.Length > 254 [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Throw[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]New[/COLOR][/COLOR] ArgumentException([COLOR=#a31515][COLOR=#a31515]"Die Lnge von Parameter 'Wert' darf nicht grer als 254 sein"[/COLOR][/COLOR], [COLOR=#a31515][COLOR=#a31515]"Wert"[/COLOR][/COLOR])
[COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] MaxS7Length < 0 [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Throw[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]New[/COLOR][/COLOR] ArgumentException([COLOR=#a31515][COLOR=#a31515]"Parameter 'MaxS7Lenght' darf nicht kleiner als 0 sein"[/COLOR][/COLOR], [COLOR=#a31515][COLOR=#a31515]"MaxS7Length"[/COLOR][/COLOR])
[COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] MaxS7Length > 254 [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Throw[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]New[/COLOR][/COLOR] ArgumentException([COLOR=#a31515][COLOR=#a31515]"Parameter 'MaxS7Lenght' darf nicht grer als 254 sein"[/COLOR][/COLOR], [COLOR=#a31515][COLOR=#a31515]"MaxS7Length"[/COLOR][/COLOR])
[COLOR=#0000ff][COLOR=#0000ff]Try[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] b(MaxS7Length + 1) [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] text [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR]() = System.Text.Encoding.ASCII.GetBytes(Wert)
b(0) = [COLOR=#0000ff][COLOR=#0000ff]CType[/COLOR][/COLOR](MaxS7Length, [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR])
b(1) = [COLOR=#0000ff][COLOR=#0000ff]CType[/COLOR][/COLOR](Wert.Length, [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR])
System.Array.Copy(text, 0, b, 2, text.Length)
[COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] b
[COLOR=#0000ff][COLOR=#0000ff]Catch[/COLOR][/COLOR] ex [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] Exception
[COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Nothing[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Try[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function[/COLOR]
[/COLOR]

Viele Grüße, Manni
 
Einzelne Bits in S7 Db screiben

Hallo

evt kann mir jemand erklären wie man mit libnodave einzelne Bits in einen S7 DB schreiben kann
z.b. Db100.dbx0.0 mit 1 oder 0 beschreiben

lesen bekomme ich hin
verbindung von pc (excel) zur S7 über TCP/IP aufbauen
daten aus DB lesen und in Excel zellen schreiben alles kein Problem


nur umgekehrt geht es einfach nicht.

also mit einem butten in excel das bit db100.dbx0.0 mit 0 oder 1 zu schreiben

Gruss uz
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Neue VB.NET-String-Funktionen

Als Ergänzung hier nochmal 2 .NET-Funktionen:

S7-String schreiben:
Code:
[COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<summary>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' Konvertiert einen String in das S7-Stringformat und kopiert ihn in ein Bytearray[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</summary>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="String">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Der zu konvertierende String[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="MaxS7Length">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Die maximale Lnge des Strings in der S7[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="Array">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Das Array in das der konvertierte String kopiert werden soll[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="Address">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Die Startadresse, ab der der konvertierte Wert in das Bytearray kopiert werden soll[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<returns>[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]0 wenn ok, -1 wenn Fehler[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</returns>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<remarks></remarks>[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]Public[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Shared[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function[/COLOR][/COLOR] SetS7String([COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] [String] [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]String[/COLOR][/COLOR], [COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] MaxS7Length [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR], [COLOR=#0000ff][COLOR=#0000ff]ByRef[/COLOR][/COLOR] [Array] [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR](), [COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] Address [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR]) [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] [String].Length > 254 [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Throw[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]New[/COLOR][/COLOR] ArgumentException([COLOR=#a31515][COLOR=#a31515]"Die Lnge von Parameter '[String]' darf nicht grer als 254 sein"[/COLOR][/COLOR], [COLOR=#a31515][COLOR=#a31515]"[String]"[/COLOR][/COLOR])
[COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] MaxS7Length < 0 [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Throw[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]New[/COLOR][/COLOR] ArgumentException([COLOR=#a31515][COLOR=#a31515]"Parameter 'MaxS7Length' darf nicht kleiner als 0 sein"[/COLOR][/COLOR], [COLOR=#a31515][COLOR=#a31515]"MaxS7Length"[/COLOR][/COLOR])
[COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] MaxS7Length > 254 [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Throw[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]New[/COLOR][/COLOR] ArgumentException([COLOR=#a31515][COLOR=#a31515]"Parameter 'MaxS7Length' darf nicht grer als 254 sein"[/COLOR][/COLOR], [COLOR=#a31515][COLOR=#a31515]"MaxS7Length"[/COLOR][/COLOR])
[COLOR=#0000ff][COLOR=#0000ff]Try[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] [String].Length > MaxS7Length [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR]
[/COLOR][String] = [String].Remove(MaxS7Length - 1)
[COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]If[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]'Den betreffenden Bereich erstmal initialisieren[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]For[/COLOR][/COLOR] i [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR] = 0 [COLOR=#0000ff][COLOR=#0000ff]To[/COLOR][/COLOR] MaxS7Length - 1
[Array].SetValue([COLOR=#0000ff][COLOR=#0000ff]CByte[/COLOR][/COLOR](0), Address + i)
[COLOR=#0000ff][COLOR=#0000ff]Next[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]'Den String in ein ASCII-kodiertes Array wandeln[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] TextArray [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR]() = System.Text.Encoding.ASCII.GetBytes([String])
[COLOR=#008000][COLOR=#008000]'Setzen der maximalen Lnge[/COLOR]
[/COLOR][Array](Address) = [COLOR=#0000ff][COLOR=#0000ff]CType[/COLOR][/COLOR](MaxS7Length, [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR])
[COLOR=#008000][COLOR=#008000]'Setzen der tatschlichen Lnge[/COLOR]
[/COLOR][Array](Address + 1) = [COLOR=#0000ff][COLOR=#0000ff]CType[/COLOR][/COLOR]([String].Length, [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR])
[COLOR=#008000][COLOR=#008000]'Den Text in das ByteArray kopieren[/COLOR]
[/COLOR]System.Array.Copy(TextArray, 0, [Array], Address + 2, TextArray.Length)
[COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] 0
[COLOR=#0000ff][COLOR=#0000ff]Catch[/COLOR][/COLOR] ex [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] Exception
[COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] -1
[COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Try[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [SIZE=3][COLOR=#0000ff][SIZE=3][COLOR=#0000ff][SIZE=2]Function[/SIZE][/COLOR]
[/SIZE][/COLOR][/SIZE]

S7-String lesen:
Code:
[COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<summary>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' Konvertiert aus einem Bytearray einen S7-String in einen String[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</summary>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="Array">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Das Array, von dem der String konvertiert werden soll[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="Address">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Die Startadresse, ab der der String konvertiert werden soll[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<returns>[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Bei Erfolg der konvertierte String, sonst Nothing[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</returns>[/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<remarks></remarks>[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]Public[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Shared[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function[/COLOR][/COLOR] GetS7String([COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] Array [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR](), [COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] Address [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR]) [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]String[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] Address < 0 [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Throw[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]New[/COLOR][/COLOR] ArgumentException([COLOR=#a31515][COLOR=#a31515]"Parameter 'Address' darf nicht kleiner als 0 sein"[/COLOR][/COLOR], [COLOR=#a31515][COLOR=#a31515]"Address"[/COLOR][/COLOR])
[COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] Address > Array.Length [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Throw[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]New[/COLOR][/COLOR] ArgumentException([COLOR=#a31515][COLOR=#a31515]"Parameter 'Address' darf nicht grer sein als die Lnge des Arrays"[/COLOR][/COLOR], [COLOR=#a31515][COLOR=#a31515]"Address"[/COLOR][/COLOR])
[COLOR=#0000ff][COLOR=#0000ff]Try[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] AktLnge [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR] = Array(Address + 1)
[COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] System.Text.Encoding.ASCII.GetString(Array, Address + 2, AktLnge)
[COLOR=#0000ff][COLOR=#0000ff]Catch[/COLOR][/COLOR] ex [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] Exception
[COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Nothing[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Try[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function[/COLOR]
[/COLOR]

VG, Manni
 
Funktionen zum Setzen/Rücksetzen von Bits

Hier noch VB.NET Funktionen für Bit-Operationen:
Code:
[SIZE=3][/SIZE][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<summary>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' Setzt ein Bit in einem Byte
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</summary>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="Byte">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Das Byte welches bearbeitet wird[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="BitNr">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Die Nummer des Bit's (0-7)[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<returns>[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]0 wenn ok, sonst -1[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</returns>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<remarks></remarks>
[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]Public[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Shared[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function[/COLOR][/COLOR] SetBit([COLOR=#0000ff][COLOR=#0000ff]ByRef[/COLOR][/COLOR] [Byte] [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR], [COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] BitNr [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR]) [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer
[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] BitNr > 7 [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] -1
[Byte] = [Byte] [COLOR=#0000ff][COLOR=#0000ff]Or[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]CByte[/COLOR][/COLOR](&H1 << BitNr)
[COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] 0
[COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<summary>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' Rcksetzt ein Bit in einem Byte
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</summary>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="Byte">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Das Byte welches bearbeitet wird[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="BitNr">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Die Nummer des Bit's (0-7)[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<returns>[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]0 wenn ok, sonst -1[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</returns>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<remarks></remarks>
[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]Public[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Shared[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function[/COLOR][/COLOR] ResetBit([COLOR=#0000ff][COLOR=#0000ff]ByRef[/COLOR][/COLOR] [Byte] [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR], [COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] BitNr [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR]) [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer
[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] BitNr > 7 [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] -1
[Byte] = [Byte] [COLOR=#0000ff][COLOR=#0000ff]And[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]CByte[/COLOR][/COLOR](&HFF [COLOR=#0000ff][COLOR=#0000ff]Xor[/COLOR][/COLOR] (&H1 << BitNr))
[COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] 0
[COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<summary>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' Fragt ein Bit in einem Byte ab
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</summary>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="Byte">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Das Byte welches bearbeitet wird[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<param name="BitNr">[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Die Nummer des Bit's (0-7)[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</param>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<returns>[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]Zustand des Bit's wenn ok, sonst -1[/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]</returns>
[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]''' [/COLOR][/COLOR][COLOR=#808080][COLOR=#808080]<remarks></remarks>
[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]Public[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Shared[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function[/COLOR][/COLOR] GetBit([COLOR=#0000ff][COLOR=#0000ff]ByRef[/COLOR][/COLOR] [Byte] [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Byte[/COLOR][/COLOR], [COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] BitNr [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR]) [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer
[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] BitNr > 7 [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] -1
[COLOR=#0000ff][COLOR=#0000ff]Return[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]CInt[/COLOR][/COLOR]((([Byte] [COLOR=#0000ff][COLOR=#0000ff]And[/COLOR][/COLOR] &H1 << BitNr) >> BitNr) [COLOR=#0000ff][COLOR=#0000ff]And[/COLOR][/COLOR] &H1)
[COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Function[/COLOR][/COLOR]

VG, Manni
 
Zurück
Oben