| |
VB.NET - Ein- und UmsteigerRe: Probleme mit Structure | | | Autor: Longri | Datum: 10.09.08 11:31 |
| Versuch mal
Dim buf As New IODBPMC
Dim lenght As Short
lenght = 9
buf.type_a = New Short
buf.type_a = 5
buf.type_d = New Short
buf.type_d = 0
buf.datano_s = New Short
buf.datano_s = 7100
buf.datano_e = New Short
buf.datano_e = 7101
__________________________________________________________________________
Ein Programmierer ist eine Maschine die Koffein in Programmcode umwandelt!
Und Bier in Bug?s
May the source code be with you. | |
Probleme mit Structure | | | Autor: DirkSch | Datum: 09.09.08 21:12 |
| Hallo zusammen
Als erstes möchte ich mal danken dafür das ich mir hier aus dem Forum als stiller Leser eine Menge Tips
holen konnte. Jetzt habe ich aber als Beginner in VB.Net ein Problem für das ich einfach keine Lösung finden kann. Vielleicht hat ja jemand mit mehr Erfahrung einen Tip für mein Problem.
Also ich greife auf eine Klasse zu in welche folgende Struktur definiert ist:
<StructLayout(LayoutKind.Explicit)> Public Structure IODBPMC
<FieldOffset(8), MarshalAs(UnmanagedType.ByValArray, SizeConst:=5)> Public cdata As Byte()
Wenn ich nun folgendes versuche um cdata einen Wert zuzuweisen :
Dim buf As New IODBPMC
buf.cdata(0) = (1)
Erhalte ich folgenden Fehler:
Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
Erstellen Sie eine Objektinstanz mit dem Schlüsselwort "new"
Da ich der Meinung bin mit new eine neue Instanz von IODBMC mit dem Namen buf instanziert zu haben werde ich aus dem ganzen nicht schlau !
Für einen Wink in die richtige Richtung wäre ich wirklich dankbar !
Gruß an alle die mir helfen können oder wollen
Dirk | |
Re: Probleme mit Structure | | | Autor: DirkSch | Datum: 10.09.08 10:11 |
| Hallo DaveS
Danke erst einmal für deine schnelle Antwort obwohl ich sie nicht wirklich verstehe. Heißt das nun ich kann cdata keinen Wert zuweisen ?? Mein Problem ist folgendes, ich stelle eine Verbindung zu einer CNC Steuerung her. Die Funktionen zur Verbindung und lesen und schreiben usw. habe ich alle ohne Probleme hin bekommen. Nun versuche ich Parameter an die Steuerung zu übergeben woran ich jedoch scheiter. Leider habe ich die Beschreibung der Funktionen nur für C++ und nicht für VB.Net.
Hier mal ein kleiner Auszug aus dieser Beschreibung:
Declaration
#include "fwlib32.h"
FWLIBAPI short WINAPI pmc_wrpmcrng(unsigned short FlibHndl, short _
length,IODBPMC *buf);
Description
Writes the PMC data of the specified PMC address/range.
This function is used to exchange the data between the application on MMC _
function and LADDER software on PMC.
Arguments
FlibHndl [ in ]
Specify the library handle. See "Library handle" for details.
length [ in ]
Specify the data block length. data_type is 0(byte type) : length = 8 + N
data_type is 1(word type) : length = 8 + N × 2
data_type is 2(long type) : length = 8 + N × 4
* N is the number of written data.
buf [ in ]
Pointer to the IODBPMC structure.
The IODBPMC structure is as follows.
typedef struct iodbpmc {
short type_a ; /* Kind of PMC address */
short type_d ; /* Type of the PMC data */
short datano_s ; /* Start PMC address number */
short datano_e ; /* End PMC address number */
union {
char cdata[N] ;/* The PMC data(byte type) */
short idata[N] ;/* (word type) */
long ldata[N] ;/* (long type) */
} u ; /* N is the number of written data */
} IODBPMC ;
type_a
Specify the identification code corresponding to the kind of the PMC address.
type_d
Specify the type of the PMC data.
It must be the same one as the type of data of the PMC side.
0 : Byte type
1 : Word type
2 : Long type
datano_s
Specify the start PMC address number.
datano_e
Specify the end PMC address number.
See "The referenceable range of PMC data" of "Read PMC data(area specified) (" & _
"pmc_rdpmcrng)" about the kind of the PMC address, the start address, and the _
end address.
Example of specifying argument
250 is written in D0100(It is assumed the word type)
buf.type_a 9
buf.type_d 1
buf.datano_s 100
buf.datano_e 101
length 8+2×1 (=10)
buf.u.idata[0] 250
0 is written all of R0200,..,R0209(It is assumed byte type)
buf.type_a 5
buf.type_d 0
buf.datano_s 200
buf.datano_e 209
length 8+1×10 (=18)
buf.u.cdata[0]
,..,buf.u.cdata[9] 0 all
Nun sieht meine Structur komplett so aus !
<StructLayout(LayoutKind.Explicit)> Public Structure IODBPMC
<FieldOffset(0)> Public type_a As Short ' PMC address type
<FieldOffset(2)> Public type_d As Short ' PMC data type
<FieldOffset(4)> Public datano_s As Short ' start PMC address
<FieldOffset(6)> Public datano_e As Short ' end PMC address
<FieldOffset(8), MarshalAs(UnmanagedType.ByValArray, SizeConst:=5)> _
Public cdata As Byte() ' PMC data
<FieldOffset(8), MarshalAs(UnmanagedType.ByValArray, SizeConst:=5)> _
Public idata As Short()
<FieldOffset(8), MarshalAs(UnmanagedType.ByValArray, SizeConst:=5)> _
Public ldata As Integer()
End Structure Ich versuche nun über folgenden Code die Funktion zum schreiben der Parameter zu nutzen weiß jedoch nicht wie ich in cdata die Daten die zu schreiben sind rein bekomme.
Call ConnectCNC()
Dim buf As New IODBPMC
Dim lenght As Short
lenght = 9
buf.type_a = 5
buf.type_d = 0
buf.datano_s = 7100
buf.datano_e = 7101
ret3 = pmc_wrpmcrng(h, lenght, buf) Es wäre wirklich super wenn du oder jemand anderes mich auf die Richtige Spur bringen könnte. Ich denke das ich Grundlegend etwas falsch mache beim benutzen der Funktion.
Danke im Vorraus.
Gruß
Dirk | |
Re: Probleme mit Structure | | | Autor: DirkSch | Datum: 10.09.08 13:42 |
| Hallo DaveS
Super vielen Dank !!! Mit dem kleinen Zusatz von ReDim funktioniert das Ganze tadellos !
Da wäre ich nie drauf gekommen. Also noch einmal besten Dank für deinen super Tip.
Gruß
Dirk | |
Re: Probleme mit Structure | | | Autor: DirkSch | Datum: 10.09.08 13:44 |
| Hallo Longri
Leider funktioniert es so nicht da cdata somit noch immer das gleiche Problem raus schmeißt aber
DaveS hat den entscheidenden Hinweis parat gehabt ! Mit einem einfachen ReDim Funktioniert das Ganze.
Trotzdem vielen Dank
Gruß
Dirk | |
| Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
|
|
Neu! sevCommand 4.0
Professionelle Schaltflächen im modernen Design!
Mit nur wenigen Mausklicks statten auch Sie Ihre Anwendungen ab sofort mit grafischen Schaltflächen im modernen Look & Feel aus (WinXP, Office, Vista oder auch Windows 8), inkl. große Symbolbibliothek. Weitere InfosTipp des Monats Access-Tools Vol.1
Über 400 MByte Inhalt
Mehr als 250 Access-Beispiele, 25 Add-Ins und ActiveX-Komponenten, 16 VB-Projekt inkl. Source, mehr als 320 Tipps & Tricks für Access und VB
Nur 24,95 EURWeitere Infos
|