Libnodave Strings schreiben/lesen

Hocheck

Level-1
Beiträge
69
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo,

Ich versuche mit Libnodave Strings in einen Datenbaustein zu schreiben und zu lesen.
Habe diesen Code unten gefunden.
Wie verknüpft man das mit den DavePut, DaveWrite Befehlen?!

Habe das natürlich schon selbst versucht, doch bei mir scheitert es an den einfachsten Dingen schon. Ich weis schon mal nicht, wie ich dieser Funktion den String aus der Textbox zukommen lasse, geschweige denn wie ich das Byte Array in den DavePut Befehl schreiben soll..


Würde Je eine Textbox nehmen für:
a) den zu übermittelten String (textboxWert)
b) die Länge dieses Strings (textboxLänge)

Den Kopf würde ich dann aus
Byte (1) = immer 254
Byte (2) = texboxwert.text

verwenden...

Komme aber nicht weiter, hoffe wer kann mir helfen...

Übertragen an S7

Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Button2_Click_2([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Button2.Click[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Hier sollte dann ber Button 2 der String aus der Textbox an die S7 bertragen werden[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]res = davePut32(Buffer(0), Array)[/SIZE]
[SIZE=2]res = daveWriteBytes(dc, daveDB, 12, 0, 254, Buffer(0))[/SIZE]
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[/COLOR][/SIZE]



Quelle: SPS-Forum
Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Shared[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SetS7String([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [String] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MaxS7Length [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByRef[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [Array] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](), [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Address [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [String].Length > 254 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Throw[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ArgumentException([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Die Lnge von Parameter '[String]' darf nicht grer als 254 sein"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"[String]"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MaxS7Length < 0 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Throw[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ArgumentException([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Parameter 'MaxS7Length' darf nicht kleiner als 0 sein"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"MaxS7Length"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MaxS7Length > 254 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Throw[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ArgumentException([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Parameter 'MaxS7Length' darf nicht grer als 254 sein"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"MaxS7Length"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [String].Length > MaxS7Length [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][String] = [String].Remove(MaxS7Length - 1)[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Den betreffenden Bereich erstmal initialisieren[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MaxS7Length - 1[/SIZE]
[SIZE=2][Array].SetValue([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]CByte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](0), Address + i)[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Den String in ein ASCII-kodiertes Array wandeln[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] TextArray [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]() = System.Text.Encoding.ASCII.GetBytes([String])[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Setzen der maximalen Lnge[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][Array](Address) = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](MaxS7Length, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Setzen der tatschlichen Lnge[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][Array](Address + 1) = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([String].Length, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Den Text in das ByteArray kopieren[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]System.Array.Copy(TextArray, 0, [Array], Address + 2, TextArray.Length)[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 0[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Exception[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] -1[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[/COLOR][/SIZE]
 
Welche programmiersprache willst du verwenden??

VB6 oder VB.NET?

Wenn Vb.Net, kann Ich dir vorschlagen es mit meiner LibNoDave Connection Library zu versuchen. Ich versuche da eine etwas Highlevel Library zu erstellen welche einfachere Funktionen als LibNoDave direkt bietet, und dir auch die Verbindungskonfiguration abnimmt. Dort ist auch ein einfaches VB.NET Demo enthalten!

siehe: http://jochensserver.dyndns.org/wordpress/?page_id=55

Zu deinem Code:
Die Verbindung zur SPS ist schon aufgebaut?
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo, danke für den Tipp :)
Werde mir die Library bei gelegenheit anschauen!

nur leider brauch ich zweck eines Projekts (Techniker Schule) hilfe bei dieser Anwendung. Verbindung und alles ist top, kann INT Bytes etc. alle laden. Nur Strings eben nicht.

Verwende VB.NET

Ist ehrlich gesagt so, dass ich mit dem Code den ich da habe nicht so klar komme. Verstehe halt nicht, wie ich den String der Textbox in meiner Form in diese Function hereinbekomme, damit die gewandelt wird. Danach müsste die ja raus kommen und mit daveput weiter benutzt werden können, aber auch da weis ich nicht wie..

Hoffe du verstehst was ich meine?
 
EDIT:

Es ist ja unsinn noch extra eine Textbox nur für die Länge des zu schreibenden bzw. lesenden Strings zu verwenden, oder? man kann doch einfach die Strings in der Box lesen lassen und dann Byte 0 und 1 automatisch erstellen lassen, oder?

Also ich versuche es auf diese Art und weise:
Dann geht das Prog aber in Keine Rückmeldung und stürzt ohne debugging ab...

Code:
[SIZE=2][COLOR=#0000ff]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Button2_Click_2([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Button2.Click[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [String] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MaxS7Length [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Address [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [Array] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]()[/SIZE]
[SIZE=2][String] = TextBox5.Text[/SIZE]
[SIZE=2]MaxS7Length = TextBox6.Text[/SIZE]
[SIZE=2]Address = TextBox7.Text[/SIZE]
 
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [String].Length > 254 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Throw[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ArgumentException([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Die Lnge von Parameter '[String]' darf nicht grer als 254 sein"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"[String]"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MaxS7Length < 0 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Throw[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ArgumentException([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Parameter 'MaxS7Length' darf nicht kleiner als 0 sein"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"MaxS7Length"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MaxS7Length > 254 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Throw[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ArgumentException([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Parameter 'MaxS7Length' darf nicht grer als 254 sein"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"MaxS7Length"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [String].Length > MaxS7Length [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][String] = [String].Remove(MaxS7Length - 1)[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Den betreffenden Bereich erstmal initialisieren[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MaxS7Length - 1[/SIZE]
[SIZE=2][Array].SetValue([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]CByte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](0), Address + i)[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Den String in ein ASCII-kodiertes Array wandeln[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] TextArray [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]() = System.Text.Encoding.ASCII.GetBytes([String])[/SIZE]
[SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"1:"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] & TextArray([String].Length))[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Setzen der maximalen Lnge[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][Array](Address) = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](MaxS7Length, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Setzen der tatschlichen Lnge[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][Array](Address + 1) = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([String].Length, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Den Text in das ByteArray kopieren[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]System.Array.Copy(TextArray, 0, [Array], Address + 2, TextArray.Length)[/SIZE]
 
[SIZE=2]res = davePut32(Buffer(0), [Array](MaxS7Length))[/SIZE]
[SIZE=2]res = daveWriteBytes(dc, daveDB, 400, 0, 254, Buffer(0))[/SIZE]
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[/COLOR][/SIZE]
 
Zuletzt bearbeitet:
Also einen String mit 254 Byte kannst du auch nicht so einfach schreiben, das musst du auf mehrere PDUs aufteilen, da in einer PDU max PDULenght -32 Bytes übertragen werden können. Dazu kommen aber noch 12 Byte pro WriteRequest!
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Oha, danke für die Info

Also das heißt man hat die möglichkeit 34 Bytes Nutzdaten auf einmal zu "transportieren"?!

das heißt ich muss erstmal überlegen wie ich in mehrere PDUs aufteile?!
 
Zuletzt bearbeitet:
34 bytes gehen natürlich auf einmal aber nur wenn Sie nicht in zu vielen variablen sitzen. Du musst pro Variable beim schreiben 12 Bytes und beim lesen 6 Bytes dazurechnen. Kannst auch in meiner Lib schauen, da teile Ich das in mehrere PDUs auf wenn es nicht reicht....
 
Danke Jochen für die Antwort,

Also wie ich sehe habe ich da ein wichtiges Detail nicht beachtet...
Ich werde mir morgen in der Schule deine Library samt programme anschauen..

wäre super wenn jemand eine Antwort auf die Frage mit den String variablen hätte...
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Danke Jochen für die Antwort,

Also wie ich sehe habe ich da ein wichtiges Detail nicht beachtet...
Ich werde mir morgen in der Schule deine Library samt programme anschauen..

wäre super wenn jemand eine Antwort auf die Frage mit den String variablen hätte...

Also dein WriteBytes kann nicht gehen, da du über der PDU Size liegst. Versuchs mal mit writeManyBytes.

Wie gesagt, meine Bibliothek ist keine eigenständige, Sie nutzt auch LibNoDave, abstrahiert nur einen höheren Level, d.h. der Programmierer muss sich nicht mit Kleinigkeiten wie PDU größe, maximal Variablenanzahl, usw herumärgern.
 
Hallo jochen,

Habe nun auf writemanybytes gewechselt. Das funktioniert bei den anderen Variablen und ich kann mehr als 20 Byte an Daten auf einmal übertragen.

Aber einen String habe ich bisher immer noch nicht übertragen bekommen.

was ist an dem code oben noch alles falsch?!
 
Zurück
Oben