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 |