Strictly speaking, this article is not the OPC category. Cause is, another project of the PLC strongman said, OPC slow, with Prodave bar, good, use it, loaded well prodave look is to look at their English information, although English is not good, but fortunately English is very simple. Well, on the Internet to check some information, here also to thank a few friends to help, let me for C # and C + + data structure has a further understanding, but also learned to use DllImport at the beginning of this article, I would like to explain that, Prodave is the communication mode of Siemens, Even if I provide the Prodave6.dll, you do not register is useless, so please use Siemens installation program, where to download? Own Baidu a bit. Do not ask me where to download Prodave6.dll, do not ask me why the program will complain that there is no registered DLL
Below begins to enter the text.
(1) Come up the first function, is to connect the loadconnection_ex6 of PLC, described in the manual is as follows:
loadconnection_ex6
The basic loadconnection_ex6 function initializes the adapter, checks if the
Driver is loaded, initializes the addresses that have been assigned parameters and
Activates the selected interface.
LOADCONNECTION_EX6 is used to set up a transport connection via mpi/pb-or IP
Addresses (TCP/IP protocol)
int loadconnection_ex6 (int connr, char* paccesspoint, int contablelen,
Con_table_type * pcontable);
Parameters
Connr
[In] Number of the connection (max. connections).
Paccesspoint
[In] access point (zero-terminated) of the driver used, e.g. "S7online" for the MPI
Driver or 0 (default).
Contablelen
[in] length of the ' table of connections provided by the ' user in bytes
Pcontable
[in] Pointer to address list of connected users; ' Adr ==0 ' is taken as the end mark of
The list.
#pragma packs (1)
typedef Union {
unsigned char Mpi; MPI/PB Station address (2)
unsigned char ip[4]; IP Address (192.168.0.1)
unsigned char mac[6]; MAC Address (08-00-06-01-AA-BB)
} Con_adr_type;
typedef struct {
Con_adr_type ADR; Connection Address
unsigned char adrtype; Type of ADDRESS:MPI/PB (1), IP (2), MAC (3)
unsigned char slotnr; Slot number
unsigned char racknr; Rack number
} Con_table_type;
#pragma packs (1)
Well, at first there were other conversions online, not hard, but there was a union common body, and C # didn't have that concept. What to do? At first, refer to the information on the Internet, using
[StructLayout (LayoutKind.Explicit)]
struct S1
{
[FieldOffset(0)]
int a;
[FieldOffset(0)]
int b;
}